![](/img/trans.png)
[英]Using Appium to automate Mobile Safari on real device and encountering uncaught exceptions
[英]Automate launching Safari from a iOS mobile app using appium
我正在iOS 移動應用程序上使用Appium進行一些自動化。
我需要:
我環顧四周,但我一直在讀到,由於蘋果框架的限制,這是不可能的,它不允許您在每個會話中向多個應用程序發送命令。
有誰知道解決這個問題的方法? 或者,如果我讀到的內容不是 100% 正確。
它不允許您在每個會話中向多個應用程序發送命令
沒錯,但您可以在一個測試中運行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();
}
您可以使用以下方法,
您也可以在不退出驅動程序的情況下按照我的方法進行操作。
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(BUNDLE_ID);
無需殺死應用程序驅動程序並啟動瀏覽器驅動程序來訪問瀏覽器,只需在應用程序之間切換即可。
蘋果瀏覽器
driver.activateApp("com.apple.mobilesafari");
您可以通過 driver.activateApp(BUNDLE_ID) 激活已安裝的應用程序; 方法,它將打開應用程序,您可以執行操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.