This page demonstrates about how to get started with the demo project for testing native and hybrid apps and the mobile web. The demo project is located at Github: https://github.com/selendroid/demoproject-selendroid
To get started please setup first your system and if you want to use an emulator during test, please checkout this section.
The demo project is based on Apache Maven and uses JUnit 4 to run the tests.
Selendroid is available in Maven central can be added in the dependencies section of the pom.xml
:
<dependency>
<groupId>io.selendroid</groupId>
<version>0.17.0</version>
<artifactId>selendroid-standalone</artifactId>
</dependency>
<dependency>
<groupId>io.selendroid</groupId>
<version>0.17.0</version>
<artifactId>selendroid-client</artifactId>
</dependency>
Selendroid latest development version is available in a Maven snapshot repo. For using the latest version, please add in the dependencies section of the pom.xml
:
<dependency>
<groupId>io.selendroid</groupId>
<version>0.18.0-SNAPSHOT</version>
<artifactId>selendroid-standalone</artifactId>
</dependency>
<dependency>
<groupId>io.selendroid</groupId>
<version>0.18.0-SNAPSHOT</version>
<artifactId>selendroid-client</artifactId>
</dependency>
Please add as well in the repositories section of the pom.xml
the following repository:
<repository>
<id>snapshot</id>
<name>snapshot repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
Before starting SelendroidDriver
it is mandatory to start the SelendroidStandalone
-server. This can be done by
Go through Selendroid's setup instructions and download the current version. The applications that are we are using in the demo project are located in this folder.
To start the standalone server please open your prefered shell and run:
java -jar selendroid-standalone-0.17.0-with-dependencies.jar -aut EmployeeDirectory.apk -aut selendroid-test-app-0.17.0.apk
When the server is started you can verify the current configuration http://localhost:4444/wd/hub/status:
"supportedApps":[
{
"appId":"io.selendroid.directory:0.0.1",
"mainActivity":"io.selendroid.directory.EmployeeDirectory",
"basePackage":"io.selendroid.directory"},
{
"appId":"io.selendroid.testapp:0.17.0",
"mainActivity":"io.selendroid.testapp.HomeScreenActivity",
"basePackage":"io.selendroid.testapp"
}
]
Before the test is executed the selendroid-standalone server will be started:
SelendroidConfiguration config = new SelendroidConfiguration();
// Add the selendroid-test-app to the standalone server
config.addSupportedApp("src/main/resources/selendroid-test-app-0.17.0.apk");
selendroidServer = new SelendroidLauncher(config);
selendroidServer.launchSelendroid();
The test itself you find here.
After the selendroid-standalone
has been started, the SelendroidDriver
can be initialized:
// Create the selendroid capabilities and specify to use an emulator and selendroid's test app
SelendroidCapabilities caps = new SelendroidCapabilities("io.selendroid.testapp:0.17.0");
driver = new SelendroidDriver(caps);
The capabilities are describing what app is used for testing and in this example the selendroid test app is used.
For testing the Android app the WebDriver API is used. This demonstrates about how a text field can be found and text can be entered.
// Find an element by id
WebElement inputField = driver.findElement(By.id("my_text_field"));
//enter a text into the text field
inputField.sendKeys("Selendroid");
//check if the text has been entered into the text field
Assert.assertEquals("Selendroid", inputField.getText());
Selendroid's test app contains an user registration flow that will be tested in the UserRegistrationTest:
The test demonstrates how activities can be started and how the interaction with different elements can be done.
Selendroid can be used to test hybrid applications. The project contains a Cordova sample app and the EmployeeDirectoryTest:
Selendroid supports with version 0.7.0 testing the mobile web. The sample project contains a MobileWebTest example:
Tests can be written in every programming language a Selenium client binding is available. A simple JUnit based python tests you can find here: