Automation for mobile apps Presenter: Nikita Mader
Tools we will learn and utilize today: Plan for the session: What is Appium and how does it work Environment installation (75% of all efforts) Hands on experience in mobile automation Tools we will learn and utilize today: Android SDK including Android AVD Android ADB UI Automator Viewer Appium ;)
There are multiple reasons: Selenium Webdriver is the standard for web automation. It is used daily by thousands of people. Last years Appium became one of the most popular tool for mobile automation. Why? There are multiple reasons: Test native, hybrid, web apps Cross-platform - Support Android and iOS Test mobile web (Safari for iOS and Chrome for Android) Does not require to recompile your app WebDriver API
So, what is Appium? Appium is an open source, cross platform tool for mobile automation. Appium ecosystem has a client-server architecture based on JSON wire protocol. Appium server is written on Node.js Basically, Appium is an HTTP server that creates and handles WebDriver sessions. Appium supports all Webdriver client libraries: Java, Python, Ruby, C#, Javascript
Features & Limitations: Implements Selenium Webdriver interfaces Provides common libraries for all platforms Extends Selenium WebDriver with additional functionality such as: driver.pinch(), driver.zoom(), driver.current_activity(), driver.lock() Limitations: Android version 4.2+ required Requires Mac OSX for iOS automation
Architectur
Environment setup: Download Appium server from http://appium.io/downloads.html Android SDK Copy to C:\android-sdk Install Intel HAXM if running on emulator from C:\android-sdk\extras\intel\Hardware_Accelerated_Execution_Manager Download Appium JAR from maven repository search.maven.org - g:io.appium a:java-client 4. Download Selenium JAR from seleniumhq.org
Environment setup: Environment variables Go to properties of computer -> Advanced system settings -> Environment variables -> and add “C:\android-sdk\tools;C:\android-sdk\platform-tools” to Path variable create new JAVA_HOME variable and provide path to JDK. Example: C:\Program Files\Java\jre7 create new ANDROID_HOME and provide path to SDK. Example: C:\android-sdk
Environment setup: Now lets verify we did everything correctly: Open command prompt(CP) (Win+r -> type CMD) If you are going to use emulator type in CP “android avd” and press enter If you are using your phone please turn on USB debugging in developer settings (7 taps) If you see AVD manager opened you are done, if not please check environment variables Create new AVD Check its status(or your Android phone connected) by typing “adb devices” in CP
Appium methods overview Lock the screen: driver.lockScreen(); Send the currently active app to the background: driver.runAppInBackground(); Hide the keyboard: driver.hideKeyboard(); Open the notification shade Android only: driver.openNotifications(); Check if an app is installed: driver.isAppInstalled("com.example.android.apis");
Appium methods overview Install an app to the device: driver.installApp("path/to/my.apk"); Remove an app from the device: driver.removeApp("com.example.android.apis"); Simulate the device shaking: driver.shake(); Close the app: driver.closeApp(); Send a key event to the device: driver.sendKeyEvent(AndroidKeyCode.HOME);
Appium methods overview TOUCHACTION / MULTITOUCHACTION: TouchAction action = new TouchAction(driver) .press(mapview, 10, 10) .release(). perform(); Pinch the screen: driver.pinch(element); Zoom the screen: driver.zoom(element); Pull a file from the device: driver.pullFile("Library/AddressBook/AddressBook.sqlitedb"); Send key code to the device(Android): driver.sendKeyEvent(AndroidKeyCode.HOME); or http://developer.android.com/reference/android/view/KeyEvent.html
Appium methods overview Scroll to an element: WebElement element = driver.findElement(By.name("Element Name")); HashMap<String, String> arguments = new HashMap<String, String>(); arguments.put("element", element.getId()); (JavascriptExecutor)driver.executeScript("mobile: scrollTo", arguments); Adjusting Network Connection: driver.setNetworkConnection(1); driver.getNetworkConnection(1) https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/network_connection.md
Lets move on to the hands on session! File appdir = new File("src"); File app = new File(appdir, "MyNetDiaryCalorieCounter.apk"); DesiredCapabilities cap = new DesiredCapabilities(); cap.setCapability( MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID ); cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android emulator"); cap.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "100"); driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap); …………… …… … .. .
https://github.com/appium/appium-dot-app Resources https://github.com/appium/appium-dot-app