Broda Noel
Broda Noel

Reputation: 2006

How to run one Cucumber (With Protractor) scenario over multiples files?

I have a Cucumber feature like this one:

@MainSuite
Scenario: Verify that user can login
  Given I can see the login form
  Then I set a username
  And I set a password
  And I click in Login button
  Then I see the "wrong-password" message

I need to check that the user can login in 5 different pages. I need to run that feature in 5 different places. It's like, I need to run that feature in /login.html, /old_login.html, /after_restore_password.html and more (it's just an example).

Do you know how to do it?

Currently, I have only one file hardcoded. Obviously I need to change it.

this.Given(/^I can see the login form$/, function(done) {
    this.goTo('login.html');
    browser.wait(EC.visibilityOf(this.loginFormContainer));
    done();
});

Upvotes: 1

Views: 676

Answers (1)

kfairns
kfairns

Reputation: 3067

Create an object containing the different login pages that you can go to.

Include an if statement in your step def if there is any extra code that needs to be executed.

this.Given(/^I can see the "(.*)" login form$/, function(loginPage, done) {
    var logins = {
         login : "login.html",
         afterpasswordreset: "after-password-reset.html"
    }
    loginPage = loginPage.toLowerCase().replace(" ", "");
    this.goTo(logins[loginPage]);
    browser.wait(EC.visibilityOf(this.loginFormContainer));
    done();
});

Make either separate Scenarios or feature file for each variation of login, or simply create a Scenario Outline for them

EDIT

Here is how I would implement the Scenario Outline:

@MainSuite
Scenario Outline: Verify that user can login
  Given I can see the "<loginType>" login form
  And I set a username
  And I set a password
  When I click in Login button
  Then I see the "wrong-password" message

 Examples:
    | loginType              |
    | Login                  |
    | After Password Reset   |

Upvotes: 1

Related Questions