Selendroid is based on the Android instrumentation framework. Currently only the testing of one specific app is supported. Selendroid requires the following permission for your app:
<uses-permission android:name="android.**permission.INTERNET"/>
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
Selendroid can be used to test already built apps. Those Android apps (apk file) must exist on the machine, where the selendroid-standalone server will be started. The reason for this is that a customized selendroid-server for the app under test (AUT) will be created. Both apps (selendroid-server and AUT) must be signed with the same certificate in order to install the apks on the device.
If you want to play around with selendroid, you can use our selendroid-test-app which we use to verify that actually selendroid works as expected. You can download this app here.
Download selendroid-standalone.jar and cd to the folder where you downloaded the jar, and run:
java -jar selendroid-standalone-0.17.0-with-dependencies.jar -app selendroid-test-app-0.17.0.apk
Selendroid-standalone will start a http server on port 4444 and will scan all Android virtual devices (avd) that the user has created (~/.android/avd/). The Android target version and the screen size will be identified. If an emulator is running, it can be used since version 0.11.0. Even an emulator that has been started manually after the selendroid-standalone got started can be used. If there are Android hardware devices plugged in, they will also be added to the device store.
You can check that the application(s) and the devices are recognized by opening a browser and navigating to: http://localhost:4444/wd/hub/status.
You should see a result similar to this:
{
status: 0,
value: {
"os": {
"name": "Android"
},
"build": {
"browserName": "selendroid",
"version": "0.17.0"
},
"supportedApps": [{
"appId": "io.selendroid.testapp:0.17.0",
"mainActivity": "io.selendroid.testapp.HomeScreenActivity",
"basePackage": "io.selendroid.testapp"
}],
"supportedDevices": [{
"screenSize": "320x480",
"targetPlatform": "ANDROID17",
"emulator": true,
"avdName": "latest"
}, {
"screenSize": "320x480",
"targetPlatform": "ANDROID16",
"emulator": true,
"avdName": "es"
}, {
"screenSize": "320x480",
"targetPlatform": "ANDROID10",
"emulator": true,
"avdName": "AVD_for_api10"
}]
}
Tests are written using the Selenium 2 client API. For Java we provide selendroid-client libraries that are used in the following example:
SelendroidCapabilities capa = new SelendroidCapabilities("io.selendroid.testapp:0.17.0");
WebDriver driver = new SelendroidDriver(capa);
WebElement inputField = driver.findElement(By.id("my_text_field"));
Assert.assertEquals("true", inputField.getAttribute("enabled"));
inputField.sendKeys("Selendroid");
Assert.assertEquals("Selendroid", inputField.getText());
driver.quit();
If, for example, you prefer to write your tests in Python, the same test can be found here, and here in Ruby.
In order to create a new test session in the desired capabilities, the id of the app under test must be provided in the format: io.selendroid.testapp:0.17.0
. Please note, if the version is not specified in the id of the app under test then the latest version of the app will be automatically selected. Based on that information a matching Android device will be identified, otherwise the test session will throw an error and not start. Important: before filing a bug: please make sure the desired capabilities in your test match the supported apps and devices available.
After the found device has been initialized, a customized selendroid-server will be created and automatically installed on the device. The app under test will also be installed and the selendroid-server on the device will then be automatically started.
After the test session has been successfully initialized, the test commands such as 'find an element' and 'element interactions' are routed to this device. If the test session has ended, the emulator will stop automatically.
We recommend the use of SelendroidCapabilities
. There you find convenient methods like:
new SelendroidCapabilities( ... )
: This requests an app for the test session without any preference about emulator or hardware device.SelendroidCapabilities.emulator( ... )
: This requests an emulator and will fail the test session if no emulator is available.SelendroidCapabilities.device( ... )
This requests a hardware device and will fail the test session if no device is plugged in.SelendroidCapabilities.android( ... )
This starts a mobile web testing session.The SelendroidCapabilities
are only available for Java projects. For other programming languages use the following properties in the DesiredCapabilities of the Selenium client apis:
io.selendroid.testapp:0.17.0
. If the version of the aut is not specified, then the latest version is assumed.
android
to start the 'Android driver webview app'.
Please note that either aut
or browserName
can be used for a test session.
True
, an emulator will be requested. If False
, a hardware device will be requested.
19
de_CH
720x1280
1
shell setprop name selendroid
, please note that the adb command itself and the serial will be added by selendroid automatically.
Nexus One
, Nexus 7
, Galaxy S3
) of an emulator when selecting a device.
google
) if you need a device that has Google APIs.
Selendroid supports testing on hardware devices as well as using Android emulators. In the capabilities the properties are used to find the device for the test execution. The supported properties in the capabilities are listed here.
For running a test on the Android target platform 18 and on an emulator which is simulating a Nexus 7, the capabilities for the selendroid-test-app are:
SelendroidCapabilities capa = new SelendroidCapabilities("io.selendroid.testapp:0.8.0");
capa.setPlatformVersion(DeviceTargetPlatform.ANDROID18);
capa.setEmulator(true);
capa.setModel("Nexus 7");
Selendroid can start and stop Android Virtual Devices (Avd). It cannot create new emulators, they must be created manually by the tester. After an emulator has been created, we recommend the first start be done manually in order to be sure everything works as expected.
When creating avds, please read the following configuration recommendations:
hw.keyboard=yes