【发布时间】:2018-05-31 22:51:50
【问题描述】:
我正在 iOS 移动应用 上使用 Appium 进行一些自动化操作。
我需要:
- 打开应用
- 做一些任务
- 开启野生动物园
我查看了如何做到这一点,但我一直在阅读,由于苹果框架的限制,这是不可能的,它不允许您在每个会话中向多个应用程序发送命令。
有人知道解决这个问题的方法吗?或者,如果我读到的不是 100% 正确的。
【问题讨论】:
标签: ios mobile automation appium
我正在 iOS 移动应用 上使用 Appium 进行一些自动化操作。
我需要:
我查看了如何做到这一点,但我一直在阅读,由于苹果框架的限制,这是不可能的,它不允许您在每个会话中向多个应用程序发送命令。
有人知道解决这个问题的方法吗?或者,如果我读到的不是 100% 正确的。
【问题讨论】:
标签: ios mobile automation appium
它不允许您在每个会话中向多个应用发送命令
没错,但您可以在单个测试中运行 2 个会话:
它可能看起来像这样:
@Test
public void testBothAppAndSafari() throws MalformedURLException {
URL appiumServerUrl = new URL("<your appium server host>");
DesiredCapabilities appCaps = new DesiredCapabilities();
// put required native app capabilities in appCaps
DesiredCapabilities safariCaps = new DesiredCapabilities();
// put required safari capabilities in safariCaps
IOSDriver driver = new IOSDriver(appiumServerUrl, appCaps);
driver.findElement(<locator for element in native app>).click();
// do whatever you want with mobile app
driver.quit();
driver = new IOSDriver(appiumServerUrl, safariCaps);
driver.findElement(<locator for element in web>).click();
// do whatever you want in safari
driver.quit();
}
【讨论】:
您可以使用以下方法,
【讨论】:
created two setup one for app and other for safari 时,我真的不明白您的意思。 :P
你也可以按照我的方法不退出驱动。
WEBVIEW_*** 来检查网页元素。NATIVE_APP关键字返回原生上下文示例代码:
System.out.println("Run application");
Map<String, Object> params = new HashMap<>();
params.put("bundleId", "com.example");
boolean terminalApp = (boolean) driver.executeScript("mobile: terminateApp", params);
System.out.println("terminateApp: " + terminateApp);
driver.findElementById("Safari").click();
Set<String> contextNames = appDriver.getContextHandles();
// Change context to WEBVIEW_***
appDriver.context(String.valueOf(contextNames.toArray()[1]));
driver.get("https://www.google.com.vn");
Thread.sleep(20000);
// Do something.
// ...
// If you want to communicate with NATIVE context just change to NATIVE_APP.
appDriver.context("NATIVE_APP");
【讨论】:
您可以通过driver.activateApp(BUNDLE_ID);激活系统应用
无需杀死应用驱动并启动浏览器驱动即可访问浏览器,只需在应用之间切换即可。
野生动物园
driver.activateApp("com.apple.mobilesafari");
【讨论】: