Cucumber in Appium

Some important points

  1. Cucumber is a very popular BDD framework
  2. We can write tests in Gherkin syntax
  3. We can use any Unit testing framework (junit, nunit etc) with Cucumber.
  4. You need to install cucumber for Java and gherkin plugins in IntelliJ IDEA

Before we dive into the example, let me tell you that you will need to add below dependency in the POM file. Note that version of this dependency and JDK (1.8.0.22) should be compatible. If you use incompatible versions, you would get into trouble.

Below feature file shows how we can write scenarios.

Feature: Calculator

Scenario: addition
  Given I click on battery setting
  Then battery settings should be displayed

Below code shows how to write the step definitions. If you are running the feature file using plugin, make sure that glue setting is set to the path of step definition class path.

package org.softpost.stepdefs;
import framework.DriverUtil;
import io.cucumber.java8.En;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.softpost.pages.Home;
import org.springframework.util.Assert;

public class MyStepdefs implements En {

    WebDriver driver = DriverUtil.getDriver();
    public MyStepdefs() {
        Given("^I click on battery setting$", () -> {
            Home home = new Home(driver);
            home.clickBattery();
            Thread.sleep(5000);
        });

        Given("^battery settings should be displayed$", () -> {
            Assert.isTrue(driver.findElement(By.id("sd")).isDisplayed());
            driver.quit();
        });
    }
}



Youtube | Facebook | Twitter | Website Home | Online Grocery Shopping Brisbane