如何使用 appium 从 iPhone 启动已安装的应用程序

How to launch already installed app from iPhone using appium

我正在使用 Java + TestNG + Appium 编写自动化脚本。

在测试场景中,我试图在 iphone 上启动已安装的应用程序。 (在这种情况下是盒子)。 Box 包含一些我需要访问的 MS office 文件。 我不太确定如何实现这一目标。

我尝试了多种选择,例如从 iTunes 中提取 .app 文件并使用 Appium 进行部署,但没有成功。

有人可以指导我吗,如果可能的话。如果是,如何?

使用以下方案自动化预安装的应用程序。

1.This 仅适用于使用 DEVELOPMENT 证书签名的应用程序。

2.This 不适用于使用分发证书签名的应用程序

3.If 您已经使用开发人员配置文件创建了应用程序,并自行构建。或者使用 testFlight 下载它,并使用开发配置文件签名

4.This 是因为 Apple 的 Instruments 不允许您与那些正在运行的应用程序进行交互。 (即使您知道 bundleId)

如果您的应用处于开发模式,请遵循以下事项 1.The 设备上安装的应用程序的 bundleId。将其用作应用功能。

  1. 遵循 Appium Real Devices 指南(用 bundleId 替换任何 .ipa/.app 参考)

除了您的常规 desiredCapabilities(例如 platformNameplatformVersiondeviceName)之外,这些应该是您的 desiredCapabilities:

预装应用程序

desiredCaps['app'] = 'yourbindleID'

设备的唯一标识符

desiredCaps['udid'] = '1824y983h2849gh2498'

这对我有用

HashmMap<String, Object> args = new HashMap<String,Object>();
args.put("bundleId","*YOUR_APP_BUNDLEID*");
driver.executeScript("mobile: launchApp", args);

参考下面的代码片段:

cap.setCapability(IOSMobileCapabilityType.APP_NAME, "{appName}");

如果应用已安装在移动设备上,此功能是自动打开应用的最重要功能。

    public static IOSDriver<IOSElement> capabilities() throws IOException {
    
    //Configure absolute path of the .ipa file

    FileInputStream fis = new FileInputStream(System.getProperty("user.dir")+"//automation.properties");
    System.out.println(fis);
    Properties prop = new Properties();
    prop.load(fis);     

    File f = new File("src/test/resources");
    File fs = new File(f, (String)prop.get("iOSAppName"));
    
    DesiredCapabilities cap = new DesiredCapabilities(); 
    cap.setCapability(MobileCapabilityType.PLATFORM_NAME, (String)prop.get("iOSPlatformName"));
    cap.setCapability(MobileCapabilityType.UDID, (String)prop.get("iDeviceUDID"));
    cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);
    cap.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone");

    driveriOS = new IOSDriver<IOSElement>(new URL("http://127.0.0.1:4725/wd/hub"), cap);
    
    //Check app is already installed if NOT install app to device automatically
    if(driveriOS.isAppInstalled("com.test.app")==false)
    {
    cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
    }
    
    //cap.setCapability(MobileCapabilityType.BROWSER_NAME, (String)prop.get("iOSBrowserType"));
    cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, (String)prop.get("iOSPlatformVersion"));
    cap.setCapability(IOSMobileCapabilityType.APP_NAME, "{appName}"); //Provide your app name here
    cap.setCapability(IOSMobileCapabilityType.BUNDLE_ID, (String)prop.get("updateWDABundleId"));
    cap.setCapability("xcodeSigningId", "iPhone Developer");
    cap.setCapability("xcodeOrgId", (String)prop.get("xcodeOrgId"));

    driveriOS = new IOSDriver<IOSElement>(new URL("http://127.0.0.1:4725/wd/hub"), cap);
    driveriOS.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
    stepRecorder(Status.INFO, "iOS Driver initiated");

    return driveriOS; 

}