Any way to host an app in the background and restart in Appium iOS

Is there a way to do the following process in iOS Automation using Appium?

  • Press the home button.
  • Put the application in the background.
  • Open another application (say Gmail) → do the operations there.
  • Then restart our application and resume checking methods.

I tried:

RemoteWebDriver wd = null;
wd.close();

But it just closes the application (exactly the same as wd.quit()), which I automate, and then when I try to restart → it starts from scratch. I run it on an iPhone simulator.

+4
source share
8 answers

Appium , , ( ), ..

#, Python Ruby, Java.

WebDriver, selenium WebDriver, , , Appium (, , , ..)

+5

iOS

Xcode : https://github.com/appium/appium/issues/4479 , : fooobar.com/questions/1532429/...

Android

i.e "" -

((AppiumDriver) driver).sendKeyEvent(AndroidKeyCode.HOME);

, : 1. "", Monitor.bat. "android.widget.TextView" at index 5.

2. i.e driver.findElementsByClassName("android.widget.TextView").get(5).click();

3. . .

driver.findElementsByName(AppName).get(0).click();
+3

, , - .

Appium (Selenium ) iOS. , , - , , Appium ( ).

, CMD + SHIFT + H, , . , "" , UIAutomation.

, (Java):

Runtime runtime = Runtime.getRuntime();
String[] args = { "osascript", "-e", "tell application \"System Events\" \n tell application \"Simulator\" to activate \n tell application \"System Events\" to keystroke \"h\" using {command down, shift down} \n end tell" };
runtime.exec(args);

: Applescript, .

, Applescript:

tell application "System Events"
  tell application "Simulator" to activate
  tell application "System Events" to keystroke "h" using {command down, shift down}
end tell

. , esacpe ( \). \n , Applescript .

. , , , iOS.

: , !

+2

, 1. + 2. :

AppiumDriver dr = MobileDriverFactory.getDriver()
            try {
                dr.runAppInBackground(2)
            } catch (WebDriverException e) {
                if (e.getMessage().contains("An error occurred while executing user supplied JavaScript")) {
                } else {
                    throw new RuntimeException(e);
                }
            }

iOS

3. + 4. .

ProcessBuilder pb = new ProcessBuilder("idevicedebug", "run", "YourAppNameHere")
            Thread.sleep(5000)
            Process p=pb.start()
            Thread.sleep(5000)
        p.destroy()

, iOs, , , :

ideviceinstaller -l

iOS, :   com.google.ios.youtube, "11.11.8", "YouTube"   com.google.ios.gmail, "11.11.8", "Gmail" : com.xxx.xxx.xxx , ,

"idevicedebug run com.google.ios.youtube" 

( ios), enter, youtube KMS Technology Vietnam

+1

, , ruby:

background_app 2

2 - , , .

+1

Have you tried using driver.execute_script "au.backgroundApp(5)"for your application?

The problem with this method is that during these 5 seconds you cannot interact with the device, backgroundApp blocks.

0
source

A simpler simple solution for Android Appium with Ruby:

  def switch_back_to_app
    # For Android
    #
    # To Put App in Background Press recent apps to close
    $driver.press_keycode(187)

    sleep(1)
    # To bring the same app back i.e Press recent apps to open
    $driver.press_keycode(187)
  rescue => e
    p e.exception
  end
  module_function :switch_back_to_app
Run codeHide result

Updates the code so that all items are found again.

0
source

For Android:

driver.pressKeyCode(AndroidKeyCode.HOME);

For iOS:

driver.executeScript("mobile: pressButton", ImmutableMap.of("name", "home"));
0
source

Source: https://habr.com/ru/post/1532429/


All Articles