How to create in Eclipse and run your Appium test on the iOS device (not emulator) where app is installed prior to the execution of the test script? [closed]

0
0

Continuing to help Engineers to save time setting up Appium. There are almost no tutorials for it online. When I say that, I mean there are no tutorials that are straight forward and tested. I hope my tutorial will help you guys. I wish I could find something like that when I was looking for one. Enjoy.

Step 1.
First, follow my other guide to setup Appium on your Mac OS Computer. Without properly setup Appium on your Mac, your tests simply won’t work. Guide on how to setup Appium on Mac is on the following page:
How to setup Appium on Mac OS to run automated tests from JAVA classes on Android and iOS devices
If you have already setup Appium on your Mac, then proceed to the step 2.

Step 2.
Download and install Xcode 5.1 or higher, it’s free:
developer.apple.com/xcode/downloads/

Step 3.
In Terminal run command:

sudo authorize_ios

Step 4.
You will need to know your app’s Bundle ID (the same as a package in Java project). It could be found using Xcode. Bundle ID (package com.blabla.company) is simply specified under an app’s name in Xcode. Install app into iOS device. Mount iOS device to your computer using USB. Then launch Xcode. In Xcode panel’s left menu, choose your iOS device, then click on “Applications” menu under it. There your application will be listed. Bundle name is under the title of your app.

Step 5.
You will need to know your device’s UDID. Important to know that serial number is not the UDID. To find your iOS device’s UDID, please follow this simple guide:
http://www.whatsmyudid.com

Step 6.
Further we go. In Eclipse, create a new project.

Step 7.
In Eclipse, right click on the project name, then select “Properties”.

Step 8.
In Properties, click on “Java Build Path”.

Step 9.
In “Java Build Path” click on “Libraries”.

Step 10.
Then click “Add External Jars” and import all Jars required for Appium Jar Library Files to remove all dependencies needed for Appium to work. This includes importing Jars for Selenium from “www.seleniumhq.org“ and the rest of required Jars.

Step 11.
When your project in Eclipse is ready setup for Appium, just create a new class in your project. Name that class “AppiumIOSTest” and copy/paste the code from bellow. In that code, where it says: “capabilities.setCapability(“app”, “<<>>”);”, replace <<>> with bundle Id for your application that you discovered in step 3 of this guide. Also where it says: “capabilities.setCapability(“udid”, “<<>>”);”, replace <<>> with the UDID number of your device that you discovered in step 4 of this guide.

package test.java.com.saucelabs.appium;
public class AppiumIOSTest {
private WebDriver driver;
private List<Integer> values;
private static final int MINIMUM = 0;
private static final int MAXIMUM = 10;
@Before
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities
.setCapability("platformName", "ios");
capabilities
.setCapability("deviceName","iOS");
capabilities
.setCapability("udid", “<<<your iOS device UDID>>>”);
capabilities
.setCapability("app", “<<<your apps bundle id>>>”);
driver
= new RemoteWebDriver( new URL( "http://127.0.0.1:4723/wd/hub" ), capabilities );
values
= new ArrayList<Integer>();
}
@After
public void tearDown() throws Exception {
driver
.quit();
}
@Test
public void testScriptGoesHere() throws Exception {
System.out.println("Test Output From Within the test");
System.out.println("Here goes your test script");
}
}

Step 12.
When you paste the code into your Eclipse, you will see lots of red underlining. Just press following combination of keys: “Command + Shift + o”. This will import all dependencies into your Java code.

Step 13.
Save your project in Eclipse.

Step 14.
Open your Terminal window. In your Terminal window you have to “cd” to the directory of you project located in the workspace directory of your Eclipse.
Example: “cd /Users/ivishnevskiy/Documents/workspace/YourProjectName

Step 15:
Attach your iOS device to USB and to your MAC computer using USB.

Step 16:
In the same Terminal window from Step 10, run following command to launch the Appium test:

mvn -Dtest=test.java.com.saucelabs.appium.AppiumIOSTest test

where test.java.com.saucelabs.appium is a package name
and
AppiumIOSTest is a class name.

This will launch your app on your iOS device. This setup will not install iOS app to your device. This setup is to launch the app that’s already installed on your iOS device before you execute the test. The actually test script will go into the following method of the code above:

@Test  
public void testScriptGoesHere() throws Exception {
System.out.println("Test Output From Within the test");
System.out.println("Here goes your test script");
}

Scripts for Appium are written using Selenium’s syntax. Also when you execute the test, on your iOS device, you might get a popup asking to Trust or Don’t Trust your computer. Press “Trust” button.

  • You must to post comments
Showing 0 results
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website