In my previous blog Overview of API Testing, Where I have explained briefly the API testing features and their benefits. I suggest you go and check out the SOAIS blog.
Now let us begin how to Integrate Worksoft Certify with Python. Where I have explained step by step procedure followed by.
- Source Code
- Send the API Request from Certify and triggering Python to receive a response.
- API URL: http://jsonplaceholder.typicode.com/todos
- Store the Response data in a text file in the Document folder.
- Deserialize the response in Certify.
Prerequisite for API Testing:
- Install the latest version of Python
- Install the latest version of PyCharm Community Version (Links given in the reference section)
After installing Python, we need to verify whether python is installed or not, to do so open the command prompt and type Python –Version. You should be seeing the version number that you have installed.
After successfully installation python we need to install and upgrade the PIP
PIP: pip is the package installer for Python. You can use pip to install packages from the Python Package Index and other indexes.
Command: python -m pip install –upgrade pip
Verify the PIP version by entering the below command, you should be seeing the latest version of PIP as per the below screenshot
Command: pip –version
So now you have successfully installed Python and PIP.
PyCharm Installation Procedure:
PyCharm is a dedicated Python Integrated Development Environment (IDE) providing a wide range of essential tools for Python developers, tightly integrated to create a convenient environment for productive Python, web, and data science development.
After Installing PyCharm, click on the Create New Project
After clicking on Create New Project we need to Name the Project now as you can see in the screenshot you can name your project as per your preference.
Now you ready to Create you are Python file to do so you can right-click on the project>New>PythonFile
After selecting the python file provide a name to the file with the .py extension.
After providing the name to the Python file. Workspace is now ready to where you can write the python code.
Python Code: Copy the Python code and paste it into your workspace.
After Copying the Python code, you will see the warning message asking to install the Request Package.
Requests allow you to send HTTP/1.1 requests extremely easily. There’s no need to manually add query strings to your URL or to form-encode your POST data. Steps: To do so hover the mouse near the import request step in python code you will see a suggestion popup asking to import Request Package, click on it and wait for the Request Package to get installed. Once it’s successfully installed there will be no warning message.
Let us now integrate it with Worksoft Certify
As per the requirement. Create certify steps to trigger the Python project from a command prompt and store the Response in a text file and deserialize the response values in Certify.
Recordset: Certify Recordset will have two input values
- Python file path
- Output file path where the response will store in a txt file
Concatenate Python File path and the output file path and store the concatenated value in a variable called CMD.
Use the Input dos command step to trigger the Python where the API Testing project is created.
Store the Response from the text file in a variable called Result.
Once it is stored in a variable, we can deserialize the values based on the requirements
In this example, I am Deserializing
- Response Status
- Response Time
- User ID
Run the Certify Process
As you can see, we have stored the Response and Deserialized based on our Requirement
This concludes the Integrating Worksoft Certify with Python. Contribution by Feroz Shaikh