Validation and Store Test Suite - HAR

This feature is to validate the request and response of the HAR and validate the responses by adding assertions.

  1. Initially, we will be taking 3 Services for recording the HAR script

    1. http://localhost:8080/AppvanceServices/rest/unique/getUniqueEntries

    The above service generates a unique ID every time the service is called.

  2. http://localhost:8080/AppvanceServices/rest/unique/verifyUniqueData?data=1443081822217- The above will return true/false based on the values

  3. http://localhost:8080/AppvanceServices/rest/unique/getUniqueEntries – This will return a JSON formatted response. Below is the screen-shot for reference

  4. In our case, we will be creating 2 HAR scripts by using the above 2 URLs in the Google Chrome browser and recording the transactions, and saving the script as HAR

  5. For the first URL we have saved the script as HAR_assert_1.har and for the second URL we have saved the script as HAR_assert_2.har

  6. We will be creating a scenario using both the scripts in Appvance Scenario Builder. The screen-shot of the test case is given below:

  7. We will save the scenario and play it as a functional test and the output from the controller will be as below

  8. As mentioned the first script will generate a random unique number and the second URL just returns a true/false with that unique number.

  9. Once the test is completed successfully, we can proceed to add assertions to the above test

  10. Navigate to the Assert suite tab and the user can select any of the assertions that already exists in the drop-down

  11. In the below, we will be using Assert Matches and adding the assertion accordingly as shown in the below screen-shot

Where

  • The select type will allow the user to select from Testcase, Step, and Request.

Test case Name is the name of the Test case that is provided in the Scenario builder.
Step Name is the name of the step under which we will add the assertions
Request name is the name of the request for which we are adding an assertion
The matching string is the string we will be looking for
Target is the area in which assertions will be checked, * can be used for everything, Any regular expression can be used.

There are 3 types are targets

  • JSON: Target is the path

  • XML: Target is the Xpath

  • Text: Target is Regex

After we add the assertions in the test controller we can view the same in Scenario Builder (SB) by Clicking on Save assertion. Once the assertion is saved User needs to refresh the Scenario Builder page to see the changes. Users should navigate to the Assert suite tab of the Scenario Builder page. The screenshot of the below is shown below:

We will be saving the scenario and running it again and the test will fail since the 2nd request will have a false value and the expected value in our assertion is “true”.

The output from the controller is given below where it is failing.

Use Locker to Store Content and Reuse in Another Test Case

The first URL is generating a unique response and it is not being used in the second URL. We will be using a mechanism called "Store Content" which will store the response from the first URL and that value can be passed to another test case using Locker DPL functionality and that value can be asserted.

The Steps to add store content and use it in the second URL are shown below.

  1. Go to the Assert suite tab of Controller and select store content

  2. The process is similar to the way we add assertions. Go to the Assert suite tab and select Store content from the drop-down, select the first URL as the step name and the Request name

  3. Target can be everything again

  4. Variable Name can be a user-defined unique name; in our case, we will be naming it UniqueID

  5. Once added, Go back to Scenario Builder and refresh the page, and navigate to Store suite to see the new entry been added. Save the Scenario

  6. Few modifications need to be done for the script to use the variable name that we created. Open the script in your favorite editor and change the value to have UniqueID as shown below

  7. Once done, the request name in the Scenario builder – Assert Suite to be updated with the same name as seen below

    http://localhost:8080/AppvanceServices/rest/unique/verifyUniqueData?data=14696219070790.5884963038213008

  8. Note that "14696219070790.5884963038213008" will be generated uniquely for each run. So we are saving the unique number into a variable called "UniqueID" which we have declared in Store content. The URL will be modified as given below:

    http://localhost:8080/AppvanceServices/rest/unique/verifyUniqueData?data=UniqueID

  9. We will be using a mechanism called "The Locker" which will be used for transferring the data stored from the first script to be used in the second script

  10. We have to add "The Locker" in the second script which will use the data from the Locker

  11. The Test case module after we add the Locker is given below:

  12. Once the changes are made we can save the script as well as the scenario and re-run it

    As you can see below, we have a successful execution

We are storing the value in the variable as seen below and passing that to the 2nd test-case

Different Formats and their targets:

We have three different formats

  1. XML

  2. JSON

  3. TEXT

For Text, we need to use regular expressions as the target

For XML, we need to use xpath as a target.

For JSON, we can use JSON as the target expression.

The below example shows how to deal with JSON responses and those assertions can be added in APC.

We can use the indexes as shown below:

Make sure the Format is JSON for this particular test.

Similarly, we can do other assertions like

  • Assert Exist

  • Assert Size

  • Assert Duration

  • Assert Matches

  • Assert Checksum

  • Assert Response Codes