Home Appium Environment Setup Android Emulators iOS Simulators Appium Architecture Android chrome app automation Safari browser automation Appium Capabilities Inspecting android apps Native Android app automation Inspecting iOS app Native iOS app Automation Real Android Phone automation Real iPhone automation Element Identification Pressing button FaceId and TouchId Fingerprint automation Drag and Drop Tap and press Swipe gestures Hybrid app automation Execute script Synchronization in Appium Screenshots Page Object Models Cucumber and Appium Appium integration with azure Appium and Selenium Grid Running tests in browserstack Parallel testing Recording tests Mobile automation framework Errors and Exceptions in Appium Mobile automation test strategy Mobile automation challenges Appium QnA
Appium tests using cucumber
Some important points
- Cucumber is a very popular BDD framework
- We can write tests in Gherkin syntax
- We can use any Unit testing framework (junit, nunit etc) with Cucumber.
- 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.
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>5.0.0-RC1</version>
</dependency>
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();
});
}
}
Web development and Automation testing
solutions delivered!!