Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

Category: Appium

Appium is an open-source mobile automation testing tool used to test web, native and hybrid applications. It supports multiple languages, including Java, PHP and Perl.

Category: Appium
  • Driver Client: Appium drives mobile applications as though it were a user. Using a client library you write your Appium tests which wrap your test steps and sends to the Appium server over HTTP.
  • Appium Session: You have to first initialize a session, as such Appium test takes place in the session. Once the Automation is done for one session, it can be ended and wait for another session
  • Desired Capabilities: To initialize an Appium session you need to define certain parameters known as “desired capabilities” like PlatformName, PlatformVersion, Device Name and so on. It specifies the kind of automation one requires from the Appium server.
  • Driver Commands: You can write your test steps using a large and expressive vocabulary of commands.
Category: Appium

Yes, it is possible to interact with App while using Javascript. When the commands run on Appium, the server will send the script to your app wrapped into an anonymous function to be executed.

Category: Appium
  • Appium does not support testing of Android Version lower than 4.2
  • Limited support for hybrid app testing. E.g., not possible to test the switching action of application from the web app to native and vice-versa
  • No support to run Appium Inspector on Microsoft Windows
Category: Appium

To find the DOM element use “UIAutomateviewer” to find DOM element for Android application.

Category: Appium
  • Appium is an “HTTP Server” written using Node.js platform and drives iOS and Android session using Webdriver JSON wire protocol. Hence, before initializing the Appium Server, Node.js must be pre-installed on the system
  • When Appium is downloaded and installed, then a server is setup on our machine that exposes a REST API
  • It receives connection and command request from the client and execute that command on mobile devices (Android / iOS)
  • It responds back with HTTP responses. Again, to execute this request, it uses the mobile test automation frameworks to drive the user interface of the apps. Framework like
  • Apple Instruments for iOS (Instruments are available only in Xcode 3.0 or later with OS X v10.5 and later)
  • Google UIAutomator for Android API level 16 or higher
  • Selendroid for Android API level 15 or less
  • It responds back with HTTP responses. Again, to execute this request, it uses the mobile test automation frameworks to drive the user interface of the apps. Framework like
  • Apple Instruments for iOS (Instruments are available only in Xcode 3.0 or later with OS X v10.5 and later)
  • Google UIAutomator for Android API level 16 or higher
  • Selendroid for Android API level 15 or less
Category: Appium

Appium support any language that support HTTP request like Java, JavaScript with Node.js, Python, Ruby, PHP, Perl, etc.

Category: Appium

Appium has an “Inspector” to record and playback. It records and plays native application behavior by inspecting DOM and generates the test scripts in any desired language. However, Appium Inspector does not support Windows and use UIAutomator viewer in its option.

Category: Appium
  • Java Client uses AppiumServiceBuilder to start a node server programmatically. With the updated version, it works slightly differently with different Appium server versions.
  • The default URL for the server has been changed at the server-side and it does not contain the /wd/hub by default.
  • Java Client starting from v8.0.0 has made required changes to align to Appium V2.
  • If you still would like to use Java Client v8 with Appium 1.2.X then consider providing the –base-path explicitly while building the AppiumServiceBuilder.
// From Appium 2.0 Beta
AppiumDriverLocalService service;
service = new AppiumServiceBuilder()
       .withIPAddress("127.0.0.1")
       .usingPort(4723)
       .build();
service.start();

// Older approach: Appium 1.22.X
AppiumDriverLocalService service;
service = new AppiumServiceBuilder()
       .withIPAddress("127.0.0.1")
       .withArgument(GeneralServerFlag.BASEPATH, "/wd/hub")
       .usingPort(4723)
       .build();
service.start();
Category: Appium
  • Java Development Kit (JDK) – It should have at least JDK version 8 or higher.
  • Android SDK version 22 has separate platforms and build tools, suitable for Appium.
  • Node.js is needed for a non-blocking event-based server to handle multiple WebDriver sessions for iOS and Android platforms.
  • Microsoft WebDriver– also known as WinAppDriver, Appium compatible WebDriver server – Need Windows 10 or above.
  • PDANet+ – It is a free application that converts Android and iOS mobile into Modem and enables tethering.
  • Appium – Client libraries and Desktop application of Appium is mandatory
  • GenyMotion – It is required to run Appium tests in multiple virtual Android devices in parallel.
  • ADT Plugin to access Android SDK within Eclipse.
  • Java Client Drivers are also known as language binding for creating testing in multiple programming languages.
  • Appium Client Libraries supports Appium extensions to WebDriver protocol by Appium Server.
Category: Appium
AppiumServiceBuilder() appiumLocalService = new AppiumServiceBuilder().usingAnyFreePort().build();
appiumLocalService.start();
Category: Appium
URL testAppUrl = getClass().getClassLoader().getResource("ApiDemos.apk");
File testAppFile = Paths.get(Objects.requireNonNull(testAppUrl).toURI()).toFile();
String testAppPath = testAppFile.getAbsolutePath();
Category: Appium
DesiredCapabilities desiredCaps = new DesiredCapabilities();
desiredCaps.setCapability(MobileCapabilityType.DEVICE_NAME, "android25-test");
desiredCaps.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.example.android.apis");
desiredCaps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
desiredCaps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1");
desiredCaps.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.Controls1");
desiredCaps.setCapability(MobileCapabilityType.APP, testAppPath);
Category: Appium

By ID : AndroidElement button = driver.findElementById(“com.example.android.apis:id/button”);
By Class : AndroidElement checkBox = driver.findElementByClassName(“android.widget.CheckBox”);
By XPath : AndroidElement secondButton = driver.findElementByXPath(“//*[@resource-id=’com.example.android.apis:id/button’]”);
By AndroidUIAutomator : AndroidElement thirdButton = driver.findElementByAndroidUIAutomator(“new UiSelector().textContains(\”BUTTO\”);”);

Category: Appium

TouchAction touchAction = new TouchAction(driver);
AndroidElement element = driver.findElementById(“android:id/content”);
Point point = element.getLocation();
Dimension size = element.getSize();
touchAction.press(PointOption.point(point.getX() + 5, point.getY() + 5))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(200)))
.moveTo(PointOption.point(point.getX() + size.getWidth() – 5, point.getY() + size.getHeight() – 5))
.release()
.perform();

Category: Appium
public void tapByElement (AndroidElement androidElement) {
        TouchAction touch = new TouchAction(driver);
            touch.tap(tapOptions().withElement(element(androidElement))).waitAction(waitOptions(ofMillis(250))).perform();
    }
Category: Appium
public void tapByCoordinates (int x,  int y) {
        TouchAction touch = new TouchAction(driver);
             touch.tap(point(x,y))
            .waitAction(waitOptions(ofMillis(250))).perform();
    }
Category: Appium
public void pressByElement (AndroidElement element, long seconds) {
        TouchAction touch = new TouchAction(driver);
             touch.press(element(element))
            .waitAction(waitOptions(ofSeconds(seconds)))
            .release()
            .perform();
    }
Category: Appium
    public void pressByCoordinates (int x, int y, long seconds) {
        TouchAction touch = new TouchAction(driver);
             touch.press(point(x,y))
            .waitAction(waitOptions(ofSeconds(seconds)))
            .release()
            .perform();
    }
Category: Appium
public void horizontalSwipeByPercentage (double startPercentage, double endPercentage, double anchorPercentage) {
    Dimension size = driver.manage().window().getSize();
    int anchor = (int) (size.height * anchorPercentage);
    int startPoint = (int) (size.width * startPercentage);
    int endPoint = (int) (size.width * endPercentage);
    TouchAction touch = new TouchAction(driver);
        touch.press(point(startPoint, anchor))
        .waitAction(waitOptions(ofMillis(1000)))
        .moveTo(point(endPoint, anchor))
        .release().perform();
}
Category: Appium
public void verticalSwipeByPercentages(double startPercentage, double endPercentage, double anchorPercentage) {
        Dimension size = driver.manage().window().getSize();
        int anchor = (int) (size.width * anchorPercentage);
        int startPoint = (int) (size.height * startPercentage);
        int endPoint = (int) (size.height * endPercentage);

         TouchAction touch = new TouchAction(driver);
             touch.press(point(anchor, startPoint))
            .waitAction(waitOptions(ofMillis(1000)))
            .moveTo(point(anchor, endPoint))
            .release().perform();
    }
Category: Appium
public void swipeByElements (AndroidElement startElement, AndroidElement endElement) {
        int startX = startElement.getLocation().getX() + (startElement.getSize().getWidth() / 2);
        int startY = startElement.getLocation().getY() + (startElement.getSize().getHeight() / 2);
        int endX = endElement.getLocation().getX() + (endElement.getSize().getWidth() / 2);
        int endY = endElement.getLocation().getY() + (endElement.getSize().getHeight() / 2);
        
        TouchAction touch = new TouchAction(driver);
             touch.press(point(startX,startY))
            .waitAction(waitOptions(ofMillis(1000)))
            .moveTo(point(endX, endY))
            .release().perform();
    }
Category: Appium
public void multiTouchByElement (AndroidElement androidElement) {
        TouchAction touch = new TouchAction(driver);
            touch.press(element(androidElement))
            .waitAction(waitOptions(ofSeconds(1)))
            .release();
         MultiTouchAction multiTouch = new MultiTouchAction(driver).
             multiTouch.add(touch)
            .perform();
    }
Category: Appium

Managing your mobile device capabilities need so much effort in case you change your device frequently. During the test, there are mandatory capabilities that you need to manage like “Platform Name”, “Device Version”, “Device Name” or “UDID” information.
You need to run ADB command to extract those kinds of data or you need to manually find them out.

You need to run ADB command to extract those kinds of data or you need to manually find them out.

Bahadır Üstün, has recently developed a library to fetch information from devices connected to your computer. It fetches any information that can be captured from your IOS or Android device.
Here is the library GitHub Link: https://github.com/Testinium/MobileDeviceInfo

You can add your project as a maven dependency.

You have to add our repository to your pom.xml because it hasn’t released to Maven Central repositories.

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PLATFORM, device.getDeviceProductName());
capabilities.setCapability("platformName", device.getDeviceProductName());
capabilities.setCapability(CapabilityType.VERSION, device.getProductVersion());
capabilities.setCapability("deviceName", device.getModelNumber());
capabilities.setCapability("udid", device.getUniqueDeviceID());
capabilities.setCapability("app", "#Your App File#");


driver = new RemoteWebDriver(new URL(URL), capabilities);
Category: Appium

UIAutomator is for Android only.
With UI Automator I can scroll and find element\elements with text\text contains\id\text starts with.
Searching for element via UIAutomator allows to actually scroll view up/down to the searchable element. First of all, it is a search action, you can use it for scrolling if you have a scrollable view and know element inside of it. So it requires:
View with scrollable=true attribute.
Know element id, text, etc. to locate it.
Can’t use coordinates.
Fails if element is not found.
Not precise, stops scrolling as soon as element is found.

  • MobileElement firstClickableEl = driver.findElement(MobileBy.AndroidUIAutomator(“new UiSelector().clickable(true)”))
  • MobileElement elementInView = driver.findElement(MobileBy.AndroidUIAutomator(“new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text(“‘ + text + ‘”).instance(0))’)

driver.swipe is with x and y coordinates.
Actions API is used for different gestures like touch, tap, drag&drop, swipe, etc.

  1. no need to locate elements
  2. Can use both coordinates and elements
  3. More precise if you pass the right coordinates
public void swipeScreen() {
    // final value depends on your app and could be greater
    final int ANIMATION_TIME = 200; // ms

    final int PRESS_TIME = 200; // ms

    int edgeBorder = 10; // better avoid edges
    PointOption pointOptionStart, pointOptionEnd;
    // init screen variables
    Dimension dims = driver.manage().window().getSize();

    // init start point = center of screen
    pointOptionStart = PointOption.point(dims.width / 2, dims.height / 2);
    pointOptionEnd = PointOption.point(dims.width / 2, dims.height - edgeBorder);

   TouchAction touch = new TouchAction(driver);
                touch.press(pointOptionStart)
                // a bit more reliable when we add small wait
                .waitAction(WaitOptions.waitOptions(Duration.ofMillis(PRESS_TIME)))
                .moveTo(pointOptionEnd)
                .release().perform();
}
Category: Appium
  • UIScrollable is a powerful Android class that performs element lookups in scrollable layouts. In most cases you should use “scrollIntoView” class which performs scroll action until the destination element is found on the screen.
  • We can use UIScrollable swipe in following cases: – search elements in a list (e.g. country list) – search elements outside of the screen (e.g. input field, text or button).
  • ScrollIntoView has UiSelector as search criteria input that allows you to find elements by: – by text (exact, contains, match, starts with or regex) – id (exact or regex) – some other methods (rarely used) see in Android developer documentation – a combination of available search methods.

Search by text

// Page object
@AndroidFindBy(uiAutomator = "new UiScrollable(new UiSelector().scrollable(true))" +
        ".scrollIntoView(new UiSelector().text(\"exact_text\"))")
MobileElement element;

@AndroidFindBy(uiAutomator = "new UiScrollable(new UiSelector().scrollable(true))" +
        ".scrollIntoView(new UiSelector().textContains(\"part_text\"))")
MobileElement element;

// FindElement
MobileElement element = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator(
        "new UiScrollable(new UiSelector().scrollable(true))" +
         ".scrollIntoView(new UiSelector().text(\"exact_text\"))"));

MobileElement element = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator(
        "new UiScrollable(new UiSelector().scrollable(true))" +
         ".scrollIntoView(new UiSelector().textContains(\"part_text\"))"));

Search by id

// Page object
@AndroidFindBy(uiAutomator = "new UiScrollable(new UiSelector().scrollable(true))" +
        ".scrollIntoView(new UiSelector().resourceIdMatches(\".*part_id.*\"))")
MobileElement element;

// FindElement
MobileElement element = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator(
        "new UiScrollable(new UiSelector().scrollable(true))" +
         ".scrollIntoView(new UiSelector().resourceIdMatches(\".*part_id.*\"))"));

Search by id and text

// Page object
@AndroidFindBy(uiAutomator = "new UiScrollable(new UiSelector().scrollable(true))" +
        ".scrollIntoView(new UiSelector().resourceIdMatches(\".*part_id.*\").text(\"exact_text\"))")
MobileElement element;

// FindElement
MobileElement element = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator(
        "new UiScrollable(new UiSelector().scrollable(true))" +
         ".scrollIntoView(new UiSelector().resourceIdMatches(\".*part_id.*\").text(\"exact_text\"))"));

Long view issue

For some longer views it is necessary to increase “setMaxSearchSwipes”. This value allows to set the maximum count of swipe retries made until the search is stopped.

// set max swipes to 10
// FindElement
MobileElement element = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator(
        "new UiScrollable(new UiSelector().scrollable(true)).setMaxSearchSwipes(10)" +
         ".scrollIntoView(new UiSelector().text(\"exact_text\"))"));
Category: Appium
Category: Appium
For Example:-
MobileElement elementOne = (MobileElement) driver.findElementByAccessibilityId("SomeAccessibilityID");
MobileElement elementTwo = (MobileElement) driver.findElementByClassName("SomeClassName");

List elementsOne = (List) driver.findElementsByAccessibilityId("SomeAccessibilityID");
List elementsTwo = (List) driver.findElementsByClassName("SomeClassName");
Category: Appium

Get Element Text
MobileElement element = (MobileElement) driver.findElementByClassName(“SomeClassName”);
String elText = element.getText();

Get Tag Name
MobileElement element = (MobileElement) driver.findElementByAccessibilityId(“SomeAccessibilityID”);
String tagName = element.getTagName();

Get Element Attribute
MobileElement element = (MobileElement) driver.findElementByAccessibilityId(“SomeAccessibilityID”);
String tagName = element.getAttribute(“content-desc”);

Is Element Selected
Determine if a form or form-like element (checkbox, select, etc…) is selected
MobileElement element = (MobileElement) driver.findElementByAccessibilityId(“SomeAccessibilityID”);
boolean isSelected = element.isSelected();

Is Element Enabled
MobileElement element = (MobileElement) driver.findElementByAccessibilityId(“SomeAccessibilityID”);
boolean isEnabled = element.isEnabled();

Is Element Displayed
MobileElement element = (MobileElement) driver.findElementByAccessibilityId(“SomeAccessibilityID”);
boolean isDisplayed = element.isDisplayed();

Get Element Location
Determine an element’s location on the page or screen
MobileElement element = (MobileElement) driver.findElementByAccessibilityId(“SomeAccessibilityID”);
Point location = element.getLocation();

Get Element Size
Determine an element’s size in pixels
MobileElement element = (MobileElement) driver.findElementByAccessibilityId(“SomeAccessibilityID”);
Dimension elementSize = element.getSize();

Get Element Rect
Gets dimensions and coordinates of an element
MobileElement element = (MobileElement) driver.findElementByAccessibilityId(“SomeAccessibilityID”);
Rectangle rect = element.getRect();

Get Element CSS Value
Query the value of a web element’s computed CSS property
MobileElement element = (MobileElement) driver.findElementById(“SomeId”);
String cssProperty = element.getCssValue(“style”);

Category: Appium

Click
Click element at its center point.
MobileElement el = driver.findElementByAccessibilityId(“SomeId”);
el.click();

Send Keys
Send a sequence of key strokes to an element
MobileElement element = (MobileElement) driver.findElementByAccessibilityId(“SomeAccessibilityID”);
element.sendKeys(“Hello world!”);

Clear Element
Clear an element’s value
MobileElement element = (MobileElement) driver.findElementByAccessibilityId(“SomeAccessibilityID”);
element.clear();

Category: Appium

Get Current Context
Retrieve the current context. This can be either NATIVE_APP for the native context, or a web view context, which will be:
iOS – WEBVIEW_
Android – WEBVIEW_
String context = driver.getContext();

Get All Contexts
Retrieve all the contexts available to be automated. This will include, at least, the native context. There can also be zero or more web view contexts.
Set contextNames = driver.getContextHandles();

Set Current Context
Set the current context to that passed in. If this is moving into a web view context it will involve attempting to connect to that web view:
Set contextNames = driver.getContextHandles();
driver.context(contextNames.toArray()[1]);
// …
driver.context(“NATIVE_APP”);

Category: Appium

Appium can automate the Safari browser on real and simulated iOS devices. It is accessed by setting the browserName desired capabilty to “Safari” while leaving the app capability empty.
Mobile Safari on Simulator
First of all, make sure developer mode is turned on in your Safari preferences so that the remote debugger port is open.

Mobile Safari on a Real iOS Device
For XCUITest
We use appium-ios-device to handle Safari since Appium 1.15. You no longer need to install additional dependencies.

For Instruments
For iOS 9.3 and below (pre-XCUITest), we use the SafariLauncher App app to launch Safari and run tests against mobile Safari. This is because Safari is an app that is owned by Apple, and Instruments cannot launch it on real devices. Once Safari has been launched by SafariLauncher, the Remote Debugger automatically connects using the ios-webkit-debug-proxy. When working with ios-webkit-debug-proxy, you have to trust the machine before you can can run tests against your iOS device.

Setup for an iOS real device
Before you can run your tests against Safari on a real device you will need to:

XCUITest and Instruments
Turn on web inspector on iOS device (settings > safari > advanced)
Only for Instruments
Have the ios-webkit-debug-proxy installed, running and listening on port 27753
Make sure that SafariLauncher will work

//setup the web driver and launch the webview app.
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “iOS”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “13.2”);
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, “XCUITest”);
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, “Safari”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “iPhone 11”);

URL url = new URL(“http://127.0.0.1:4723/wd/hub”);
AppiumDriver driver = new AppiumDriver(url, desiredCapabilities);

// Navigate to the page and interact with the elements on the guinea-pig page using id.
driver.get(“http://saucelabs.com/test/guinea-pig”);
WebElement div = driver.findElement(By.id(“i_am_an_id”));
Assert.assertEquals(“I am a div”, div.getText()); //check the text retrieved matches expected value
driver.findElement(By.id(“comments”)).sendKeys(“My comment”); //populate the comments field by id.

//close the app.
driver.quit();