Skip to content

Instantly share code, notes, and snippets.

@dannyshain
Last active March 12, 2021 01:34
Show Gist options
  • Save dannyshain/c6eba96dcee3382837a808b406833f65 to your computer and use it in GitHub Desktop.
Save dannyshain/c6eba96dcee3382837a808b406833f65 to your computer and use it in GitHub Desktop.
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