Today we are going to learn cucumber functional automated testing basic concept with example. If you are new to cucumber than please go through my cucumber set-up blog.
Cucumber set-up step
Before starting our testing we will know some basic about
1.How to create feature file?
2.How to create step file corresponding to feature file?
Feature file contains human readable specification. A specification contains various scenarios and all scenarios needs to be executed successfully. A scenario contains at least three part
- Given
- When
- Then
Create LoginTest.feature file inside the cucumber folder and add these lines in that
1 2 3 4 5 6 7 8 9 10 |
[php] Feature: Logging in to Application Scenario: Successful login as a carer Given I go to the start page When I enter username "userName" and password "Password1" Then I am logged in When I logout Then I am not logged in [/php] |
Now use this command to run test case and see what happens
1 2 3 |
[php] grails test-app functional:cucumber [/php] |
You will get this
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
[php] | Running 1 cucumber test... 1 Scenarios ( 1 undefined ) 3 Steps ( 3 undefined ) 0m 0.237s You can implement missing steps with the snippets below: Given (~'^I go to the start page Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that. <pre>[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 Now run the test case,it will get passed. We're done with our first Cucumber functional automated testing. ) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } When (~'^I enter username "([^"]*)" and password "([^"]*)" Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that. <pre wp-pre-tag-3=""></pre> Now run the test case,it will get passed. We're done with our first Cucumber functional automated testing. ){String username, String password -> // Express the Regexp above with the code you wish you had throw new PendingException() } Then (~'^I am logged in Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that. <pre wp-pre-tag-3=""></pre> Now run the test case,it will get passed. We're done with our first Cucumber functional automated testing. ) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } When(~'^I logout Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that. <pre wp-pre-tag-3=""></pre> Now run the test case,it will get passed. We're done with our first Cucumber functional automated testing. ){->; // Express the Regexp above with the code you wish you had throw new PendingException() } Then (~'^I am not logged in Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that. <pre wp-pre-tag-3=""></pre> Now run the test case,it will get passed. We're done with our first Cucumber functional automated testing. ) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } | Completed 1 cucumber test, 1 failed in 605ms | Tests FAILED [/php] |
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) {-> driver.get(“http://localhost:8080/application”) } When (~’^I enter username “([^”]*)” and password “([^”]*)”
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } When (~’^I enter username “([^”]*)” and password “([^”]*)”
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
){String username, String password -> // Express the Regexp above with the code you wish you had throw new PendingException() } Then (~’^I am logged in
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } When(~’^I logout
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
){->; // Express the Regexp above with the code you wish you had throw new PendingException() } Then (~’^I am not logged in
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } | Completed 1 cucumber test, 1 failed in 605ms | Tests FAILED [/php]
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
){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
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } When (~’^I enter username “([^”]*)” and password “([^”]*)”
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
){String username, String password -> // Express the Regexp above with the code you wish you had throw new PendingException() } Then (~’^I am logged in
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } When(~’^I logout
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
){->; // Express the Regexp above with the code you wish you had throw new PendingException() } Then (~’^I am not logged in
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } | Completed 1 cucumber test, 1 failed in 605ms | Tests FAILED [/php]
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) { -> Assert.assertEquals(“http://localhost:8080/application/success”, driver.getCurrentUrl()) Assert.assertTrue(driver.findElement( By.name(“logoutLink”)).getText().contains(“Logout”) ) } When(~’^I logout
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } When (~’^I enter username “([^”]*)” and password “([^”]*)”
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
){String username, String password -> // Express the Regexp above with the code you wish you had throw new PendingException() } Then (~’^I am logged in
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } When(~’^I logout
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
){->; // Express the Regexp above with the code you wish you had throw new PendingException() } Then (~’^I am not logged in
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } | Completed 1 cucumber test, 1 failed in 605ms | Tests FAILED [/php]
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
){-> driver.findElement(By.name(“logout”)).click() } Then (~’^I am not logged in
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } When (~’^I enter username “([^”]*)” and password “([^”]*)”
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
){String username, String password -> // Express the Regexp above with the code you wish you had throw new PendingException() } Then (~’^I am logged in
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } When(~’^I logout
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
){->; // Express the Regexp above with the code you wish you had throw new PendingException() } Then (~’^I am not logged in
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } | Completed 1 cucumber test, 1 failed in 605ms | Tests FAILED [/php]
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) {-> Assert.assertEquals(“http://localhost:8080/application”, driver.getCurrentUrl()) } [/php]
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } When (~’^I enter username “([^”]*)” and password “([^”]*)”
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
){String username, String password -> // Express the Regexp above with the code you wish you had throw new PendingException() } Then (~’^I am logged in
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } When(~’^I logout
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
){->; // Express the Regexp above with the code you wish you had throw new PendingException() } Then (~’^I am not logged in
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
) { ->; // Express the Regexp above with the code you wish you had throw new PendingException() } | Completed 1 cucumber test, 1 failed in 605ms | Tests FAILED [/php]
Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.
1 |
Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.
Recent Comments