如何启动已安装appium的iOS应用程序

时间:2018-04-30 10:16:58

标签: appium appium-ios

为了测试注册中的重复,我需要关闭并重新启动iOS应用程序。任何人都可以使用Appium和JAVA提供最好的简单脚本来关闭应用程序并在iOS中重新启动它吗?

3 个答案:

答案 0 :(得分:0)

您可以通过以下方式实现:

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

public class SampleTest {
    AppiumDriver<?> appiumDriver;
    final String URL_STRING = "http://127.0.0.1:4723/wd/hub";
    URL url = new URL(URL_STRING);

    public SampleTest() throws MalformedURLException {
    }

    @BeforeTest
    public void beforeTest() {
         File appDir = new File("path to ipa file");
    File app = new File(appDir, "app.ipa");
    DesiredCapabilities iOSCapabilities = new DesiredCapabilities();
    iOSCapabilities.setCapability(MobileCapabilityType.PLATFORM, "iOS");
    iOSCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
    iOSCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone6s");
    iOSCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "11.2.1");
    iOSCapabilities.setCapability(MobileCapabilityType.UDID, "udid");
    iOSCapabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
    appiumDriver = new IOSDriver(url, iOSCapabilities);
    }

    @Test
    public void test() {
        //perform some test
    }

    @AfterTest
    public void afterTest() {
        // following command will close and restart the app
        appiumDriver.resetApp();
    }
}

您可以查看this了解详情。

答案 1 :(得分:0)

使用驱动程序driver.resetApp(),像这样

try{
      LOG.debug("reset app");
      driver.resetApp();
    } catch (WebDriverException e){
      LOG.error("ERROR on reset app, e: ",e);
    }

答案 2 :(得分:0)

Appium 允许您启动设备上任何预装的应用程序,因此您可以先使用 closeApp,然后使用您的应用程序包 ID 使用 launchApp

            // closing app
            driver.closeApp();
            // launch app again
            HashMap<String, Object> args = new HashMap<>();
            args.put("bundleId", APP_BUNDLE_ID);
            driver.executeScript("mobile: launchApp", args);