When

MW 9:30am - 11:00am

Where

Tech LR 5

Who

Chris Riesbeck

Resources

Tutorial for Appium End to End Automation

This tutorial was posted to Piazza by Jiwei Xia. Thank you very much, Jiwei! I've reformatted the post for here and made a few editorial changes. Assume any errors were introduced by me.

A video of the end to end tests in action is here.

Guys, you might need help on Appium. Here is the brief tutorial.

Things you need:

It would be good if we can do automation in iOS simulator. However, I can't find a way to install our app into simulator. Even with steroids connect we can have one Scanner app in the simulator, but when the Appium start new one, the app is gone. As a result, I think we can only do automation on real phone.

If you find a way to automation in simulator, that is great. Please tell me.

Deploy your app to iPhone

As usual you need deploy your code to the Appgyver Cloud first.

In your app cloud configuring page:

In the Build Types part,

Download Appium GUI

It looks like this.

Click on the little Apple icon and set things like this

(Not sure the next step is a must but I did this.) To install Appium in command line:

npm install -g appium

These tool are need to be installed for establishing connection between your Mac and your phone.

brew install ios-webkit-debug-proxy
    
brew install ideviceinstaller

On your iPhone:

Download Eclipse

I ran the tests with Java. You may use other languages like JavaScript. I have not tested that.

Create new project.

Add these JARs.

Right click on your Java folder create TestNG class.

Include all the import files:

  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.HashMap;
  import java.util.List;
  import java.util.concurrent.TimeUnit;
  import org.testng.Assert;
  import org.testng.asserts.*;
  import org.testng.annotations.Test;
  import org.testng.annotations.BeforeTest;
  import org.testng.annotations.AfterTest;
  import org.openqa.selenium.*;
  import org.openqa.selenium.remote.CapabilityType;
  import org.openqa.selenium.remote.DesiredCapabilities;
  import org.openqa.selenium.remote.RemoteWebDriver;
  import org.openqa.selenium.support.ui.ExpectedCondition;
  import org.openqa.selenium.support.ui.ExpectedConditions;
  import org.openqa.selenium.support.ui.Select;
  import org.openqa.selenium.support.ui.WebDriverWait;
  import org.openqa.selenium.interactions.Action;
  import org.openqa.selenium.interactions.touch.TouchActions;

  import io.appium.java_client.AppiumDriver;
  import io.appium.java_client.MobileDriver;
  import io.appium.java_client.TouchAction;
  import io.appium.java_client.TouchShortcuts;
  import io.appium.java_client.ios.*;

Initial Settings:

  @BeforeTest
  public void beforeTest() throws MalformedURLException{
    DesiredCapabilities capabilities = new DesiredCapabilities();

    capabilities.setCapability("automationName", "Appium");
    capabilities.setCapability("browserName", "");
    capabilities.setCapability("autoLaunch",true);
    capabilities.setCapability("platfromName","iOS");
    capabilities.setCapability("platfromVersion","8.3");
    capabilities.setCapability("deviceName","Alfredx's iPhone 5");
    capabilities.setCapability("showIOSLog",true);
    wd = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
    wd.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    }

Then you can do something like the following to put text into text box.

WebElementusername =
  wd.findElements(By.xpath(" //UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAWebView[1]/UIATextField[1]"))
    .get(0);
  username.sendKeys();

Click Launch in Appium GUI.

Run your TestNG Java file as TestNG test. It could be found by right click on your file.

If everything goes well, your app will launch on your phone.

Then it will follow the script you wrote.

I'm 100% sure this tutorial doesn't make enough sense. Shoot me question if you have one.

Thanks

If you need help, or have advice to give, post to Piazza.