Skip to content
Tamikana edited this page Nov 16, 2017 · 15 revisions

Mobile automation

Table of Contents

Mobile Configuration
ExtendedWebElement

### **Mobile Configuration**

All project configuration properties are located in _config.properties file. In the table below we are providing description for the mobile project parametrs (you may see most of main parametrs here):

Attribute Meaning Default value Example
capabilities.platformName Name of automation platform {must_override} Android/iOS
capabilities.deviceName Device name for execution * Sumsung_Galaxy_J5
capabilities.deviceType Type of device {must_override} phone/simulator
capabilities.platformVersion Version of testing platform {must_override} 10.3
capabilities.automationName Appium for Android under 7,0, uiautomator2 for Android 7.0+, XCUITest for iOS {must_override} XCUITest
capabilities.app Path to app {must_override} /User/Automation/App.app
capabilities.udid Unique Device ID {must_override} 23AEE92B-7088-4CEE-BBD4-C02B70C111B2
capabilities.noSign true true
capabilities.autoGrantPermissions Permission for all phone additional actions, like using camera true true
capabilities.newCommandTimeout Timeout before new command, extremly useful during debugging 180 1800

Examples:

  1. For Android:
#=============== Android Mobile ======================#
capabilities.automationName=Appium
capabilities.appPackage=
capabilities.deviceName=Lenovo
capabilities.udid=dc0dc6a9
capabilities.noSign=true
capabilities.deviceType=phone
capabilities.app=<path_to_apk>
capabilities.platformName=ANDROID
capabilities.autoGrantPermissions=true
#=====================================================#
  1. For iOS:
#=================== iOS Mobile ======================#
capabilities.platformName=iOS
capabilities.deviceName=*
capabilities.deviceType=simulator
capabilities.platformVersion=10.3
capabilities.automationName=XCUITest
capabilities.app=/Users/andrei_litsvin/Documents/builds/ios/MapMyRun.app
capabilities.udid=23AEE92B-7088-4CEE-BBD4-C02B70C111B2
#=====================================================#
### **ExtendedWebElement**
Table of Contents

ExtendedWebElement
How to find ExtendedWebElement?
ExtededWebElement's methods

### **ExtendedWebElement**

ExtendedWebElement is an extended version of selenium WebElement which you can find in org.openqa.selenium package. The best thing in using ExtendedWebElement is that you can use both all old methods of WebElement and new more comfortable Carina methods.

### **How to find ExtendedWebElement?**

The simpliest way to find ExtendedWebElement is using annotation @FindBy. The @FindBy annotation is used to locate one or more ExtendedWebElements using a single criterion. The list of criterions is standart:

  • className
  • css
  • how...using
  • id
  • linkText
  • name
  • partialLinkText
  • tagName
  • xpath

Example:

    @FindBy(name = "Hybrid")
    private ExtendedWebElement hybridUnits;

    @FindBy(id = "com.ua.record.debug:id/spinner_text")
    private List <ExtendedWebElement> unitsVersions;

Also for iOS platform @Predicate is avaliable. Example:

    @FindBy(xpath = "name CONTAINS 'Share'")
    @Predicate
    protected ExtendedWebElement privacySettingsBtn;
### **ExtededWebElement's methods** Most usable methods are reperesented in the table bellow:
Method Return type Description
getName() String Get the name of this element
getText() String Get the visible innerText of this element
getAttribute() String Get the value of a the given attribute of this element
click() void Click on element
doubleClick() void Double click on element
isElementPresent() boolean Is element present or not?
isElementPresent(long timeout) boolean Is element present or not during the timeout in seconds?
isElementNotPresent(long timeout) boolean Is element not present during the timeout in seconds?
isElementWithTextPresent(String text) boolean Is element with text present or not?
isElementWithTextPresent(String text, long timeout) boolean Is element with text present or not during the timeout in seconds?
clickIfPresent boolean Click on element if it's presented, return true if click is performed
type(String text) void Clear the value of field and simulate typing the text
scrollTo() void Scroll page until the element could be located
check() void If element is checkable it will be checked
uncheck() void If element is checkable it will be unchecked
isCheck() boolean If element is checkable return is the element checked or not
tapWithCoordinates(double x, double y) void Tap on screen using the given cordinates

How to use WebDriver methods?

You can simple transform ExtendedWebElement to WebElement using getElement() method. After this it's possible to operate with standart WebElement methods.

Example:

   Point point = element.getElement().getLocation();
   Dimension dim = element.getElement().getSize();

CustomTypeFactory and DeviceType

Carina provides a solution to mobile testing on iOS/Android platforms with the same test-code. For both platforms you should use Page Object Design Pattern but in a bit improved way. Each page has 3 realizations in 3 packages:

  • common page Base in common package with common methods and elements;
  • iOS page in ios package with iOS methods and elements;
  • Android page in android package with Android methods and elements; iOS and Android pages should extends Base Page and have the same name. Annotation @DeviceType would provide information about device type and parent (common) page.

Example: Common (Base) Page

public abstract class RecordFinishScreenBase extends AbstractPage {
}

Android Page

@DeviceType(pageType = Type.ANDROID_PHONE, parentClass = RecordFinishScreenBase.class)
public class RecordFinishScreen extends RecordFinishScreenBase {
}

iOS page

@DeviceType(pageType = Type.IOS_PHONE, parentClass = RecordFinishScreenBase.class)
public class RecordFinishScreen extends RecordFinishScreenBase {
}

Carina will get the right version according to using driver (identified in _config.properties) if you will create new page using CustomTypeFactory Example:

RecordFinishScreenBase recordFinishSB = CustomTypePageFactory.initPage(RecordFinishScreenBase.class);

AbstractTest

AbstractTest is Carina class which should be used as base for all test classes (your test class should extends AbstractTest).This class provides necessary before- and after- class methods including integration with Jira, TestRail and S3.

IosUtils and AndroidUtils

This static classes provides a scope of useful methods like: tap, scroll, swipe, scroll with JavaScript, hideKeydboard and etc. Classes could be accessed by import ‘com.qaprosoft.carina.core.foundation.utils.ios.IosUtils’ or ‘com.qaprosoft.carina.core.foundation.utils.ios.AndroidUtils’

Device.class

Class provides a scope of methods for Android using ADB like: installApp, unnstallApp, reinstall App, startRecording, stopRecording, dropFile,getFullPackageByName, getInstalledPackages,isAppInstall, getScreenState, screenOn, screenOff, clearAppData, getApkVersion, downloadFileFromJar. Classes could be accessed by import ‘com.qaprosoft.carina.core.foundation.webdriver.device.Device’