Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 900000);
// Session is created using Android Espresso Driver
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ESPRESSO);
capabilities.setCapability(MobileCapabilityType.APP, System.getProperty("user.dir") + "/apps/ApiDemos.apk");
driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.findElementByAccessibilityId("Views").click();
// Switch to Android UIAutomator2 from Espresso
Map<String, Object> args = new HashMap<>();
args.put("strategy", "textContains");
args.put("locator", "android.widget.TextView");
args.put("action", "getText");
String text = (String)driver.executeScript("mobile: uiautomator", args);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment