Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Current »

Attention QA Specialists: Pricefx does not support the Cypress open-source testing framework for web applications. Explore alternative testing solutions that align with Pricefx requirements.

This article explains how to perform API testing with Cypress, specifically focusing on adding or modifying entries in Pricefx PP tables using Pricefx APIs instead of the graphical user interface (GUI). The article provides step-by-step instructions, including adding a command to the Cypress commands.js file and using a JSON file to specify the necessary parameters for the API request. It also explains how to find the table ID for the PP table and the format of the JSON file containing the data to be inserted. The article concludes with an example of how to use the command in a Cypress test case.

While using Cypress, in order to add/modify entries in PP tables through Pricefx APIs( instead of the GUI), we just need to carry out the following steps:

Step 1: Add the following command to commands.js of Cypress:

Cypress.Commands.add('insertDataToPPTable', (file) => {

  // read the file which contains details on: the username/partition, password, pp table id(into which data will be inserted) and the json file which contains data to be inserted into the PP table
  const readParamsJson = require('../fixtures'+file)

  //read the data to be inserted into the selected PP table
  const allData = require('../fixtures/'+readParamsJson.fileName)
 
  //read the configurations for username/partition and password from cypress.json
  //looping the json data file to insert the rows one by one  
  allData.forEach((row) =>{
      cy.request({
          url:`${Cypress.env('apiBaseUrl')}`+readParamsJson.username.substr(0, readParamsJson.username.indexOf('/'))+"/lookuptablemanager.add/"+readParamsJson.tableId,
          method: "POST",
          auth: {
              "username": readParamsJson.username,
              "password": readParamsJson.password
          },
          body:{
              "data": row
         }
      })
      .its("status")
      .should("eq", 200);
  });

CODE REVIEW: this is a code snippet from a JavaScript file that defines a custom command using the Cypress testing framework. The custom command is named insertDataToPPTable and it is intended to insert data into a PP table (presumably some kind of database or data structure used within the application under test).

Here's a step-by-step breakdown of what the code does:

  1. The command insertDataToPPTable takes a file argument, which is expected to be the path to a JSON file.

  2. It uses require to read the contents of the JSON file specified by the file argument. This JSON file contains details such as the username/partition, password, PP table ID, and another JSON file name that contains the data to be inserted into the PP table.

  3. It then reads the data from another JSON file specified by the fileName property in the previously read JSON object. This second JSON file contains the actual data to be inserted into the PP table.

  4. The code constructs a POST request to an API endpoint using Cypress's cy.request method. The URL for the request is built using the apiBaseUrl environment variable from Cypress's configuration and includes the username and table ID read from the JSON file.

  5. The POST request includes authentication credentials (username and password) and the body of the request contains the data from one row of the JSON data file.

  6. The command loops over each row in the data file, sending a separate POST request for each row.

  7. After sending the POST request, it checks the response status to ensure it is 200, indicating that the operation was successful.

NOTE: This custom command seems to be designed to automate the process of populating a PP table with multiple entries

Step 2: Note that the command takes one string parameter, which contains the relative path (from fixtures folder)to a json file. The json file is expected to be present in the fixtures folder of the cypress project. It should contain details as shown in the sample below:

{
    "username":"<partition>/<loginName>",
    "password":"<password>",
    "tableId" : 174,
    "fileName":"PPTableData/UserHierarchy-Customer/PPData.json"
}

 CODE REVIEW: Note the following about the parameters in the file:

  • Username is combination of {partition}/{loginName}

  • Password is the password associated with the loginName used in step 1

  • tableId is the id of the PP table into which the data needs to be inserted. The table id can be found using the following request in postman(refer to the screenshot below for an example):

 

CODE REVIEW: a JSON response in a web API testing tool, likely from a GET request to a URL that seems to be related to fetching data from a lookup table manager in a Pricefx application environment.

The JSON response contains several key-value pairs, which include:

  • "typedid": "IM.LI", which may be an identifier for the type of data or the specific lookup table being accessed.

  • "label": "Di6 - Sales Region Mapping", which likely describes the content or purpose of the lookup table, in this case, mapping sales regions.

  • "validafter": "2000-08-01", which could indicate that the data in the lookup table is valid after the specified date.

  • "status": "ACTIVE", suggesting that the lookup table is currently active and presumably in use.

  • "simulationSet": null, indicating that there is no simulation set associated with this data at the moment.

  • "valuetype": "**szsz**", where the value is not clearly defined and could be a placeholder or an internal code.

  • "userregedit": "o16 (dit)", which might refer to user registration or editing information, possibly indicating who created or last edited the lookup table.

The API response is shown in a pretty-printed format for easier readability, and there are other tabs and options available in the tool, such as Raw, Preview, Visualize, and JSON options for viewing the response. Additionally, the response metadata indicates a successful request with a 200 OK status, taking 1056 milliseconds to complete, and the size of the response is 475 KB.

 Step 3: While sending the above request, “Authorization” should be set as shown in the screenshot below (using appropriate {partition name}/{loginName} and {password})

The response “body” will have an array of json elements, one per PP table present in the system. Each element gives details about the PP table including the PP table id as shown in the example below:

{
                "version": 9,
                "typedId": "174.LT",
                "uniqueName": "UserHierarchy-Customer",
                "label": "General - User Hierarchy Customer",
                "validAfter": "2000-01-01",
                "status": "ACTIVE",
                "simulationSet": null,
                "type": "MATRIX",
                "valueType": "MATRIX6",
                "nodeId": 16,
                "userGroupEdit": "SDM_Edit,PBM_Edit,RBMEdit",
                "userGroupViewDetails": "SDM_View,PBM_View,RBMView",
                "hideWarnings": false,
                "formatType": null,
                "lastUpdateByName": "pfx.jenkins",
                "createdByName": "pfx.jenkins",
                "numberOfKeyFields": 6,
                "createDate": "2020-10-27T07:03:37",
                "createdBy": 318,
                "lastUpdateDate": "2021-08-02T14:10:48",
                "lastUpdateBy": 447,
                "id": 174,
                "isPlasma": false
            }

 

NOTE: the value of the field “id” is the id of the table whose “uniqueName” is UserHierarchy-Customer

 The fileName is the relative path (from fixtures folder) to the file which contains the actual data to be inserted into the PP table identified above. Format of the file for a Matrix6 PP table is as below (multiple rows can be inserted in one go):

[
    {"key1":"SE01",
     "key2":"Default",
     "key3":"ISO",
     "key4":"S62",
     "key5":"Test",
     "key6":"Admin"
     },
{"key1":"SE02",
     "key2":"Default",
     "key3":"ISO1",
     "key4":"S62",
     "key5":"Test",
     "key6":"Admin"
     }
 ]

      

In the Cypress testcase, the command can be called as shown below:

describe('userHierarchyTableTest', () => {
    it('userHierarchy', () => {
        cy.insertDataToPPTable("/PPTableData/UserHierarchy-Product/BasicDetails.json")
        cy.insertDataToPPTable("/PPTableData/UserHierarchy-Customer/BasicDetails.json")
    });
});
  • No labels