Activity activity = new Activity("com.android.chrome","com.google.android.apps.chrome.Main");
activity.setStopApp(false);((StartsActivity)driver).startActivity(activity);
Thread.sleep(5000);
driver.get("https://www.youtube.com/watch?v=-GJTzPOIoqs");
驱动程序未切换到当前活动。仅在以前的Apppackage中
答案 0 :(得分:0)
您检查活动名称了吗?可能是 com.google.android.apps.chrome.Main 不是启动应用程序的活动。
您可以尝试重新初始化驱动程序并在功能中设置浏览器:
$ gatsby develop
# GATSBY_CONTENTFUL_OFFLINE is undefined
$ GATSBY_CONTENTFUL_OFFLINE=true gatsby develop
# GATSBY_CONTENTFUL_OFFLINE is true
$ GATSBY_CONTENTFUL_OFFLINE=true gatsby build
# GATSBY_CONTENTFUL_OFFLINE is true, but contenful doesn't care
# because NODE_ENV is always set to `production`
也许您需要先使用driver.closeApp()停止其他应用,例如:
public static AndroidDriver<?> setUpForChrome(){
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.2.2");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
ChromeOptions options=new ChromeOptions();
options.setExperimentalOption("androidPackage", "com.android.chrome");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
return (AndroidDriver<?>) new RemoteWebDriver(appiumUrl, capabilities);
}