0

Is there anyway we can run the same tests multiple times to verify the functionality.

Here is my feature file:

Feature: End to end tests 

    I want an End to End test pack
    As Super user and Admin user
    So that I can ensure that the integrated components of the application function as expected

    Background:
            Given I have the login Page
            When I login to application
            Then the list is displayed

    @javascript
    Scenario: To verify the functionality on the Dashboard          
            When I navigate to the Dashboard Page
            Then the Dashboard Page is displayed

I would like to run this scenario for 2 different users. Is there way I can run the same features using multiple users/roles.

I have several other feature files which needs to be run using 2 or 3 different users which I need to run overnight

Refer to the context file below:

public function iLoginToApplication() { 
$page = $this->getSession()->getPage();
$page->find('css', '#username')->setValue("admin");
$page->find('css', '#password')->setValue("Password");
$signInButton->press();
}
vijay pujar
  • 1,683
  • 4
  • 19
  • 32
  • Some would consider helping when you go through all your 19 questions and accept the answers that complemented your 13+ years of experience at work. Community spends time you know… – Ian Bytchek Sep 06 '14 at 21:39
  • 1
    I completely understand and appreciate where you are coming from. And I have accepted and commented on the one's that are relevant. Can you be more specific – vijay pujar Sep 07 '14 at 22:45

1 Answers1

1

Yes, you can. The part that goes directly under Feature: … is mostly useless from the functionality perspective and used as documentation. AFIAK you can delete it or write there anything you want, your tests will run exactly the same.

What you are looking for are scenario outlines, they are intended exactly for that, though you'll need to update a few of your scenarios and still manually specify each user under Examples.

Feature: End to end tests 

    I want an End to End test pack
    As Super user and Admin user
    So that I can ensure that the integrated components of the application function as expected

    Background:
        Given I have the login Page

    @javascript
    Scenario Outline: To verify the functionality on the Dashboard         
        When I login to application as "<username>" with "<password>"
        Then the list is displayed
        When I navigate to the Dashboard Page
        Then the Dashboard Page is displayed

    Examples:
        | username | password |
        |  super   |  qwerty  |
        |  admin   |  qwerty  |

/**
 * @When /^I login to application$/
 * @When /^I login to application as "(.+)" with "(.+)"$/
 */
public function iLoginToApplication($username = null, $password = null) {
    $page = $this->getSession()->getPage();
    $page->find('css', '#username')->setValue(isset($username) ? $username : 'admin');
    $page->find('css', '#password')->setValue(isset($password) ? $password : 'Password');
    $signInButton->press();
}

Another approach is to configure this on the global scale prior running the suites, e.g., passing environment variable with the user name to PHP when you run Behat, and run everything several times with different configuration. This would be a hack of the solution above and not as intuitive, so you'd be better off with doing it the Behat way.

Ian Bytchek
  • 8,804
  • 6
  • 46
  • 72
  • Thanks a lot for the reply. I'm going to try this solution when our environment is back up and running – vijay pujar Sep 09 '14 at 14:55
  • Let me know if it does the job. – Ian Bytchek Sep 09 '14 at 15:09
  • Hi Ian, I'm trying to use that solution. However the issue is using it in my context file. Can I pass this as an argument to my context file. Please refer to the description above for the context: – vijay pujar Sep 09 '14 at 15:14
  • So when I run the test, it only passes for the second user, since it is in my context file and fails for the "Super" user. How can I pass the username as an argument to the method. – vijay pujar Sep 09 '14 at 15:19
  • See the update. It works exactly the same as any other step definition / context. In the above example you can either use default values or you can specify the username and password. – Ian Bytchek Sep 09 '14 at 15:28
  • 1
    That's a brilliant answer. Thanks very much. – vijay pujar Sep 09 '14 at 15:49