0

In Scenario outlines, if there are 2 or more scenarios, then all the steps of feature will execute for both of the 2 more scenarios.

But I need to execute one of the step only once i.e. login step.

For Example:

Scenario Outline: Acceptance page has <Application> logo appearing on top
    Given I am signing up in <Application>         #I want to run this step only once
    And I navigate to "Dashboard" page     # I want to run this step only once
    Then I should see "header logo" exist
    And I should see "footer" exist
    And I should expect the following elements to be visible
        | element                    |
        | Legal                      |
        | Privacy                    |
        | Security                   |
        | Cookies                    |

    Examples:
        | Application | 
        | Gmail       | 

In above feature file, i want to log on application only once and verify rest of the steps.

Currently for every verification step, Logon thing happen again and again.

Please suggest how can i run login step only once and can check multiple items on page.

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
Hemanshu
  • 39
  • 2

2 Answers2

0

Extract the common step(s) and place them into a Background statement. Background is run before each of your scenarios but after any of your Before Hooks.

Sander
  • 390
  • 1
  • 4
  • 13
MikeJRamsey56
  • 2,779
  • 1
  • 20
  • 34
0

First, @mikejramsey56 is right about moving common steps from scenarios to the background.

Second, you can log into a website once in the before hook as Mike suggested, but you will not be in a good place if the browser logs you out for any reason. Tests should be independent.

Third, Cucumber is a great place to show the level of complexity that you need to show what is expected. You can combine steps into one step. If you do that, you should pull the code out of step and put it into a separate method, then call the method from the step. You could have one step that calls several methods, such as verifying the common page components.

Fourth, I hope you are practicing because making sure a header & foot exist are not use behaviors. Users want to do stuff and see stuff, which might be in a div or frame at the top, but they never want to see a div or frame.

Dave McNulla
  • 2,006
  • 16
  • 23