xcode 如何创建有效的 .app 或 .zip 存档以使用 Appium 自动化 iOS?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16902234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:26:52  来源:igfitidea点击:

How to create valid .app or .zip archive for automating iOS with Appium?

iosxcodeinstrumentsremotewebdriverappium

提问by Wulf

When testing native Objective-C applications, Appium requires a valid .app package, or a .zip archived .app package, in order to run automation against with Instruments.

在测试原生 Objective-C 应用程序时,Appium 需要一个有效的 .app 包,或一个 .zip 存档的 .app 包,以便使用 Instruments 运行自动化。

But I'm doing something terribly wrong and running up against a brick wall in trying to just CREATE a valid .app package that Appium can actually run in the iOS emulator.

但是我正在做一些非常错误的事情,并且在试图创建一个 Appium 可以在 iOS 模拟器中实际运行的有效 .app 包时碰壁。

I'm writing my automation in Java and using JUnit.

我正在用 Java 编写我的自动化并使用 JUnit。

Currently, in Xcode, I'm generating an .xarchive file for an "iOS Device" and then using the Xcode Organizer to show me where the .xarchive file has been placed. Once I find this archive I'm using "show package contents" to drill down into the .xarchive until I find the test.app package within the xarchive, which is greyed out and shows a circle/slash through the .app icon (yeah, I know, trouble...). I pull the test.app package from the .xarchive, and then place it in a directory with 777 write permissions.

目前,在 Xcode 中,我正在为“iOS 设备”生成一个 .xarchive 文件,然后使用 Xcode Organizer 显示 .xarchive 文件的放置位置。一旦我找到这个档案,我就会使用“显示包内容”来深入到 .xarchive,直到我在 xarchive 中找到 test.app 包,它是灰色的,并在 .app 图标上显示一个圆圈/斜线(是的,我知道,麻烦...)。我从 .xarchive 中拉取 test.app 包,然后将其放在具有 777 写入权限的目录中。

In my Java code (a Maven project using the Eclipse IDE) I write the capabilities like this, giving a full path to the test.app package:

在我的 Java 代码(使用 Eclipse IDE 的 Maven 项目)中,我编写了这样的功能,提供了 test.app 包的完整路径:

package com.my.appium._webdriver_test_demo;
import java.net.URL;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class AppiumWebDriverTestBVTDemo {

    private WebDriver driver;

    @Before
    public void setup() throws Exception
    {

        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability("device", "iPhone Simulator");
        cap.setCapability("app", "/Users/wulf/Library/Developer/Xcode/Archives/2013-05-31/Test/Products/Applications/test.app");    

        driver = new RemoteWebDriver(new URL("http://localhost:4723/wd/hub"), cap);

    }   

    @After
    public void tearDown() throws Exception
    {
        //Do stuff...
    }
}

When running this code, whether or not an "App path" has also been given to the test.app package (just as done above) on the Appium interface, I get the following error in the Appium console:

运行此代码时,无论是否在 Appium 界面上为 test.app 包提供了“应用路径”(就像上面所做的那样),我在 Appium 控制台中收到以下错误:

error: Could not parse plist file at /Users/wulf/Library/Developer/Xcode/Archives/2013-05-31/Story/Products/Applications/test.app/Info.plist

error: Failed to start an Appium session, err was: Error: ENOENT, open '/Users/wulf/Library/Developer/Xcode/Archives/2013-05-31/Story/Products/Applications/test.app/Info.plist'

When I then take the same test.app package and zip it, and then change the code like so:

当我然后使用相同的 test.app 包并压缩它时,然后像这样更改代码:

cap.setCapability("app", "/Users/wulf/Library/Developer/Xcode/Archives/2013-05-31/Story/Products/Applications/test.app.zip");

I get the following error in the Appium console:

我在 Appium 控制台中收到以下错误:

error: Failed to start an Appium session, err was: Error: ENOENT, stat '/Users/wulf/Library/Developer/Xcode/Archives/2013-05-31/test.app.zip'

And then when I place the same zipped test.app archive on a server (Ubuntu, Apache) and change my code like so:

然后当我将相同的压缩 test.app 存档放在服务器(Ubuntu、Apache)上并像这样更改我的代码时:

cap.setCapability("app", "http://10.xxx.xxx.100/var/www/myGitRepo/myProject/test.app.zip");

I get the following error dialog in the Appium console:

我在 Appium 控制台中收到以下错误对话框:

error: Test zip archive threw error Error: Command failed: 

error: Stderr: Archive:  /var/folders/gg/2_0flj7s51nd88kbtlwmm1qjxw981t/T/appium-app11353-39508-t2rmzq.zip
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of /var/folders/gg/2_0flj7s51nd88kbtlwmm1qjxw981t/T/appium-app11353-39508-t2rmzq.zip or
        /var/folders/gg/2_0flj7s51nd88kbtlwmm1qjxw981t/T/appium-app11353-39508-t2rmzq.zip.zip, and cannot find /var/folders/gg/2_0flj7s51nd88kbtlwmm1qjxw981t/T/appium-app11353-39508-t2rmzq.zip.ZIP, period.

error: Stdout: 
error: Failed to start an Appium session, err was: Error testing zip archive, are you sure this is a zip file?

What the heck am I doing wrong?

我到底做错了什么?

Is there any way to simply install my application properly on the iOS emulator (I can already do this just fine) and then have Appium tell Instruments to launch the already installed application? If so, how would this be specified in my capabilities code block?

有什么方法可以简单地在 iOS 模拟器上正确安装我的应用程序(我已经可以做到这一点),然后让 Appium 告诉 Instruments 启动已经安装的应用程序?如果是这样,这将如何在我的功能代码块中指定?

Do I need to generate a package with an .ipa extension and then do something fancy with that?

我是否需要生成一个带有 .ipa 扩展名的包,然后用它做一些花哨的事情?

Obviously, I'm a total newb when it comes to building .app packages in Xcode and could really use whatever help the good souls here can provide. If I can just get Appium to launch the fricken app on the iOS Emulator, I'm gold!

显然,在 Xcode 中构建 .app 包时,我完全是个新手,并且可以真正使用这里的好心人可以提供的任何帮助。如果我能让 Appium 在 iOS 模拟器上启动该死的应用程序,我就是金子!

Thanks in advance for any feedback!

提前感谢您的任何反馈!

Wulf

沃尔夫

回答by Dan Cuellar

The easiest way I've found to make this work is to:

我发现使这项工作最简单的方法是:

  1. Build and run the app for the simulator in xcode.
  2. Go to Products in the left-hand nav in Xcode and control-click (right-click) on YourApp.app and Select Show In Finder. (This is the .app you want to use)
  3. If you want a .zip just control-click (right-click) on the app and Select "Compress YourApp.app"
  1. 在 xcode 中为模拟器构建并运行应用程序。
  2. 转到 Xcode 左侧导航中的 Products 并按住 Control 单击(右键单击)YourApp.app 并选择 Show In Finder。(这是您要使用的 .app)
  3. 如果您想要 .zip 文件,只需在应用程序上按住 Control 单击(右键单击)并选择“压缩 YourApp.app”

回答by Leonardo

  1. Build you project.
  2. Click on the organizer icon (top right).
  3. Click on the arrow next the "Derived Data" directory (something like ~/Library/Developer/Xcode/DerivedData/YouApp-ajsnkjasngjkans).
  4. Finder will open in the derived data directory, go to /Build/Products/Debug-iphonesimulator.
  5. There is, you found your .app file. Point appium to it and enjoy.
  1. 构建你的项目。
  2. 单击组织者图标(右上角)。
  3. 单击“派生数据”目录旁边的箭头(类似于 ~/Library/Developer/Xcode/DerivedData/YouApp-ajsnkjasngjkans)。
  4. Finder 将在派生数据目录中打开,转到 /Build/Products/Debug-iphonesimulator。
  5. 有,你找到了你的 .app 文件。将 appium 指向它并享受它。

回答by AlekseiPetrovski

Also you van build app in terminal:

您还可以在终端中构建应用程序:

xcodebuild VALID_ARCHS="i386" -sdk iphonesimulator -configuration your_configuration -target your_target