0

For mobile testing automation I'm using appium, pytest-bdd and allure.

Application has multiple functions. To use it user must be logged in.

Process to test is next:

  1. Scenario to authenticate - 2 scenarios - first with 3 steps and second with 1 step.
  2. Template creation - 3 scenarios.
  3. Invite friend - 2 scenarios.
  4. Payments - 4+ scenarios
  5. and many other

I have feature files for:

  1. Login
  2. Templates
  3. Invitation
  4. Payments
  5. and other ones

When I run command to execute tests, it fails, cause test is not starting with Login scenario.

Beside this, there are some features, that have dependencies on other features. E.g: I cannot pay using template if I have no templates created. So payment.feature partially depends on templates.feature, and many other cases.

I want to run scenario from 'login.feature' file at the begining of test.

Is there any possibility to control test execution sequence?

1

This is a common trap people fall into when writing behavior driven tests. You do not want to run entire scenarios as a prerequisite. Instead, you need to write one or more Given steps that simulate the things the other scenarios do. Without seeing an example of the login scenario, and one of the other scenarios requiring the user to log in I cannot give you specific advice, but I'll make up couple of scenarios.

Example "log in" scenario:

Scenario: Logging in
    Given "Bob" is a registered user
    And "Bob" has verified his access
    When the user logs in as "Bob"
    Then the user should be logged in

The "log in" scenario isn't too bad. Create a registered user, then log them in. Make your assertion and move on. Copying and pasting these steps for each subsequent scenario that requires a user to be logged in will create a maintenance nightmare if the login procedure changes.

Just as an example, here is a scenario for inviting a friend (poorly written):

Scenario: Inviting a friend
    Given "Bob" is a registered user
    And "Bob" has verified his access
    When the user logs in as "Bob"
    Then the user should be logged in
    When I invite "Edna" via "edna@example.com"
    Then "Edna" should be invited

When copying and pasting steps you end up coupling unrelated scenarios to your log in scenario. You can also see multiple sets of Given-When-Then combinations, which is an indication this scenario is written poorly. Instead, invent new Given steps that essentially do the "log in" scenario:

Scenario: Inviting a friend
    Given "Bob" is a registered user
    And "Bob" has verified his access
    And the user has logged in as "Bob"
    When I invite "Edna" via "edna@example.com"
    Then "Edna" should be invited

The new step: Given the user has logged in as "Bob" will open the browser, navigate to the login page, enter Bob's credentials and log in. Lastly, it should verify that the user is indeed logged in. All in one step.

Now the scenario has a natural transition from Given to When to Then, with no back-and-forth between the three different kinds of steps. Any changes to the login procedure could be fixed in the Given the user has logged in as "Bob" step.

| improve this answer | |
  • Great answer! Thx – Laurent Bristiel Mar 6 at 8:02
  • Agree. Thought about it and this is the only solution. – David Mar 9 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.