Mobile App Testing
Mobile App Test Automation: Selenium & Cucumber Insights
Introduction
Automate mobile app test automation with Selenium, Cucumber, and Appium. Boost efficiency, scalability, and streamline CI/CD with BDD and parallel execution.
Selenium, Cucumber, and Appium have played a pivotal role in automating mobile application testing within modern mobile development app projects. These tools simplify repetitive tasks and empower teams to ensure robust quality throughout the development of app lifecycles. This article shares real-world experience with Selenium, Cucumber, and Appium, detailing practical challenges, solutions, and best practices that emerged while working on mobile app test automation.
Why Selenium, Cucumber & Appium for Mobile Application Development
Appium builds on Selenium by extending selenium java automation to cover native, hybrid, and mobile web applications on both iOS and Android platforms. Furthermore, Appium’s unified API enables testers and developers to automate across multiple platforms more efficiently and with less effort. In addition, Cucumber supports behaviour driven development testing (BDD), which helps bridge the gap between technical teams and stakeholders by allowing them to write human-readable test scenarios using Gherkin syntax. Moreover, Cucumber integrates seamlessly with both Selenium and Appium, providing a strong foundation for building scalable and maintainable mobile test automation frameworks. Therefore, combining these tools creates a powerful, collaborative environment that streamlines the mobile app testing process from development through to deployment.
Appium Extends Selenium Java for Mobile App Testing
The team created a Maven project defining dependencies for Selenium, Cucumber, and Appium in the pom.xml
. They included device-specific configurations and Appium server settings to support the mobile web app and native app testing environments. Below is a key dependency snippet:
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.10.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.10.0</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.4.0</version>
</dependency>
</dependencies>
The team configured Cucumber with cucumberOptions
in the test runner class to define feature files and step definitions, which helped the framework scale as the application testing grew in complexity.
Real-World Mobile Application Testing Challenges
Using Appium and Cucumber, the team automated key functionalities including biometric login, appointment scheduling, and pet medical history tracking. They ensured consistent UI behaviour across devices with varying screen sizes.
Android and iOS require different locators, which the team managed using Appium’s MobileBy
class. They overcame challenges in managing multiple devices for parallel execution by configuring Appium servers with unique ports per device:
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformName", "Android");
caps.setCapability("deviceName", "Pixel_5_API_30");
caps.setCapability("app", "path/to/app.apk");
caps.setCapability("automationName", "UiAutomator2");
Appium tests integrated within Cucumber scenarios allowed consistent reporting and execution.
Parallel Testing in CI/CD for Test Automation
To reduce execution time, the team used Cucumber’s integration with JUnit for parallel testing of device-specific scenarios. This approach saved hours during nightly builds. They ensured thread safety of Appium instances by implementing a thread-local factory. To handle synchronization and avoid race conditions, they used FluentWait:
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/resources/features",
glue = "com.example.steps",
plugin = {"pretty", "json:target/cucumber-report.json"},
monochrome = true
)
public class TestRunner {}
However, thread safety became an issue. Since multiple tests ran concurrently, each Appium instance needed to remain isolated. We addressed this by implementing a thread-local factory for device management.
Wait<WebDriver> wait = new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofSeconds(2))
.ignoring(NoSuchElementException.class);
Additionally, synchronization issues led to test failures due to race conditions. Instead of using fixed delays, we incorporated FluentWait to dynamically wait for elements:
Implementing Page Object Model for Mobile App Testing
To improve maintainability, they adopted the Page Object Model, encapsulating locators and actions for each screen in dedicated classes. They extended this approach to handle platform-specific actions.
Sample Login Feature & Step Definitions
Feature: Login to PETcare App
Scenario: User logs in with valid credentials
Given the user is on the login screen
When the user enters valid credentials
And clicks the login button
Then the user should be redirected to the homepage
Corresponding Step Definitions in Java
package com.example.steps;
import io.cucumber.java.en.*;
import com.example.pages.LoginPage;
public class LoginSteps {
LoginPage loginPage = new LoginPage();
@Given("the user is on the login screen")
public void userOnLoginScreen() {
loginPage.navigateToLoginScreen();
}
@When("the user enters valid credentials")
public void userEntersCredentials() {
loginPage.enterUsername("testUser");
loginPage.enterPassword("password123");
}
@And("clicks the login button")
public void clickLogin() {
loginPage.clickLoginButton();
}
@Then("the user should be redirected to the homepage")
public void verifyHomePage() {
loginPage.verifyHomePage();
}
}
Benefits of Behavior Driven Test Automation
Readable, maintainable tests helped teams collaborate with non-technical stakeholders through clear Gherkin syntax. The reuse of step definitions reduced code duplication, while confining locator updates to page classes simplified test maintenance.
Best Practices for Scalable Automation
When planning for scalability, it is essential to organise feature files and step definitions by functionality because this approach significantly improves test management. Furthermore, externalising test data using Excel or JSON files not only increases flexibility but also supports test development driven methodologies effectively. In addition, replacing brittle Thread.sleep()
calls with FluentWait or ExpectedConditions greatly enhances reliability and test stability. Moreover, maximising reusability through reusable Appium factories, custom assertions, and reporting utilities strengthens the entire automation framework. Finally, investing in reporting tools such as Allure provides clearer and more actionable insights into test results, which ultimately helps teams improve their testing strategies and outcomes.
Conclusion
Selenium, Cucumber, and Appium together form a powerful testing platform for mobile application development and web app testing. Moreover, by leveraging behaviour-driven development, parallel execution, Page Object Model, and data-driven testing techniques, teams can ensure scalability and robustness in automation testing frameworks. Whether you are just starting or scaling your automation efforts, these tools provide a solid foundation for success. In addition, they are well-suited for modern mobile app testing tools environments, enabling efficient and effective testing processes.
Enhance your mobile app testing with Selenium, Cucumber, and Appium for faster, more reliable automation. Our experts can help you build a scalable framework tailored to your needs. Contact us now to streamline your testing process and boost efficiency!
WRITTEN BY
February 14, 2025, Product Development Team
Top Categories
- Software Development ................... 7
- AI in Business ................... 5
- Digital Transformation ................... 4
- Digital Marketing ................... 3
- Business Technology ................... 3