Get params as json for automated testing

When writing unittests, I want to be able to use the params as if there was user input in the parametrization. This is done by using Mocking, and importing the parametrisation as a json.

To convert my parametrisation to a jason, I currently print my parametrization, and use the replace menu (ctrl+R) in PyCharm to change the ’ to " and None to null and other formatting details. Is there an easier/ better way?

Not sure whether there is a better way of doing this, but one way would be to, once you have navigated to the editor you want to use as test case, “Inspect” the page by right clicking and selecting the option “Inspect”. This will open a DevTools window. In the case of the Chrome browser, navigate to the tab “Network”. If a trigger event occurs (by for example changing a parameter value), a response named “parametrization” is listed. When selecting the response, the parametrization will be available in the “Request Payload” section under the key “arguments”.

Here is a snippet of an example of how it will look like:

You can then copy the dictionary and save it as a json file.

1 Like

Thanks! That saves me quite some time in formatting :smile: In firefox, this can be accessed trough : right click > inspect > Network tab, Then change some value and wait for the parametrization to appear under File. Then in the right hand tab under Response, toggle on “Raw”, and you have the json ready to be copied!

Edit: Instead of Response under the tab Request, see @khameeteman’s reply

if you use the json.dumps(params) the formatting is done automatically and converted to a string. The string can be printed to terminal.

In pycharm, the json file can be formatted ‘nicely’ with ctrl+alt+L

1 Like

Please note that you currently are looking at the “parametrization” instead of the params. Params can be obtained in the Headers → Request payload (as in Marcel’s example).

1 Like