/demo-bdd-api-testing

Demo: Using BDD in API automation testing (for reqres.in)

Primary LanguageGherkin

Demo: Using BDD in API automation testing

Demo tests written for the API service ReqRes (use REST). Check: codes, field values, data structures according to the schemes (without serious use of the test design).

Example Gherkin case

More tests by link

  Scenario Outline: Create new user and update job fields
    Given I send POST request on resource url "/api/users" using: "<name>" value to "name" field, "<job>" value to "job" field
    And I retrieve value of the parameter "id" from results
    When I send PUT request on resource url "/api/users/" using: "<name>" value to "name" field, "<new_job>" value to "job" field
    And I retrieve the results
    Then the status code should be 200
    And it should have the field "name" containing the value "<name>"
    And it should have the field "job" containing the value "<new_job>"
    And request structure corresponds to the scheme "update_user.schema"

    Examples:
    | name  |       job       |        new_job       |
    |Georg R|   QA Engineer   |Automation QA engineer|
    |Pavel K|Senior Programmer|      Team Lead       |

Example Steps

More steps by link

@given('I send POST request on resource url "{url}" using: "{name}" value to "name" field, "{job}" value to "job" field')
def step_impl(context, url, name, job):
    payload = {'name': name, 'job': job}
    context.response = requests.post(BASE_URL + url, json=payload)

@given('I retrieve value of the parameter "{param}" from results')
def step_impl(context, param):
    context.param = context.response.json()[param]

@when('I send PUT request on resource url "{url}" using: "{name}" value to "name" field, '
      '"{new_job}" value to "job" field')
def step_impl(context, url, name, new_job):
    payload = {'name': name, 'job': new_job}
    user_id = context.param
    context.response = requests.put(BASE_URL + url + user_id, json=payload)

Requirements