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

Now use this command to run test case and see what happens

You will get this

Now create a LoginTest_step.groovy class in cucumber folder and add missing steps in that.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

Now run the test case,it will get passed.
We’re done with our first Cucumber functional automated testing.