How Beginners Can use EchoAPI to perform Automated API Testing?
In the realm of API testing, a strategic approach involves leveraging automation to conduct comprehensive tests on login interfaces. Rather than manually repeating test steps, automation streamlines the process by utilizing a user listing API to gather a batch of email and password combinations. These credentials are then systematically applied in bulk to verify the login interface's functionality across a spectrum of scenarios, ensuring robust performance and reliability.
Preparatory Steps
We start off by setting up two APIs in advance.
1.User Listing API
https://mock.echoapi.com/mock/306931d1b864000/userlist?echoapi_id=6c5e20435f000
The response from this API includes:
{
"data": {
"errcode": 0,
"errstr": "success",
"list": [
{
"email": "test01@echoapi.cn",
"password": "123456"
},
{
"email": "test02@echoapi.cn",
"password": "123456"
},
{
"email": "test03@echoapi.cn",
"password": "123456"
},
{
"email": "test04@echoapi.cn",
"password": "111111"
},
{
"email": "test05@echoapi.cn",
"password": "222222"
}
]
}
}
2.Login API
https://mock.echoapi.com/mock/306931d1b864000/login?echoapi_id=6c77dfd35f000
The successful response from this API includes:
{
"errcode": 0,
"errstr": "success",
"data": {
"userId": "9252A47b-0E3B-98d5-DfAC-526b87A5f14f",
"email": "test01@echoapi.cn",
"nickName": "Alex"
}
}
The failure response from this endpoint includes:
{
"errcode": 11001,
"errstr": "User account not found",
"data": []
}
Setting Up Automated Test Scenarios
Now, we will leverage the aforementioned APIs to achieve our primary objective: executing test data in bulk to validate the functionality of the login interface.
Establishing a New Test Scenario
Access EchoAPI, proceed to Automated Testing -> Create New Case, and label it as: "Bulk Login Testing."
Defining Test Scenario Steps
Let's outline the test steps for this scenario.
In the outlined process, our initial action involves integrating a user listing step by seamlessly incorporating the established user listing endpoint into our testing framework.
Next, we introduced a loop controller, and the specific configuration details for this loop controller are as follows:
As illustrated in the diagram, we decided to iterate over the outcomes of the preceding step using a loop controller. Leveraging a JSONPath
expression, we successfully extracted arrays directly from the response results, as demonstrated below:
[
{
"email": "test01@echoapi.cn",
"password": "123456"
},
{
"email": "test02@echoapi.cn",
"password": "123456"
},
{
"email": "test03@echoapi.cn",
"password": "123456"
},
{
"email": "test04@echoapi.cn",
"password": "111111"
},
{
"email": "test05@echoapi.cn",
"password": "222222"
}
]
This setup enables us to directly employ the array as our test data.
Lastly, within the loop controller, we added a sub-action: the inclusion of the user login API.
Moreover, the input parameters for this endpoint utilize variables passed from the above-mentioned array test data.
With this, a comprehensive automated test case configuration is complete. Our login interface will sequentially use the email and password data retrieved from the user listing API for bulk testing, culminating in test results.
Additionally, we can incorporate an assertion within the login interface to verify if the response aligns with our expectations.
Absolutely, apart from the showcased method of utilizing the outcomes of a previous endpoint for looping test data, we offer multiple alternative approaches for providing test data, as illustrated in the image below:
These methods include:
- Directly uploading test data in CSV format
- Employing variables as test data
- Inputting fixed values as test data, and more
Conclusion
In summary, when configuring automated test cases, we can leverage various techniques to provide test data effectively. These methods range from uploading CSV files directly to utilizing variables or fixed values as test data inputs. By employing these diverse approaches, we enhance the flexibility and robustness of our automated testing procedures, ensuring comprehensive coverage and accurate validation of system functionalities.