Appium is an open-source tool. With the help of this utility, mobile apps for iOS, Android, and Windows shall be automated. The users shall use standard programming languages like Python, Java, JavaScript, C#, Ruby, etc. to construct automation tests. They shall also use Appium to automate human-like behaviors within mobile apps, such as inputting text, touching buttons, swiping, and answer validation.
Adopting the Page Object Model (POM) design pattern may significantly improve the readability, reusability, and maintainability of your test automation framework when utilizing Appium with Java for mobile automation. By keeping test automation logic and online or mobile page representation separate, the Page Object Model encourages an organized approach to writing test code.
The Page Object Model is a design pattern used in test automation to encapsulate the functionalities and elements of a web or mobile page into separate classes called “Page Objects.” Each Page Object represents a specific page or component of the application under test.
Locators:
public class SignInPage extends BasePage {
private final HashMap<String, By> LblErrorInvalidLogin = new HashMap<String, By>() {{
put("Android", AppiumBy.xpath("//android.view.View[@content-desc=\"We didn't recognize this email or password.\"]"));
put("iOS", AppiumBy.xpath(""));
}};
private final HashMap<String, By> txtPassword = new HashMap<String, By>() {{
put("Android", AppiumBy.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.View/android.view.View/android.view.View/android.view.View/android.widget.ScrollView/android.view.View[3]"));
put("iOS", AppiumBy.xpath(""));
}};
private final HashMap<String, By> btnContinue = new HashMap<String, By>() {{
put("Android", AppiumBy.xpath("//android.widget.Button[@content-desc=\"Continue\"]"));
put("iOS", AppiumBy.xpath(""));
}};
private final HashMap<String, By> lblLogged = new HashMap<String, By>() {{
put("Android", AppiumBy.xpath("//android.view.View[@content-desc=\"Welcome to the team, Rayan!\"]"));
put("iOS", AppiumBy.xpath(""));
}};
Methods in page objects:
public SignInPage(AppiumDriver driver) {
super(driver);
}
public SignInPage enterEmail(String email) {
Actions.clickElement(txtEmail, 30, 10000);
Actions.sendText(txtEmail, email, 30, 10000);
return this;
}
public SignInPage enterPassword() {
Actions.clickElement(txtPassword, 30, 10000);
return this;
}
//android.widget.Button[@content-desc="Continue"]
public SignInPage clickContinue() {
Actions.scrollElement("Continue");
Actions.clickElement(btnContinue, 30, 10000);
return this;
}
public boolean welcomeNoteDisplay() {
boolean isWelcomeDisplayed=Actions.isDisplayedCheck(lblLogged, 30, 10000);
return isWelcomeDisplayed;
}
Test Class:
public class LoginTest extends TestNGListener {
LaunchPage launchPage;
FilterPage filter;
SignInPage login;
ProcessPage chargeProcess;
AccountPage account;
HomePage home;
AccountSettingsPage settings;
@Test(dataProvider = "platforms", testName = "Login Functionality-Valid", description = "care crown login validation with valid credentials")
public void loginIntoApplicationValidCase(String platform) throws InterruptedException {
launchPage = PageFactory.getInstance(LaunchPage.class);
login = PageFactory.getInstance(SignInPage.class);
filter = PageFactory.getInstance(FilterPage.class);
chargeProcess = PageFactory.getInstance(ProcessPage.class);
account = PageFactory.getInstance(AccountPage.class);
home = PageFactory.getInstance(HomePage.class);
LaunchPage launchPage = PageFactory.getInstance(LaunchPage.class);
launchPage.clickGetStarted().clickLogin();
login.enterEmail(Constants.EMAIL).enterPassword();
Actions.keyStoreEventOnAndroidPassword();
login.clickContinue();
if (login.welcomeNoteDisplay()) {
login.loggedInValidation();
} else {
home.clickhamburgerIcon().NameInHamburger();
}
}
@Test(dataProvider = "platforms", testName = "Login Functionality-Invalid", description = "care crown login validation with invalid credentials")
public void loginIntoApplicationInvalidCase(String platform) throws InterruptedException {
launchPage = PageFactory.getInstance(LaunchPage.class);
login = PageFactory.getInstance(SignInPage.class);
home = PageFactory.getInstance(HomePage.class);
LaunchPage launchPage = PageFactory.getInstance(LaunchPage.class);
launchPage.clickGetStarted().clickLogin();
login.enterEmail(Constants.INVALID_EMAIL).enterPassword();
Actions.keyStoreEventOnAndroidPassword();
login.clickContinue();
login.invalidLoginValidation();
}
}
The LoginTest class exemplifies the implementation of automated tests for login functionality in a mobile application using the Page Object Model (POM) design pattern. By organizing test logic into separate methods and leveraging Page Objects, the test suite becomes more maintainable and scalable.
launchPage = PageFactory.getInstance(LaunchPage.class);
login = PageFactory.getInstance(SignInPage.class);
home = PageFactory.getInstance(HomePage.class);
<suite thread-count="1" verbose="1" name="Demo Android TestSuite" annotations="JDK" parallel="tests">
<parameter name="endpoint" value="https://Username:[email protected]/wd/hub"/>
<parameter name="host" value="BrowserStack" />
<!-- Structure for execution platform is <platform>:<deviceName(or)UUID>:<version> comma seperated multiples -->
<parameter name="executionPlatforms" value="Android:Samsung Galaxy S22 Ultra:12.0"/>
<parameter name="androidApp"I'm value=""/>
<parameter name="iosApp" value=""/>
<parameter name="browserStackAndroidApp" value="bs://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" />
<parameter name="BrowserStackiOSApp" value="" />
<parameter name="projectName" value="Regression execution" />
<parameter name="build" value="1.0" />
<parameter name="timezone" value="New_York" />
<parameter name="geolocation" value="US" />
<parameter name="browserstackUser" value="Username" />
<parameter name="browserstackKey" value="Password" />
<test thread-count="1" name="login" parallel="methods">
<classes>
<class name="tests.LoginTest"/>
</classes>
</test>
</suite>
The XML configuration file (testng.xml) plays a pivotal role in defining the test suite structure and configuring the test execution environment on BrowserStack. By utilizing this configuration, you can seamlessly integrate Appium tests with BrowserStack for automated testing on real devices in the cloud.
An XML configuration file is used to execute Appium tests on BrowserStack. This configuration file defines various parameters and settings required for running automated tests on real devices in the BrowserStack cloud.
The XML configuration file (testng.xml) is used with TestNG to orchestrate test execution and specify BrowserStack-specific parameters.
BrowserStack flow
BrowserStack facilitates the execution of Appium tests on real mobile devices in the cloud. After running tests on BrowserStack, detailed execution reports and insights are provided to assist in analyzing test results effectively.
BrowserStack App Automate is a cloud-based testing platform that enables automated testing of mobile applications using Appium and Selenium WebDriver. It allows you to execute tests on a wide range of real iOS and Android devices, ensuring comprehensive test coverage across different device configurations.
When you execute Appium tests on BrowserStack’s App Automate, the following details and insights are displayed post-execution:
After the test execution completes on BrowserStack App Automate, you can access comprehensive test reports containing:
BrowserStack App Automate seamlessly integrates with Continuous Integration (CI) platforms like Jenkins, CircleCI, and Azure DevOps, allowing for automated test execution as part of your CI/CD pipeline. This ensures consistent and efficient testing across your development lifecycle.
When a test fails in BrowserStack:
BrowserStack’s App Automate service offers comprehensive insights and detailed reports for failed test cases, empowering teams to diagnose, debug, and resolve issues efficiently during mobile app testing. By leveraging the provided information, you can streamline your debugging process and ensure the quality of your mobile applications.
When a test case fails during execution on BrowserStack’s App Automate, detailed information and insights are provided to assist in identifying the root cause of the failure. Here’s a breakdown of the details you can expect to see for failed test cases in BrowserStack:
Executing multi-device automation testing using BrowserStack involves leveraging BrowserStack’s capabilities to run automated tests across various devices, browsers, and operating systems simultaneously. BrowserStack provides a cloud-based platform that allows you to perform cross-browser testing efficiently. Here’s a general guide on how to set up and execute multi-device automation testing using BrowserStack:
Parallel Testing: BrowserStack supports parallel testing, allowing you to run multiple test sessions concurrently to reduce testing time.
Changes to be made in the XML file for multi-device execution:
<suite thread-count="1" verbose="1" name="Demo Android TestSuite" annotations="JDK" parallel="tests">
<parameter name="endpoint" value="https://Username:[email protected]/wd/hub"/>
<parameter name="host" value="BrowserStack" />
<!-- Structure for execution platform is <platform>:<deviceName(or)UUID>:<version> comma-separated multiples -->
<parameter name="executionPlatforms" value="Android: Samsung Galaxy S22 Ultra:12.0, Device 2, Device 3, Device 4, Device 5"/>
<parameter name="androidApp" value=""/>
<parameter name="iosApp" value=""/>
<parameter name="browserStackAndroidApp" value="bs://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" />
<parameter name="BrowserStackiOSApp" value="" />
<parameter name="projectName" value="Regression execution" />
<parameter name="build" value="1.0" />
<parameter name="timezone" value="New_York" />
<parameter name="geolocation" value="US" />
<parameter name="browserstackUser" value="Username" />
<parameter name="browserstackKey" value="Password" />
<test thread-count="1" name="login" parallel="methods">
<classes>
<class name="tests.LoginTest"/>
</classes>
</test>
</suite>