Lesson #17: How to add new mobile actions
Sometimes, you may find it necessary to do some things in your test that cannot be achieved with built-in actions, nor with the user-defined actions that build upon them.
Such user-scripted actions can be used to supplement the functionality of built-in TestArchitect actions. Examples of situations that you want to perform bring item to view
or zoom
action, you have to add implement a harness action.
Prerequisites:
- Completed lesson #8: Working with the Java harness
What you will learn:
- How to implement your new mobile actions in programming language Java.
Please download the sample project first and see the Readme file of each project to know how to implement TestArchitect Harness with Java language.
Best practice to use TestArchitect Harness for mobile testing
Let’s get started with TaHarnessWithBestPractice
project (in the sample projects above).
Examples: you want to interact with an item in List View out of the mobile screen, Test Architect has not supported scrolling to item yet. And now you have to implement new mobile action to scroll and click the expected item.
Unlike the other platform,
attach session
is prerequisites action. You have to attach with retrieved session Id afterconnect device
.
In Test Architect client, please implement the script as below:
Besides that, in the harness project, please reference methodaction_attachSession
in classMod_Mobile_Example.java
to implement harness actionattach session
.public static void action_attachSession() throws MalformedURLException { String serverUrl = AbtLibrary.getArgByIndex(1); String sessionId = AbtLibrary.getArgByIndex(2); if(serverUrl.length() == 0) { AbtLibrary.reportError("The 'server url' argument cannot be empty."); return; } if(sessionId.length() == 0) { AbtLibrary.reportError("The 'session id' argument cannot be empty."); return; } String completeUrl = serverUrl + "/session/" + sessionId; URL remoteSessionAddress = new URL(completeUrl); AbtLibrary.report("remoteSessionAddress: " + remoteSessionAddress); driver = new AppiumDriver(remoteSessionAddress, "Android", "UIAutomator2"); }
In case you execute the test script with Selected Desired Capabilities file, you can get session Id via action
get device session id
.Implement harness action
bring item to view
to scroll the item that you want to interact. Please take a look methodaction_bringItemtoView
in classMod_Mobile_Example
.Now you have a new powerful action to scroll the item in list view. And you can click the item!
Notes:
- The
AppiumDriver
which is attached inaction_attachSession
method is a standard Java Interface of Appium Java Client. So you can implement a lot of interesting function with that object.
For more informations aboutAppiumDriver
, please reference Appium Java Client AppiumDriver.