6

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

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

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

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

在我的 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...
    }
}

运行此代码时,无论是否在 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'

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

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

我在 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'

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

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

我在 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?

我到底做错了什么?

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

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

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

提前感谢您的任何反馈!

伍尔夫

4

3 回答 3

4

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

  1. 在 xcode 中为模拟器构建并运行应用程序。
  2. 转到 Xcode 左侧导航中的 Products 并按住 Control 单击(右键单击)YourApp.app 并选择 Show In Finder。(这是您要使用的 .app)
  3. 如果您想要一个 .zip,只需在应用程序上按住 Control 键单击(右键单击)并选择“Compress YourApp.app”
于 2013-06-04T14:48:37.073 回答
4
  1. 构建你的项目。
  2. 单击组织者图标(右上角)。
  3. 单击“派生数据”目录旁边的箭头(类似于 ~/Library/Developer/Xcode/DerivedData/YouApp-ajsnkjasngjkans)。
  4. Finder 将在派生数据目录中打开,转到 /Build/Products/Debug-iphonesimulator。
  5. 在那里,你找到了你的 .app 文件。将appium指向它并享受。
于 2013-10-09T21:19:42.613 回答
2

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

xcodebuild VALID_ARCHS="i386" -sdk iphonesimulator -configuration your_configuration -target your_target
于 2014-01-16T00:54:50.737 回答