Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

3. Create & maintain tests

jeangb edited this page Jun 28, 2017 · 5 revisions

Update objects repository

Since we are using the Page Object Model design pattern, editing POM classes is necessary to add references to new objects from Riot GUI, or editing / deleting them. Objects from the GUI are referenced as MobileElement in POM classes.
Example:

[...]
/*
 * TOP BAR : contains back button, and confirm button
 */
@AndroidFindBy(id="im.vector.alpha:id/action_bar")
public MobileElement actionBarView;
@AndroidFindBy(xpath="//android.widget.ImageButton[@content-desc='Navigate up']")
public MobileElement backButton;
[...]
  • @AndroidFindBy is the mechanism used to locate the element. For iOS, we use @iOSFindBy.
  • id is the method used to locate the element. More used in Android than iOS. It's the id of the element. More methods are available:
    • accessibility: refers to the accessibility id on iOS elements.
    • classname: name of the class
    • xpath: path to the objects through the GUI hierarchy. Jokers can be used to bypass elements. Very powerfull but very slow on iOS.
    • and 2 more: UIAutomator (deprecated since new iOS automation framework) and tagName.

Adding a new element in a POM class consists in adding a new MobileElement as showed above.
Note that it's possible to directly fetch a list of MobileElements, example:

@iOSFindBy(accessibility="InviteRecentTableViewCell")
public List<MobileElement> invitationCells;

-> Fetch all the elements whose accessibility id is InviteRecentTableViewCell.

How to inspect UI elements from application under test:

Before adding new objects in POM classes, an inspector can be used to retrieve the objects properties.
Note that if you have access to the application under test source code, inspector is not always mandatory. You can set properties or guess it without using inspector.

- Android

Launch Appium inspector or google UIAutomatorViewer.
UIAutomatorViewer:

Relations between @AndroidFindBy from POM classes and properties showed by Inspector:

@AndroidFindBy(method) Property showed by Inspector Example
id resource-id @AndroidFindBy(id="im.vector.alpha:id/circular_room_view")
xpath hierarchy + properties @AndroidFindBy(xpath="//android.widget.RelativeLayout[@resource-id='im.vector.alpha:id/circular_room_view']")
className class @AndroidFindBy(className="android.widget.RelativeLayout")

- iOS

Launch Appium inspector or Appium iOS inspector (used in browser).
Appium iOS Inspector is a web interface. It requires that a iOS test is pending. For that we define a breakpoint to launch and suspend a test when the Appium session is ready, then we run the inspector.

Relations between @iOSFindBy from POM classes and properties showed by Inspector:

@iOSFindBy(method) Property showed by Inspector Example
accessibility Accessibility Id @iOSFindBy(accessibility="ContactsTableVCTableView")
xpath hierarchy + properties @iOSFindBy(xpath="//XCUIElementTypeCell[last()]")
className Type @iOSFindBy(className="XCUIElementTypeCell")

Use multiple devices in one test

Some tests need more than one device to be executed on, for example if you want to test a call between 2 devices or if you want to test the typing indicator on the room page.
It means that during the execution, the test will switch between appium drivers (linked to real devices) and will perform actions and verification on them. One instance of a test can use several devices, from 1 to 4. This project can handle 2 ios devices and 2 android devices, thanks to the utility/AppiumFactory class.
One appium driver is linked to one appium server, because an appium server can handle only one appium driver.
Note that for the moment it's not possible to perform parallel execution on a set of devices.

How to switch between devices:

When instantiating a POM class you have to specify which driver from the AppiumFactory class you want to use, example:

RiotIncomingCallPageObjects incomingCallDevice2= new RiotIncomingCallPageObjects(appiumFactory.getAndroidDriver2());

In this example, the second android driver is used, so all the actions linked to this POM class (RiotIncomingCallPageObjects) will be played on the second android device. By playing actions on a POM class linked to an other driver, you will be able to switch between devices.

Don't forget to set the appropriate group following the set of devices needed in the test, because the appium drivers and appium drivers are instanciated in setup methods from RiotParentTest class.
Example:
@Test(groups={"2drivers_android","2checkuser"}, description="call from device 1 answered by device 2")

The "2drivers_android" group will start 2 appiums servers and 2 android drivers.

How to link your real devices with the drivers:

To be able to choose which real device will be attached to a driver in the test, you can configure the config/device.yaml file.
The udid is the most important parameter because it identifies the device.

Clone this wiki locally