The Appium linkage function uses the UIAutomation2 interface provided by the Nexacro Platform 17 to read or write properties of apps running in Android NRE and to support method execution by specifying parameters. You can write unit tests and test using UI automation testing tools, such as Selenium.
In this chapter, we will look at the steps to install Appium, create a basic Java project in Visual Studio code, and connect it to the Nexacro Platform apps.
The following is written based on Appium 1.19.1, Android Studio version 4.1.1.
The Appium linkage function is supported only in version 17.1.3.100 or later.
If yours is not the supported version, please update the Nexacro Platform.
In version 17.1.3.100, there is an error wherein the function to search for the Element by ID in the Android 10 operating system does not function properly. Please check in operating systems earlier than Android 10.
Configuring the Appium Linkage
Installing Appium & Checking the Terminal Connection
1
Check if Android Studio and Android SDK, JDK are installed.
2
Enable the developer option on the terminal to test and then check the following 3 options to use.
USB debugging
Install via USB
USB debugging (Security settings)
3
Download and install the Appium installation file on the PC to test.
https://github.com/appium/appium-desktop/releases/latest
4
Connect the terminal and PC using a USB cable.
5
Check the serial number of the connected terminal with the adb command.
In the image below, "0a388e93" is the serial number of the connected terminal.
$ adb devices List of devices attached 0a388e93 device usb:1-1 product:razor model:Nexus_7 device:flo
6
Install the Nexacro app on the terminal to test.
When building the app, the Package Name is set to "nexacro" and the Program Name is set to"TEST0120".
7
Run Appium on the PC.
8
Click the [Start Server] button to start the Appium server.
In the Windows operating system environment, change the Host setting to "127.0.0.1".
9
Click the [Start Inspector Session] button to open the Appium Inspector window.
10
In the [Custom Server] tab, enter the JSON Representation item as follows.
{ "platformName": "Android", "platformVersion": "10", "appPackage": "nexacro.TEST0120", "appActivity": ".MainActivity", "automationName": "UIAutomator2", "autoGrantPermissions": "true", "deviceName": "0a388e93" }
Item | Description (Items in Bold are Fixed Values) |
---|---|
platformName | "Android" |
platformVersion | The operating system version of the terminal to test |
appPackage | App to test (value set at build time) [Package Name].[Program Name] format |
appActivity | If built with App Builder, ".MainActivity" If built in Android Studio, the set activity |
automationName | "UIAutomator2" |
autoGrantPermissions | "true" |
deviceName | Terminal serial number checked with the adb command |
Please refer to the link below for additional settings.
11
Click the [Start Session] button.
The Appium Settings app is installed on the terminal for the initial execution.
12
Check if the app is running on the terminal to test it, and check that the running status of the app is displayed in the Appium Inspector window.
Configuring the Test Project Execution & Testing
1
Install Visual Studio Code.
2
Select Extensions from the sidebar and install the Java Extension Pack.
3
Set the appium, selenium, testing libraries required for project execution.
Please refer to the related document for the configuration of the Maven, Gradle, Eclipse plug-ins, etc.
client-combined-3.141.59.jar (https://www.selenium.dev/downloads/)
byte-buddy-1.8.15.jar
commons-exec-1.3.jar
guava-25.0-jre.jar
okhttp-3.11.0.jar
okio-1.14.0.jar
testng-7.3.0.jar (https://testng.org/doc/download.html)
jcommander-1.78.jar
java-client-7.4.1.jar (https://github.com/appium/java-client)
commons-lang3-3.11.jar (https://commons.apache.org/proper/commons-lang/)
4
Create the Java Project and the BaseClass.java file as below.
package tests; import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; public class BaseClass { AndroidDriver<MobileElement> driver; final String URL_STRING = "http://127.0.0.1:4723/wd/hub"; @BeforeTest public void setup() { System.out.println("setup"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("automationName", "UiAutomator2"); capabilities.setCapability("platformName", "Android"); capabilities.setCapability("platformVersion", "10"); capabilities.setCapability("deviceName", "0a388e93"); capabilities.setCapability("autoGrantPermissions", "true"); capabilities.setCapability("appPackage", "nexacro.TEST0120"); capabilities.setCapability("appActivity", ".MainActivity"); try { driver = new AndroidDriver<MobileElement>(new URL(URL_STRING), capabilities); } catch (MalformedURLException e) { System.out.println("MalformedURLException"); e.printStackTrace(); } catch (Exception e) { System.out.println("Exception"); e.printStackTrace(); } } @Test public void sampleTest() { System.out.println("sampleTest"); } @AfterTest public void teardown() { System.out.println("teardown"); driver.close(); } }
5
Select Test from the sidebar and then click the [Run] button in the BaseClass item.
6
Check if the app is running on the terminal to test it, and then check that the test success message is displayed normally in the DEBUG CONSOLE.
Creating & Running the Unit Test
1
Modify and update the Nexacro app as follows.
Place the Button component at the top and the Edit component below it.
Write the onclick event handler function of the Button component as follows.
this.Button00_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo) { this.Edit00.set_value("BUTTON CLICK"); };
2
Create the Tests.java file as shown below.
package tests; import java.net.MalformedURLException; import java.util.concurrent.TimeUnit; import org.testng.annotations.Test; public class Tests extends BaseClass { @Test public void testOne() throws MalformedURLException, InterruptedException { System.out.println("testOne"); int nTestSpeed = 2000; driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); driver.findElementById("mainframe.WorkFrame.form.Button00").click(); Thread.sleep(nTestSpeed); } }
3
Select Test from the sidebar and then click the [Run] button in the Tests item.
4
Check if the app is running on the terminal to test it, and then check that the Button click event is processed normally for the Edit component value to be changed.
Supported Interfaces
Method | Return | Argument |
---|---|---|
AndroidDriver
| ||
findElement | WebElement | By by |
findElementById | WebElement | String id |
findElementByName | WebElement | String using |
findElementByClassName | WebElement | String using |
findElementByXPath | WebElement | String using |
getKeyboard | Keyboard | - |
pressKeyCode | - | AndroidKeyCode |
WebElement
| ||
getText | String | - |
getAttribute | String | String name |
getClass | String | - |
getRect | Rectangle | - |
getSize | Dimension | - |
getLocation | Point | - |
isEnabled | Boolean | - |
click | - | - |
TouchAction
| ||
longPress | PointOption | - |
waitAction | WaitOptions | - |
moveTo | PointOption | - |
release | - | - |
perform | - | - |
Keyboard
| ||
sendKeys | - | CharSequence... keysToSend |
pressKey | - | CharSequence... keysToSend |
releaseKey | - | CharSequence... keysToSend |