Using Serenity with Appium enables you to write automated mobile tests in a BDD style (using Cucumber or JBehave) while taking advantage of Serenity’s rich reporting and test management features.

What Is Serenity Appium?

ComponentRole
SerenityTest automation framework with reporting, screen recording, BDD
AppiumMobile automation engine for Android and iOS
CucumberBDD framework to define tests in Gherkin syntax (optional)

1. Dependencies (Maven)

Add this to your pom.xml:

<dependencies> <!-- Serenity core --> <dependency> <groupId>net.serenity-bdd</groupId> <artifactId>serenity-core</artifactId> <version>3.6.12</version> </dependency> <!-- Serenity Appium --> <dependency> <groupId>net.serenity-bdd</groupId> <artifactId>serenity-appium</artifactId> <version>3.6.12</version> </dependency> <!-- Serenity Cucumber (optional) --> <dependency> <groupId>net.serenity-bdd</groupId> <artifactId>serenity-cucumber6</artifactId> <version>3.6.12</version> </dependency> <!-- Cucumber & JUnit --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <version>6.11.0</version> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-junit</artifactId> <version>6.11.0</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> </dependency> </dependencies>

2. Serenity Appium Test Example

MobileLoginSteps.java

import io.appium.java_client.MobileElement; import net.thucydides.core.annotations.Step; import net.thucydides.core.steps.ScenarioSteps; public class MobileLoginSteps extends ScenarioSteps { private MobileLoginPage loginPage; @Step("User logs in with valid credentials") public void login(String username, String password) { loginPage.enterUsername(username); loginPage.enterPassword(password); loginPage.clickLogin(); } }

MobileLoginPage.java

import io.appium.java_client.AppiumDriver; import io.appium.java_client.MobileElement; import net.serenitybdd.core.pages.PageObject; import org.openqa.selenium.support.FindBy; public class MobileLoginPage extends PageObject { @FindBy(id = "com.example:id/username") private MobileElement usernameField; @FindBy(id = "com.example:id/password") private MobileElement passwordField; @FindBy(id = "com.example:id/loginButton") private MobileElement loginButton; public void enterUsername(String username) { usernameField.sendKeys(username); } public void enterPassword(String password) { passwordField.sendKeys(password); } public void clickLogin() { loginButton.click(); } }

3. serenity.conf

webdriver { driver = appium } appium { platformName = "Android" deviceName = "emulator-5554" app = "src/test/resources/apps/your_app.apk" automationName = "UiAutomator2" }

4. Cucumber Feature File (optional)

Feature: Mobile Login Scenario: Login with valid credentials Given the app is launched When I login with "admin" and "password123" Then I should see the home screen

5. Test Runner

@RunWith(CucumberWithSerenity.class) @CucumberOptions(features = "src/test/resources/features") public class MobileTestRunner {}