Appium - Mobile test automation on a real device


If you are looking to perform test automation on a real device (iPhone in my case) and you have had problems with the documentation on the official Appium website , the following post will help you for sure:

Prerequisites: 

  1. Apple account with valid apple ID 
  2. Download and Install Eclipse on your Mac – A link that might help you with the installation process http://www.cs.dartmouth.edu/~cs5/install/eclipse-osx/
  3. Download and Install Xcode
  4. Download Selenium Jars for java from the Selenium website
  5. Download the java client libraries from http://appium.io/downloads.html
  6. Download and install appiumD
    1. download the latest version from Appium.io.
    2. Mount the disk image.
    3.  Drag Appium.app to your Applications folder
  7. Download and Install brew (The missing package manager for OS X)
    1. It's on the bottom of the Homebrew homepage. http://brew.sh/ (Yeah, it would be helpful if it was listed at the top, instead.)
    2. From a Terminal prompt:  ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
  8. Tip: (Optional) – Install Oh my zsh for a better shell experience https://github.com/robbyrussell/oh-my-zsh
  9. Your apple id has access to a valid iOS Developer portal


Important points to note:

  1. Appium uses ‘Appium Inspector’ to view the elements similar to what we have as ‘uiautomatorviewer’ tool to view UI components in Android in UI Automator. You can access elements using name , xpath or tagName as visible through appium inspector
  2. Appium Inspector can be launched by clicking on the blue ‘i’ button besides ‘Launch’ button from appium app.
Setup and Execution:

The core of what most of the Appium help posts are missing:


  1. Find UDID of the iphone: http://www.innerfence.com/howto/find-iphone-unique-device-identifier-udid
  2. Turn on web inspector on iOS device (**settings > safari > advanced**, only for iOS 6.0 and up) http://appium.io/slate/en/master/?java#toc_80
  3. Note:1.       To be able to run your tests against mobile Safari we use the SafariLauncher App to launch Safari. Once Safari has been launched the Remote Debugger automatically connects using the ios-webkit-debug-proxy.
  4. Setup: Before you can run your tests against Safari on a real device you will need to:   Have the ios-webkit-debug-proxy installed, running and listening on port 27753 
  5. Note: When executing against a real iOS device appium is unable to access the web view directly. Therefore the connection has to be established through the USB lead. To establish this connection we use the ios-webkit-debugger-proxy. http://appium.io/slate/en/master/?java#toc_14
  6. To install the latest tagged version of the ios-webkit-debug-proxy using brew, run the following commands in the terminal:
    1.  ruby -e "$(curl –fsSL https://raw.github.com/mxcl/homebrew/go/install)"
    2. brew update
    3. brew install ios-webkit-debug-proxy
  7. Once installed you can start the proxy with the following command:
    1. Change the udid to be the udid of the attached device and make sure to set the port to 27753 as that is the port the remote-debugger uses:
    2. > ios_webkit_debug_proxy -c 0e4b2f612b65e98c1d07d22ee08678130d345429:27753 –
  8. On Mac                                    i.      Connect your device to your Mac.
  9.                                                              ii.      In the Devices organizer under Devices, select your device.
                                                                iii.      Click the “Use for Development” or “Add to Member Center” button.
                                                               iv.      If the device was previously used for development, the “Use for Development” button does not appear. If this happens, click “Add to Member Center” at the bottom of the window instead.
                                                                 v.      In the team dialog that appears, select the checkbox next to your account name, and click Choose.
                                                               vi.      If a Certificate Not Found dialog appears, click Request.
  10. Create a provisioning profile that can be used to deploy the SafariLauncherApp.
  11. Create a new App Id and select the WildCard App ID option and set it to “*”
    2.       You can only create application IDs in the iOS developer portal. Once you're logged in, choose the "Certificates, Identifiers & Profiles" link:
    3.       On the next screen, choose the "Identifiers" option on the left:
    4.       Now you can click the "+" icon near the top right to create a new App ID:
    5.       The first thing you're asked to do is provide an App ID description:
    6.       Choose an App ID Suffix as “*”
    7.       Complete and submit to get a message – “This App ID is now registered to your account and can be used in your provisioning profiles
  12. Create a new Development Profile and for App Id select the one created in step 1.
    1.       Click on Add new Provisioning Profile
    2.       Choose iOS App Development option
    3.       for App Id select the one created in step 1.
    4.       Select your certificate(s) and device(s) and click next.
    5.       Set the profile name and generate the profile.
    6.       Download the profile and open it with a text editor.
Make sure you either use XCode and install ios --real-safari –launcher on your device:
  1.                                                                i.      git clone https://github.com/appium/appium.git
                                                                 ii.      install npm using brew – brew install npm
                                                                iii.      cd appium
                                                               iv.      ./reset.sh --ios --real-safari –launcher
  2. If unable to install. Open the git project using XCode - build and run the installation
ExecurtionExecution:
Execution:
  1. Make sure you have a new terminal and run: ios_webkit_debug_proxy -c 0e4b2f612b65e98c1d07d22ee08678130d345429:27753 –d
  2. Open another terminal and start the appium server:                                                              
                                                                                  i.      cd appium
                                                                                 ii.      node . -U --app ‘safari’


You are good to start writing your selenium webdriver scripts now




                               Sample script in Java(JUnit 4)

package com.test.appium;
import java.net.URL;
import java.util.Iterator;
import java.util.Set;
import org.junit.After;
import org.junit.Before;
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 FirstTestCase {
public WebDriver driver = null;
@Before
public void setUp() throws Exception {
// set up appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserName","Safari");
capabilities.setCapability("deviceName","iPhone");
capabilities.setCapability("platformName","iOS");
//capabilities.setCapability("udid","36d2a431a84fd87e95dcf87914a7c3df386b6d4b");
capabilities.setCapability("version","7.1");
System.out.println("Before App launched");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
System.out.println("App launched");
}
@After
public void tearDown() throws Exception {
              driver.quit();
}
@org.junit.Test
public void testCases() throws InterruptedException {
driver.get("https://test.com");
Thread.sleep(5000);
WebElement login = driver.findElement(By.xpath("//*[@class='login_button']"));
login.click();
int itr=2;
String windowHandle=null;
Set parentWindowHandle = driver.getWindowHandles(); // save the current window handle.
  Iterator windowIterator = parentWindowHandle.iterator();
  while(windowIterator.hasNext() && itr!=0) {
    windowHandle = windowIterator.next();
    itr=itr-1;
  }
  driver.switchTo().window(windowHandle);
  WebElement username = driver.findElement(By.xpath("//*[@id='username']"));
  username.sendKeys("testing");
}
}

Comments

  1. Anonymous28/1/16

    Thank you for sharing the information.It is very interesting blog on Appium

    ReplyDelete
  2. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Appium.
    http://thecreatingexperts.com/appium-training-in-chennai/

    ReplyDelete

Post a Comment

Popular posts from this blog

Software Testing @ Microsoft

Trim / Remove spaces in Xpath?