15

Looking far and wide for a step-by-step guide to set-up iOS Test Automation using appium, with scripts in Java (no ruby and/or cucumber).

Note: The appium wiki is not helpful either.

arka.b
  • 204
  • 2
  • 13
Ethen Hunt
  • 579
  • 2
  • 4
  • 13

4 Answers4

15

To run iOS tests, you can follow these steps :

(Note : I am using Java language here in Eclipse IDE and using Appium app):

  1. Create a new java project in Eclipse.
  2. Import jar files : Selenium Server (formerly the Selenium RC Server) version and required client driver (according to your language choice) which can be downloaded here. (To import : Right click on your project -> Properties -> Libraries -> Add External JARs. Add all three selenium jar files here.)
  3. Download Appium app and launch.
  4. You can run your test scripts either in simulator or on real device. To run scripts on real iOS device, you will need 'deviceName', 'platformVersion', 'UDID' (Device ID) and 'Bundle ID' (Application Bundle ID) and absolute path to the .ipa.
  5. To run scripts on iOS simulator , you will need 'deviceName', 'platformVersion', path to .app and 'Bundle ID' of your app.
  6. Choose capabilties in Appium app and mention the same in your script based on whether you are testing on simulator or on device.
  7. Launch Appium server and then run your script.

All Appium server capabilities which can be used can be found here.

You can refer to my blog post here as well for more details to execute a sample basic script.

Smriti
  • 1,552
  • 3
  • 15
  • 29
  • Thanks for creating and sharing this post. I believe that this excellent post could be made more elaborate for the benefit of the community. Please let me know if you would be open to collaborating on it. – Ethen Hunt Dec 24 '13 at 01:12
  • be aware that your answer only provide links, the moderators could delete it in any moment... – jcesarmobile May 22 '15 at 10:47
  • I have a .app file. Do I need to worry about provisioning profile to run the app on iOS simulator? I am not really aware of what provisioning profile means and why we do it, but it will be great if someone can point out to some resource which explains why provisioning is needed to run appium tests on iOS. – Abhijeet Vaikar Jun 18 '15 at 12:01
6

I found this very helpful.

http://seleniumworks.blogspot.co.uk/2013/12/appium-native-ios-app-testing-webdriver.html

Note you need to get the .app of your project for it to work - not the .ipa

Appium Native iOS App Testing | WebDriver Appium is an open source, cross-platform test automation tool for native, hybrid and mobile web apps. Appium tests can be written in your favorite Webdriver-compatible language.

Requirements & installation

1| MAC OS X 10.7 (minimum version required) 2| Xcode updated version (prefer) 3| Node.js 4| Appium.app 5| Eclipse Kepler (prefer) 6| TestNG framework

Pre-Appium setup

iOS .app file is enough to inspect elements. In this example, I have used the project, 'InternationalMountains' from Apple DEV site.

1| Download the project, 'InternationalMountains' 2| Double click and extract it 3| Import it into Xcode by opening the Xcode file 4| Run the project 5| Make sure that the simulator is opened with the application 6| Open Terminal and move to the project folder 7| Run the following command to build the .app file

`xcodebuild -sdk iphonesimulator6.1`

8| It will build the app and generate the file, 'InternationalMountains.app' under /InternationalMountains/Build/Products/Release-iphonesimulator/

Appium iOS setup

1| Download & Install Node.js // npm represents that Node.js Package Manager $ sudo npm install wd

2| Run the Appium server using node.js; There are couple of ways to do so..

1 Using Node.js

//install Appium $ npm install -g appium (or) $ sudo npm install appium -g //start Appium server $ appium &

2 Using the App

Download Appium, install and Run it

3| Now, the Appium server gets started in the

default port 4723 and IP Address 0.0.0.0

Appium inspector

Appium inspector is a record and playback tool just like Selenium IDE for web.

1| Open Appium

2| Change the default IP address to 127.0.0.1 and port 4725

3| Now, enable the check box, 'App path' 4| Click on the 'Choose' button and locate the .app local directory. i.e., InternationalMountains.app

5| Click on the 'Launch' button [Appium server launches now] 6| Now, a blue-colored icon found beside the 'Launch' button is enabled 7| Clicking blue-colored icon open up the Appium inspector with Simulator 8| Now, click the 'Record' button in Appium inspector 9| Every action will be generating a script at bottom of the Appium inspector

Run the script in Eclipse IDE

package packagename;

import java.io.File;
import java.net.URL;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class AppiumTest {
public WebDriver driver = null;

@BeforeMethod
public void setUp() throws Exception {
// set up appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");
capabilities.setCapability(CapabilityType.VERSION, "6.1");
capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
capabilities.setCapability("app","/Users/username/Downloads/InternationalMountains   /build/Release-iphonesimulator/InternationalMountains.app");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4725/wd/hub"), capabilities);
}

@AfterMethod
public void tearDown() throws Exception {
driver.quit();
}

@Test
public void test01() throws InterruptedException {
driver.findElement(By.xpath("//window[1]/tableview[1]/cell[2]")).click();
driver.findElement(By.xpath("//window[1]/navigationBar[1]/button[1]")).click();
driver.findElement(By.xpath("//window[1]/tableview[1]/cell[7]/text[1]")).click();
}
}

Note: 1| Currently, there is no Appium inspector support for Windows

Community
  • 1
  • 1
Bob
  • 73
  • 1
  • 6
  • Please read [answer] and provide informations so that if the link dies, your answer is still useful. – Jonathan Drapeau Feb 28 '14 at 17:40
  • Hi Jonathan, I had a look at the guidelines and are happy to include all of step by step guide but it seemed very long - and also tricky to cherry-pick the main items as you need most of it. Let me know what is the best way to deal with it. thanks – Bob Feb 28 '14 at 18:00
  • You can either summarize the steps or copy them all. I checked the link and without the images, it doesn't seem very long so you could copy everything. – Jonathan Drapeau Feb 28 '14 at 18:03
  • I record my test script using Objective-C language, how i run my recorded script of application through? Should i record my iOS app build in java and then run it through Eclipse?? I don't think so it better way to go Eclipse rather than XCode. – Tirth Feb 07 '16 at 02:50
0

I am getting error popup on step 6 -

Could not start a new session

Be sure the Appium server is running with an application opened by using the "App Path" parameter in Appium.app (along with package and activity for Android) or by connecting with selenium client and supplying this in the desired capabilities object.

Jitendra kumar
  • 106
  • 3
  • 10
0

I have uploaded the java eclipse project on github

https://github.com/boobalaninfo/javaworkspace.git

Requirement:

  1. Appium should up and running on Mac machine
  2. Eclipse to develop and run the java test cases
Boobalan
  • 815
  • 11
  • 11