简体   繁体   中英

How to run the same BDD features multiple times using different user roles

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();
}

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, eg, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM