How to Automate Appium for Hybrid App Automation? – Devstringx

Back to Blog
Feature image for Appium blog

How to Automate Appium for Hybrid App Automation? – Devstringx

Definition of Automation

Automation define as it is a method of testing software products with special testing tools and frameworks to minimize human intervention and maximize product quality.

Automation Testing is done with the help of automation Software, and it controls the flow of the execution of tests as per the written scripts. They are then compared with the predicted outcomes to ensure the quality and reliability of the application.


An Appium is an open-source automation tool, it use to automate native and hybrid mobile applications for both ios and android. Withappium, cross–Appium platform testing is simple and the same test script can use for multiples platform.

What Is an Automation Framework?

Framework support automation testing as a technical implementation guideline. The automation framework not only offers the benefit of re-using the code in various scenarios. But it helps the team to write the test script in a standard format. Some are the following advantages

  • Framework help in maintaining a well–defined strategy across the test suites
  • Framework enhanced speed at which testing progresses.
  • Framework help in easily maintaining the whole code
  • We can easily test the application many times as required.

The test automation framework very helps full because we added the test script as we want and run it many times so it saves a lot of time which is a waste of checking manually.

Here We Discuss a Hybrid Framework

A hybrid testing framework is simply defined as a testing framework that has well-defined and well-organized steps to automate the application and it is a mix of both the data Driven and Keyword Driven frameworks.

What is Data-Driven?
  • It define as it is a method in which test data store in table or spreadsheet format. It allows a tester to create a test script where test data or output are read from data files instead of using the same hard–coded value each time the test runs. By doing this the applications handle various inputs effectively. There are multiple ways.
  • Data pools
  • Excel files­­­­­­­
  • ADO objects etc

Selenium Framework Image

Resources Required to Create a Hybrid Framework
  • Eclipse: Download Eclipse and install it.
  • JDK Setup: Download the JDK and install it.

After that check the java version in cmd by running this command

  • javav
  • Node js &npm: Download the NodeJs and install them.

Image to download NodeJs


  • After that check the version in cmd by running this command:
    • node –version
    • npm  -v


Install Appium with Nodejs and after the installation checks the version.

  • npm install –g appium
  • appium –version

Image of NodeJs Command

Check Appium and start the Appium server by entering the command in cmd:

    • Appium

Image of Welcome to Appium

Create a Maven Project Using Java

Click on Eclipse -> click on File -> click on Project -> click on Maven Project->Type Project Name

Path to create Maven project


Code for Driver Page

Here we write code for the set desired Capabilities for set the all required data like UDID, PLATFORM NAME, etc. for the ANDROID AND IOS devices both.

package init;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;

publicclass DriverFactory {
    publicfinalstaticintTIMEOUT_SECONDS = 8000;
    public DesiredCapabilities capability;
    publicstatic AppiumDriverLocalService service;
    publicstatic AppiumServiceBuilder builder;
    privatestatic ThreadLocal<AppiumDriver<MobileElement>>mobileDriver = newThreadLocal<AppiumDriver<MobileElement>>();

    privatestatic Logger log = Logger.getLogger(DriverFactory.class);
    static Map<String, AppiumDriver<MobileElement>>map = new HashMap<String, AppiumDriver<MobileElement>>();

public DriverFactory() throws IOException {

    switch (Config.PLATFORM_NAME.toLowerCase()) {

        capability = new DesiredCapabilities();
        capability.setCapability("deviceName", Config.DEVICE_NAME);
        capability.setCapability("udid", Config.DEVICE_UDID.trim());
        capability.setCapability("app", Config.APP);
        capability.setCapability("autoGrantPermissions", true);
        capability.setCapability("gpsEnabled", true);
        capability.setCapability("noReset", true);			
capability.setCapability("newCommandTimeout", TIMEOUT_SECONDS);
mobileDriver.set(new AndroidDriver<MobileElement>(
new URL(""+ Config.PORT_NUMBER + "/wd/hub"), capability));

getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);"Driver initialized for Appium on Android...");

    capability = new DesiredCapabilities();
    capability.setCapability("deviceName", Config.DEVICE_NAME);
    capability.setCapability("udid", Config.DEVICE_UDID.trim());
    capability.setCapability("app", Config.APP);
    capability.setCapability("newCommandTimeout", TIMEOUT_SECONDS);
mobileDriver.set(new IOSDriver<MobileElement>(new URL("" + Config.PORT_NUMBER + "/wd/hub"),capability));
    getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);"Driver initialized for Appium on IOS...");

        thrownew RuntimeException("Please provide correct platform...");


publicstaticsynchronizedvoid setDriver(AppiumDriver<MobileElement>remote) {

    publicstaticsynchronized AppiumDriver<MobileElement> getDriver() {

    publicstaticvoid unloadDriver() {
Pom File
  • POM means Project Object Model. It is a fundamental unit of work in maven; it is an XML file that contains information about the project and configuration details used by maven to build the project. We need to set all the required dependencies, so here all the important dependencies add in the pom.xmlfiles example below.
  • To get the dependencies we refer to this site:  Maven Repository
  • Add dependencies for Java client
  • Add dependencies for selenium
  • Add dependencies for Appium.
  • Add dependencies for TestNG

All the important dependencies are given below for the projects

        <!-- -->
        <!-- -->
        <!-- -->
            <!-- -->
        <!-- -->
<reportsDirectory>${project.basedir}/ReportNG Reports</reportsDirectory>
Annotation Use In The Program

Annotation is a feature introduce and use to add metadata to java code. This will allow you to add some information to an existing data object in your source code. It can be applied to classes, methods, variables, and parameters.

@BeforeSuite ,@AfterSuite ,@BeforeTest etc.

To read more details about the TestNG Annotation please refer to this link.

So, Here is the first scenario:-

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
publicclass DashboardTests {
    public DriverFactory driverFactory;
    public AppiumDriver<MobileElement>driver;
    public AppiumDriver<MobileElement>driver2;
    public DriverFactoryBrowser driverFactory2;
@BeforeMethod(alwaysRun = true)
publicvoid startUp() throws IOException {
this.driverFactory = newDriverFactory ();
this.driver = DriverFactory.getDriver();
publicvoid verifyLoginWithPin()
{"verifyLoginWithPin() test started");
softAssert = new SoftAssert();
loginWorkflows.loginIntoVeociApp(driver, Config.USER_NAME, Config.PASSWORD);
softAssert.assertEquals(homePage.getDialogText(driver), Home.HOME_TITLE);
softAssert.assertAll();"verifyLoginWithPin() test completed");
ReportListener.logToReport("Pin login verified successfully");

publicvoid tearDown() 

Test Class

Publicclass LoginWorkflows extendsBasePage {
publicvoid loginIntoVeociApp(AppiumDriver<MobileElement>driver,String userName,String password) {
loginPage.enterUserName(driver, userName);
loginPage.enterPassword(driver, password);

Page Class

publicclass LoginPage extends BasePage {
By emailField = By.xpath("//*[@text='EMAIL']/..//android.widget.EditText");
By nextBtn = By.xpath("//android.widget.Button[@text='NEXT']");
By passwordField =By.xpath("//*[@text='Password']/..//android.widget.EditText");
By submitBtn = By.xpath("//android.widget.Button[@text='SUBMIT']");
By dialogText = By.xpath("//android.widget.TextView[@text='Home']");
publicvoidenterUserName(AppiumDriver<MobileElement>driver,String userName) {
enterData(driver, emailField, userName);
publicvoidclickOnNextButton(AppiumDriver<MobileElement>driver) {
    waitForElementVisibility(driver, nextBtn);
    click(driver, nextBtn);

publicvoidenterPassword(AppiumDriver<MobileElement>driver, String password) {
    enterData(driver, passwordField, password);
public String getDialogText(AppiumDriver<MobileElement>driver) {
    return getText(driver, dialogText);
publicvoidclickOnSubmitButton(AppiumDriver<MobileElement>driver) {
click(driver, submitBtn);

Related Articles

Share this post

Back to Blog