Вы делаете это неправильно.
Убедитесь, что вы используете клиент Java 6.1.0, а не 1.6.0
Во-первых, вам нужно использовать дженерики сAndroidDriver, например,
AndroidDriver <AndroidElement>
Так что ваш код должен выглядеть так:
public class sample {
AndroidDriver <AndroidElement> driver;
@BeforeTest
public void beforeTest() {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "xyz");
capabilities.setCapability("platformVersion", "6.0");
capabilities.setCapability("platformName", Platform.ANDROID);
capabilities.setCapability("appPackage", "com.app1.pkgname");
capabilities.setCapability("appActivity","com.app1.activityname");
capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 6000);
capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS,true);
try {
driver = new AndroidDriver<>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void Test() {
Activity activity = new Activity("com.app2.pkgname", "com.app2.MainActivityName");
activity.setStopApp(true);
driver.startActivity(activity);
System.out.println("current context it will return native " + driver.getContext());
driver.context("WEBVIEW_com.app2");
AndroidElement xx = driver.findElement(By.id("SA_btn_SignIn"));
if (xx.isEnabled()) {
AndroidTouchAction action = new AndroidTouchAction (driver);
action.tap(TapOptions.tapOptions().withElement(ElementOption.element(xx))).perform();
}
}
}