This is a summary of the findings from my research past week.
Day to day collection from work and self learning in QA, middleware, tech support spaces ..
In here the entire user payload is read from the examples table and stored as a Map in the step definition.
This approach is useful when you have a small number of fields in the request body, and you can easily read them from the feature file's data table.
Scenario Outline: Create User Successfully Given the user payload is: | first_name | <first_name> | | last_name | <last_name> | | email | <email> | | mobile_phone | <mobile_phone> | | date_of_birth | <date_of_birth> | | password | <password> | | username | <username> | When I send a <method> request to <path> Then the response status code should be <status_code> Examples: | first_name | last_name | email | mobile_phone | date_of_birth | password | username | method | path | status_code | | John | Doe | john.doe@example.com | 1234567890 | 1990-01-01 | password | johndoe | POST | /users/create | 201 |
public class CreateUserStepDefinitions { private RequestSpecification requestSpec; private Response response; private Map<String, String> userPayload = new HashMap<>(); @Given("the user payload is:") public void the_user_payload_is(Map<String, String> userData) { this.userPayload = userData; } @When("I send a {string} request to {string}") public void i_send_a_request_to(String method, String path) { requestSpec = RestAssured.given() .contentType(ContentType.JSON) .body(userPayload); response = requestSpec.when() .request(method, path); } @Then("the response status code should be {int}") public void the_response_status_code_should_be(int expectedStatusCode) { assertEquals(expectedStatusCode, response.getStatusCode()); } }
How we change this code to PageObjectModel and action classes. 1 2 3 driver . findElement ( By . id ( "userEmail" )). sendKeys (...