What is appium-uiautomator2-server?
The appium-uiautomator2-server npm package is a server component for the Appium automation framework that uses Google's UiAutomator2 library to automate Android applications. It allows for advanced interactions with Android devices, including finding elements, performing gestures, and executing commands.
What are appium-uiautomator2-server's main functionalities?
Finding Elements
This feature allows you to find elements on the screen using various strategies such as accessibility id, class name, XPath, etc.
const { UiAutomator2Driver } = require('appium-uiautomator2-driver');
const driver = new UiAutomator2Driver();
await driver.findElement('accessibility id', 'myElementId');
Performing Gestures
This feature allows you to perform touch gestures like tap, swipe, and pinch on the device screen.
const { UiAutomator2Driver } = require('appium-uiautomator2-driver');
const driver = new UiAutomator2Driver();
await driver.performTouch([{ action: 'tap', options: { x: 100, y: 200 } }]);
Executing Commands
This feature allows you to execute shell commands on the Android device, providing a way to interact with the device at a lower level.
const { UiAutomator2Driver } = require('appium-uiautomator2-driver');
const driver = new UiAutomator2Driver();
await driver.execute('mobile: shell', { command: 'input text', args: ['Hello World'] });
Other packages similar to appium-uiautomator2-server
webdriverio
WebdriverIO is a popular automation framework that supports multiple browser and mobile automation protocols, including Appium. It provides a high-level API for interacting with web and mobile applications, making it easier to write and maintain tests compared to using appium-uiautomator2-server directly.
detox
Detox is an end-to-end testing library for mobile apps developed by Wix. It is designed to work with React Native applications and provides a high-level API for writing tests. Unlike appium-uiautomator2-server, Detox is specifically tailored for React Native and offers a more integrated experience for those applications.
appium-uiautomator2-server
A netty server that runs on the device listening for commands and executes using UiAutomator V2.
building project
build the android project using below commands
gradle clean assembleServerDebug assembleServerDebugAndroidTest
Starting server
push both src and test apks to the device and execute the instrumentation tests.
adb shell am instrument -w io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner
run unitTest
build the unitTest flavor using the below commands
gradle clean assembleE2ETestDebug assembleE2ETestDebugAndroidTest
unitTest flavor contains tests for handlers and can be invoked by using following command
gradle clean connectedE2ETestDebugAndroidTest
the above command takes care about installing the AUT apk in to the testing device/emulator before running the tests.
you can also invoke the test using below command
adb shell am instrument -w io.appium.uiautomator2.e2etest.test/androidx.test.runner.AndroidJUnitRunner
Note: AUT apk should be installed before executing above command.
Other Sections: