Let’s start!
1- Create a new API automate project
Click PROJECTS and select the API tab
Click ADD URL button
Write your App Name, Version, base URL of the API and click ADD PROJECT button
Info |
---|
URL will be your baseURL and must start with http:// or https:// |
2- Develop your test cases
You will be navigated CASE MANAGEMENT automatically
Click ADD SECTION and write your SECTION name
Click ADD SECTION to Save your Section
Click ADD CASE button
Write your TestCase Name and click ADD CASE button
Select Java languageand Rest Assured framework.
Click ADD STEP button
Enter your Step Title and copy-paste the needed step code(s) (Rest Assured Automation Script)
Click the ADD STEP button
Example-1 GET Single User Request https://reqres.in/api/users/2
Response:
Code Block |
---|
{ "data": { "id": 2, "email": "janet.weaver@reqres.in", "first_name": "Janet", "last_name": "Weaver", "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg" }, "ad": { "company": "StatusCode Weekly", "url": "http://statuscode.org/", "text": "A weekly newsletter focusing on software development, infrastructure, the server, performance, and the stack end of things." } } |
Automation Script:
Code Block |
---|
when(). get("/api/users/2"). then(). statusCode(200). body("data.email", equalTo("janet.weaver@reqres.in")). time(lessThan(2000L)); |
Example-2 POST Create User Request. https://reqres.in/api/users
Request Post Data:
Code Block |
---|
{ "name": "morpheus", "job": "leader" } |
Response:
Code Block |
---|
{ "name": "morpheus", "job": "leader", "id": "610", "createdAt": "2020-07-01T09:15:46.358Z" } |
Automation Script:
Code Block |
---|
String postData = "{\n" + " \"name\": \"morpheus\",\n" + " \"job\": \"leader\"\n" + "}"; given(). contentType(ContentType.JSON). body(postData). when(). post("/api/users"). then(). statusCode(201). body("name", equalTo("morpheus")); |
Info |
---|
For more advanced use cases, you can read Rest Assured usage documentation: https://github.com/rest-assured/rest-assured/wiki/Usage |
3- Run a test and check the results
Click the TEST RUNS tab to create a new Test Run
Click CREATE NEW TEST button to create a new Test Run
Set Your Test Name
Check your TestCase(s) which will run
Click the SET TIME button
Click the SELECT DEVICE button
Select API-Bot which will run your TestCases
Click the RUN TEST button
After a few seconds, your test will start automatically. You can inspect the TestRun when the test goes RUNNING status
Click COMPLETED status
You should see your TestCases with Steps and the Overall status of your test
Click on any STEP nameto inspect
Select API-Bot from the list
Review the Test Results (Request & Response Details, Console Logs, Error Logs..)
Info |
---|
Learn more about creating your Environment Variables with MomentumSuite. |