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:
- An iOS device
- I have not tested on Android
- A Mac
- Xcode
- Homebrew
- An Apple developer account
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.
- Generate your distribution file with .p12 extension,
- Generate your developer file with .p12 extension. This step needs the developer account.
- Generate your distribution .mobileprovisionfile for Ad Hoc .ipa file) for the class deployment task (optional)
- Generate your developer .mobileprovisionfile for Ad Hoc Debug .ipa for the end-to-end tests.
In your app cloud configuring page:
- put your distribution .p12 file on left
- put your developer .p12 file on the right.
- Enter the password you set for the two files.
In the Build Types part,
- Bundle identifier this is the ID you need to remember for Appium to identify the app you want to run.
- Choose the Development Provisioning Profile, the .mobileprovisionfile.
- Save and Build as Debug AdHoc Build.
- After several minutes, you will get your .ipa file in email.
- Install it into your iPhone.
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:
- Settings → Safari → Advanced → Web Inspector
- Settings → Developer → Enable UI Automation
Download Eclipse
I ran the tests with Java. You may use other languages like JavaScript. I have not tested that.
Create new project.
- Go to Eclipse → Help → Eclipse MarketPlace
- Search for TestNG and install it
- Make sure your JDK and JRE are over 1.7 version.
- Right click your project folder in eclipse → Property → Java Build Path -> Add External JARs
Add these JARs.
- javaclient2.1.0.jar
- seleniumjava2.46.0srcs.jar
- seleniumjava2.46.0.jar
- seleniumserverstandalone2.46.0_1.jar
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.