iOS app gets reset on creation of new appium session

做~自己de王妃 提交于 2019-12-04 18:33:07

As far as I can tell, there is currently no solution to reopening the application after going to the home screen without clearing the app from cache.

In past versions of iOS/Appium, the solution was to do:

from appium import webdriver
driver = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)
driver.close_app()
app = driver.find_element_by_xpath('//UIAApplication/UIAWindow/UIAScrollView/UIAButton[@name="sampleApp"]')
app.click()

However this currently crashes Appium

I will update this question when I log a github issue for it.

The Appium help page says that it only supports multiple app testing in a single test session for Android without Selendroid:

iOS: Support for automating multiple apps in one session: No

Android:Support for automating multiple apps in one session: Yes (but not when using the Selendroid backend)

http://appium.io/slate/en/master/?ruby#toc_27

I'm guessing that is why you are having this issue, and it's most likely an Instruments/XCode issue.

I was able to relaunch the same app without it resetting its state with Appium 1.3.1 running with Xcode 6.1 on a Mac Mini running Mavericks. I did not try launching another app in between launches. I'm driving the automation from C#.

    protected AppiumDriver GetAppiumDriver(bool forRestart = false)
    {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.SetCapability("appium-version", "1.0");
        capabilities.SetCapability("platformName", "iOS");
        capabilities.SetCapability("platformVersion", "7.1");
        capabilities.SetCapability("deviceName", "iPhone Simulator");
        capabilities.SetCapability("app", _appPath);
        capabilities.SetCapability("locationServicesEnabled", true);
        if (forRestart)
        {
            capabilities.SetCapability("noReset", true);
        }
        AppiumDriver driver = new AppiumDriver(_serverUrl), capabilities, new TimeSpan(0, 5, 0));
        return driver;
    }

    public void iOSMobileAppBasicUITest()
    {
        // Initially Launch the app with the noReset capability at its default value of false to ensure a clean starting point.
        _driver = GetAppiumDriver(false);

        //Shut down the app.
        _driver.Quit();

        // Launch the app again, this time with the noReset capability set to true.
        _driver = GetAppiumDriver(true);

        // Use _driver to do whatever UI automation is desired.

        // Optional: Send the app to the background so that iOS does state preservation.
        _driver.BackgroundApp(3);

        // Close the app.
        _driver.CloseApp();
        // Alternative: _driver.Quit();

        // Launch the app.
        _driver.LaunchApp();
        // Alternative: _driver = GetAppiumDriver(true);
        ...

As I known, Appium by default runs in fast reset mode, and it tries to clear app's data when the session ends (as a result of the invocation of quit() in this case). If your want to keep app's data, the option --no-reset should work for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!