Today we are going to learn how to use Scenario Outline and Examples in cucumber?. If you are new to cucumber functional automated testing than please go through my blog post
Cucumber basic concept
First-of-all create a feature file as LoginTest.feature and add these lines of code in that
1 2 3 4 5 6 7 8 9 10 11 |
[php] Scenario Outline: Successful login as a carer Given I go to the start page When I enter username "<userName>" and password "<Password>" Then I am logged in Examples: |userName |Password | |userName1 |Password1| |userName2 |Password2| |userName3 |Password3| [/php] |
Scenario Outlines, any
1 |
[php]< >[/php] |
delimited tokens will be substituted with values from the example tables to corresponding step like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
[php] import org.junit.Assert import org.openqa.selenium.By import static cucumber.api.groovy.EN.* WebDriver driver = new FirefoxDriver() Given (~'^I go to the start page Scenario Outline and Examples help us to reduce line of code and it checks one scenario with different inputs. ) {-> driver.get("http://localhost:8080/application") } When (~'^I enter username "([^"]*)" and password "([^"]*)" Scenario Outline and Examples help us to reduce line of code and it checks one scenario with different inputs. ){String username, String password -> driver.findElement(By.id("j_username")).sendKeys(userName) driver.findElement(By.id("j_password")).sendKeys(password) driver.findElement(By.id("loginButton")).click() } Then (~'^I am logged in Scenario Outline and Examples help us to reduce line of code and it checks one scenario with different inputs. ) { -> Assert.assertEquals("http://localhost:8080/application/success", driver.getCurrentUrl()) Assert.assertTrue(driver.findElement( By.name("logoutLink")).getText().contains("Logout") ) } [/php] |
Scenario Outline and Examples help us to reduce line of code and it checks one scenario with different inputs.
Recent Comments