Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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.

I'm writing my automation in Java and using 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.

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:

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:

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:

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:

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:

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:

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?

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

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!

Thanks in advance for any feedback!

Wulf

like image 582
Wulf Avatar asked Jun 03 '13 17:06

Wulf


People also ask

Can we automate iOS app using Appium?

Appium is an open source test automation framework for automating native, mobile web, and hybrid applications on iOS devices, Android devices, and Windows desktop platforms. Importantly, Appium is “cross-platform”: it allows you to write tests against multiple platforms (iOS, Android, Windows) using the same API.

How do you automate apps on iOS?

From an iPhone or iPad, open the Shortcuts app and tap the Automation tab. Here, you can select Create Personal Automation to build a shortcut that runs directly on your Apple device or Create Home Automation for one that runs for everyone in a household through a smart home device.

Does Uiautomator work for iOS?

The way to start a session using the UIAutomation driver is to set the platformName capability in your new session request to the value of iOS . Of course, you must also include appropriate platformVersion , deviceName , and app capabilities, at a minimum.


2 Answers

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"
like image 59
Dan Cuellar Avatar answered Sep 28 '22 02:09

Dan Cuellar


  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.
like image 28
Leonardo Avatar answered Sep 28 '22 01:09

Leonardo