简体   繁体   中英

Appium IOS native app application switch

I click on link in myApplication which redirects me to safari, Now I want to close safari and open back myApplication at same state? Home Button is not supported with appium.

Tried,

1.

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("UIATarget.localTarget().deactivateAppForDuration(5); 

But it is closing and opening Safari app again. How can I switch to myApplication instead of safari?

2. Appium default methods doesn't seem to be working working IOS,

driver.closeApp();
driver.launchApp();

Quitting driver.

3.

JavascriptExecutor js = (JavascriptExecutor) driver;
Object result = js.executeScript("mobile: closeApp");
HashMap<String, String> args = new HashMap<String, String>();
args.put("bundleId", "com.myApplication.iphone");
js.executeScript("mobile: launchApp", args);

Got "org.openqa.selenium.WebDriverException: Not yet implemented" error.

4.

Runtime runtime = Runtime.getRuntime();
String[] args = {"osascript", "-e", "tell app \"safari\" to quit"};
runtime.exec(args);


runtime = Runtime.getRuntime();
String[] cmd = { "osascript", "-e", "tell app \"myApplication\" to launch" };
runtime.exec(cmd);

Not Working.

5.

try {
        Robot robot = new Robot();

        // Simulate a key press
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_SHIFT);
        robot.keyPress(KeyEvent.VK_H);

        // Simulate a key press
        robot.keyRelease(KeyEvent.VK_H);
        robot.keyRelease(KeyEvent.VK_SHIFT);
        robot.keyRelease(KeyEvent.VK_CONTROL);

    } catch (AWTException e) {
        e.printStackTrace();
    }

Not working

The best way I can see is to set your desired capabilities to not reset the app between sessions caps.setCapability("noReset", true) .

Then, after you click the link on Safari and do whatever else you need to do, close the session driver.quit() and start a new session using your app again. It should start from where you left off.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM