如何在自动化测试期间使用 android 默认浏览器
How to use android default browser during automation testing
我想在 android 默认浏览器(不是 chrome)中自动执行一些测试用例。这是我想要的功能:
DesiredCapabilities capabilities = new DesiredCapabilities().android();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "browser");
capabilities.setCapability(MobileCapabilityType.PLATFORM, Platform.ANDROID);
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "My Device");
capabilities.setCapability(MobileCapabilityType.VERSION, "5.1.1");
capabilities.setCapability("appPackage", "com.android.browser");
capabilities.setCapability("appActivity", "com.android.browser.BrowserActivity");
当我运行通过appium的任何测试用例时,输出是:
A new session could not be created. (Original error: An unknown server-side error occurred while processing the command. (Original error: unknown error: com.android.browser is not installed on device a5cde43e
如果有人知道如何解决这个问题,请告诉我。提前致谢。
试试下面的 activity 之一,
//Android Default Browser
// capabilities.setCapability("appPackage","com.sec.android.app.sbrowser");
capabilities.setCapability("appPackage","com.android.browser");
capabilities.setCapability("appActivity","com.android.browser/.BrowserMainActivity");
我使用下面的代码,我可以在我的魅族设备上打开默认浏览器
new DesiredCapabilities();
DesiredCapabilities capabilities = DesiredCapabilities.android();
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Browser");
capabilities.setCapability(MobileCapabilityType.PLATFORM, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"81HEBM6245N7");
capabilities.setCapability(MobileCapabilityType.VERSION, "5.0.1");
try {
URL url = new URL("http://127.0.0.1:4723/wd/hub");
AndroidDriver<MobileElement> driver = new AndroidDriver<MobileElement>(url, capabilities);
driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(120, TimeUnit.SECONDS);
driver.quit();
}catch (MalformedURLException e){
System.out.println("URL init error");
}
我想在 android 默认浏览器(不是 chrome)中自动执行一些测试用例。这是我想要的功能:
DesiredCapabilities capabilities = new DesiredCapabilities().android();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "browser");
capabilities.setCapability(MobileCapabilityType.PLATFORM, Platform.ANDROID);
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "My Device");
capabilities.setCapability(MobileCapabilityType.VERSION, "5.1.1");
capabilities.setCapability("appPackage", "com.android.browser");
capabilities.setCapability("appActivity", "com.android.browser.BrowserActivity");
当我运行通过appium的任何测试用例时,输出是:
A new session could not be created. (Original error: An unknown server-side error occurred while processing the command. (Original error: unknown error: com.android.browser is not installed on device a5cde43e
如果有人知道如何解决这个问题,请告诉我。提前致谢。
试试下面的 activity 之一,
//Android Default Browser
// capabilities.setCapability("appPackage","com.sec.android.app.sbrowser");
capabilities.setCapability("appPackage","com.android.browser");
capabilities.setCapability("appActivity","com.android.browser/.BrowserMainActivity");
我使用下面的代码,我可以在我的魅族设备上打开默认浏览器
new DesiredCapabilities();
DesiredCapabilities capabilities = DesiredCapabilities.android();
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Browser");
capabilities.setCapability(MobileCapabilityType.PLATFORM, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"81HEBM6245N7");
capabilities.setCapability(MobileCapabilityType.VERSION, "5.0.1");
try {
URL url = new URL("http://127.0.0.1:4723/wd/hub");
AndroidDriver<MobileElement> driver = new AndroidDriver<MobileElement>(url, capabilities);
driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(120, TimeUnit.SECONDS);
driver.quit();
}catch (MalformedURLException e){
System.out.println("URL init error");
}