On this page we describe Selendroid advanced concepts.
In Selendroid are by default native events used. There are scenarios where the Android Instrumentation Framework has limitations with regards to simulating user input with different locales. Native events should be used whenever it is possible. But when specific locales are causing issues, Selendroid offers you to disable native events.
@Test
public void shouldSetJapaneseTextIntoNativeTextField() {
//Initialize your Selendroid Driver and navigate to your main Activity
Configuration configurable = (Configuration) driver();
configurable.setConfiguration(DriverCommand.SEND_KEYS_TO_ELEMENT, "nativeEvents", false);
String text = "ありがとう";
WebElement input = driver().findElement(By.id("my_text_field"));
input.sendKeys(text);
Assert.assertEquals(text, input.getText());
}
This mechanism can be used for native UI and WebView elements. A full example you can find in our Selendroid test suite.
Selendroid is hte first Mobile Test Automation framework that can be extended by the users with your own code at runtime! We provide the ability to implement your own request handler that extends our BaseRequestHandler. We provide a full demo project that you can find at Github.
package io.selendroid.extension;
import io.selendroid.server.http.HttpRequest;
import io.selendroid.server.BaseRequestHandler;
import io.selendroid.server.Response;
import io.selendroid.server.SelendroidResponse;
import org.json.JSONException;
public class DemoExtensionHandler extends BaseRequestHandler {
public DemoExtensionHandler(String mappedUri) {
super(mappedUri);
}
@Override
public Response handle(HttpRequest request) throws JSONException {
return new SelendroidResponse(getSessionId(request), "I'm an extension!");
}
}
#!/bin/bash
mvn clean install
cd target
dx --dex --output=extension.dex extension-0.0.1-SNAPSHOT.jar
@Test
public void extensionCallShouldSucceed() {
SelendroidCapabilities capa = new SelendroidCapabilities("io.selendroid.testapp:1.0");
capa.setSelendroidExtensions(myExtension.dex)
WebDriver driver = new SelendroidDriver(capa);
assertEquals("I'm an extension!",
driver().callExtension("io.selendroid.extension.DemoExtensionHandler"));
}
Selendroid offers you to put the app under test into the background and resume it later.
//put the app to the background
driver().backgroundApp();
//resume app
driver().resumeApp();
Selendroid offers you to control the brightness of the screen.
ScreenBrightness brightness = (ScreenBrightness) driver();
brightness.setBrightness(0);
brightness.setBrightness(50);
brightness.setBrightness(100);
Selendroid offers you to control the orientation of the screen per activity.
driver().getOrientation();
driver().rotate(ScreenOrientation.LANDSCAPE);
Selendroid offers you to interact with the device via ADB. The benefit is that the limitations of the Android Instrumentation framework of testing only one Android process can be avoided.
sendText(String text)
sendKeyEvent(int keyCode)
tap(int x, int y)
executeShellCommand(String command)