• Selenium Video Tutorials

Selenium IDE - JSON Data File



Selenium IDE can be used to work with the JSON Data file. JavaScript Object Notation or JSON is a data interchange format and is of lightweight nature. It has an easy readable pattern and machines can analyze and produce JSON data quickly.

Selenium IDE 'store json' Command

Selenium IDE can be used to work with the JSON data file using the store json command. It is an accessor command which is used to store the JSON data in a variable.

Store JSON Data to a Variable in Selenium IDE

Let us take an example where we will store the JSON data to a variable using the Selenium IDE taking the help of the accessors command - store json.

The steps to store json data and access them in Selenium IDE are listed below −

Step 1 − Click on the Selenium IDE extension visible on the browser after its installation.

Step 2 − Selenium IDE should be launched along with it, a welcome message should be displayed with the version of the tool. In the below image, the version installed is 3.17.2.

Along with this, it gives us the option to select what we would like to do with the tool, like Record a new test in a new project, Open an existing project, Create a new project, and Close Selenium IDE.

Also, a link with the text - the Selenium IDE project page is provided, which on clicking would land us to the Selenium Integrated Development Environment documentation page.

https://www.selenium.dev/selenium-ide/.

Step 3 − Click on the Create a new project link, then enter a project name under the Please provide a name for your new project. Finally, we would click OK.

Step 4 − We would have the workspace ready in the Selenium IDE.

Step 5 − Enter open in the Command field, and https://www.tutorialspoint.com/selenium/ in the Target field, to launch the application.

Step 6 − Enter store json in the Command field, {"Language":"Java","Name":"Selenium"} in the Target field, and val in the Value field. Please note, {"Language":"Java","Name":"Selenium"} is the json data we would like to store using the variable val.

Step 7 − Enter echo in the Command field, ${val} in the Target field. Please note, this would print the json object we accessed in Step6 under the Log in Selenium IDE.

Step 8 − Enter close in the Command field to close the browser window.

Selenium IDE Json Data File 1

Step 9 − Click on the Run all tests from the top, and wait for the test execution to complete. In our example, we would see Runs: 1, Failures: 0, and a green bar denoting the test ran successfully without any failures. Also, the message test completed successfully appeared under the Log.

Selenium IDE Json Data File 2

In the example above, we obtained the json data under the Log. Besides, we got a green tick beside the test case at the top, signifying a passed test.

Apart from that, all the test steps, along with the test case name turned green, reflecting a PASS for all the steps. All the steps which reflected under the Log tab, showed an OK in green.

Thus, in Selenium IDE, we would get the information about the test results both at the test step level and only if all the steps would be executed successfully, we would get a PASS at the test case level as well.

Moreover, we would infer that variables used in one step can be accessed further in other steps using the syntax: ${<variable name>}. In Step2 we followed this approach in our test. The echo command was used to get the JSON objects under the Log tab.

Once the test was executed, the project would be saved in a file having .side extension. Here, we had saved the project with the name Test13.side. On opening this file in Notepad, Notepad++, or any text file format, we would get the data and other information of the test in JSON format.

Selenium IDE Json Data File 3

The complete JSON data received from the test .side file −

{
   "id": "9da88821-edda-4f81-9e7b-57b89080eadc",
   "version": "2.0",
   "name": "Test13",
   "url": "",
   "tests": [{
      "id": "a87746b2-6478-47ce-b241-196675f0c91d",
      "name": "Untitled",
      "commands": [
         {
            "id": "86c94e67-93ba-44ba-89c5-170d1669f333",
            "comment": "",
            "command": "open",
            "target": "https://www.tutorialspoint.com/selenium/practice/register.php",
            "targets": [],
            "value": ""
         }, {
            "id": "62ed3587-a53b-4f10-ad98-90fc3223018a",
            "comment": "",
            "command": "storeJson",
            "target": "{\"Language\":\"Java\", \"Name\":\"Selenium\"}",
            "targets": [],
            "value": "val"
         }, {
            "id": "d5676067-fb60-46fa-9b02-cd7a0b2ae630",
            "comment": "",
            "command": "echo",
            "target": "${val}",
            "targets": [],
            "value": ""
         }, {
            "id": "3ce68f7d-2958-4e66-ad33-d9b9a4e5aa7f",
            "comment": "",
            "command": "close",
            "target": "",
            "targets": [],
            "value": ""
         }
      ]
   }],
   "suites": [{
      "id": "7f58de7c-b22c-4fd1-bd59-00e4644995a6",
      "name": "Default Suite",
      "persistSession": false,
      "parallel": false,
      "timeout": 300,
      "tests": ["a87746b2-6478-47ce-b241-196675f0c91d"]
   }],
   "urls": [],
   "plugins": []
}

In the above example, we had four test steps, with the commands open, store json, echo, and close. All these commands along with their Target, and Value had been captured in the JSON file. The JSON data {"Language":"Java", "Name":"Selenium"} passed in the test had also been captured in the json file.

This concludes our comprehensive take on the tutorial on Selenium IDE - JSON Data File. We’ve started with describing how to access a json data using the store json command in Selenium IDE, and walked through an example to illustrate how to use the store json command and the file with side format to save the Selenium IDE test, and later access the same file to get the test information in a json format.

This equips you with in-depth knowledge of the JSON Data file in Selenium IDE. It is wise to keep practicing what you’ve learned and exploring others relevant to Selenium to deepen your understanding and expand your horizons.

Advertisements