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

时间:2013-06-03 17:16:42

标签: ios xcode instruments remotewebdriver appium

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

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

我正在用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包提供了“App path”(就像上面所做的那样),我在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'

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

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 app,我就是金牌!

提前感谢您的任何反馈!

沃尔夫

3 个答案:

答案 0 :(得分:3)

  1. 建立你的项目。
  2. 点击管理器图标(右上角)。
  3. 点击“Derived Data”目录旁边的箭头(类似〜/ Library / Developer / Xcode / DerivedData / YouApp-ajsnkjasngjkans)。
  4. Finder将在派生数据目录中打开,转到/ Build / Products / Debug-iphonesimulator。
  5. 有,你找到了你的.app文件。点赞它并享受。

答案 1 :(得分:2)

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

  1. 在xcode中为模拟器构建并运行应用程序。
  2. 转到Xcode左侧导航栏中的产品,然后按住ControlApp并单击(右键单击)YourApp.app并选择Show In Finder。 (这是你想要使用的.app)
  3. 如果你想在.zip上只需按住Control键点击(右击)并选择“Compress YourApp.app”

答案 2 :(得分:1)

你也可以在终端中建立应用程序:

xcodebuild VALID_ARCHS =“i386”-sdk iphonesimulator -configuration your_configuration -target your_target

相关问题