31
Building a Mobile Automation Framework Around Appium Ru Cindrea - @ru_altom

Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

  • Upload
    others

  • View
    14

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Building a Mobile Automation Framework Around Appium

Ru Cindrea - @ru_altom

Page 2: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Who am I?

Page 3: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

In this demo / talk

Page 4: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

The test app - Android

Page 5: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

The test app - iOS

Page 6: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Appium for Mobile App AutomationAn open source framework for Android and iOS

Page 7: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Appium

Page 8: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

public class AndroidTest {

private AppiumDriver<WebElement> driver;

@Before

public void setUp() throws Exception {

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability("deviceName","Nexus 5X");

capabilities.setCapability("app","executables/app.apk");

driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

}

@After

public void tearDown() throws Exception {

driver.quit();

}

@Test

public void loginTest(){

driver.findElement(By.id("email")).sendKeys("[email protected]");

driver.findElement(By.id("password")).sendKeys("hello");

driver.findElement(By.id("email_sign_in_button")).click();

assertEquals("Main Activity", driver.currentActivity());

}

}

AndroidTest.java

56789

1011121314151617181920212223242526272829303132333435363738394041

Page 9: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

public class IOSTest {

private AppiumDriver<WebElement> driver;

@Before

public void setUp() throws Exception {

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability("deviceName","iPhpne 6s");

capabilities.setCapability("app","executables/app.ipa");

driver = new IOSDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

}

@After

public void tearDown() throws Exception {

driver.quit();

}

@Test

public void loginTest(){

driver.findElement(By.id("username")).sendKeys("[email protected]");

driver.findElement(By.id("password")).sendKeys("hello");

driver.findElement(By.id("loginButton")).click();

assertTrue(driver.findElement(By.id("Welcome Test User")).isDisplayed());

}

}

IOSTest.java

56789

1011121314151617181920212223242526272829303132333435363738394041

Page 10: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Some common problems

• Maintenance• Page Object Model • How to add more / better checks?

• Reporting• How and what framework to use• What to report?

• Steps taken, screenshots, videos, logs, crashes

• Infrastructure:• Device management • Appium server management• Parallel running

Page 11: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Page Object Model - Page Factory

@AndroidFindBy(id = "username")@iOSFindBy(id = "email")private MobileElement email;…

PageFactory.initElements(driver, this);

Page 12: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

AltRunner

Page 13: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

alt-runner

- Java module- Imported in your test

project to run the tests

- Deals with:- Reporting + Logs- Appium Server

Management- Device Selection and

management

Page 14: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

alt-multi-runner

- NodeJs application- Runs locally

- Deals with:- Starting the tests- Parallel test runs- Displaying the

results

Page 15: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Demo - alt-multi-runner

Page 16: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Appium Server Management

Page 17: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

public void setupAndroidDriver() throws MalformedURLException { DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability("deviceName", "LG Nexus 5X"); capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);

capabilities.setCapability("app","executables/app.apk");

driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);}

Setup Appium Driver

1234 567891011121314151617181920212223

Page 18: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

public void setupAndroidDriver() throws MalformedURLException { DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability("deviceName", "LG Nexus 5X"); capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);

capabilities.setCapability("app","executables/app.apk");

driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);}

Setup Appium Driver

1234 567891011121314151617181920212223

Page 19: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

package com.example;

import ro.altom.altrunner.SingleRunner;

public class MyRunner extends SingleRunner {}

import io.appium.java_client.AppiumDriver;import ro.altom.altrunner.contexts.TestContext;

public class LoginTest {

private AppiumDriver driver = (AppiumDriver) TestContext.instance.get().getDriver();

@Test void loginWithValidCredentials() {

…. }

Runner Class

1234 567891011121314151617181920212223

Page 20: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Device Management

Page 21: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Device Info

Page 22: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Reporting

Page 23: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Allure - An open source test reporting framework

@Step("Type username {0}")public void typeUsername(String text);

@Attachment()public void takeScreenshot();

http://allure.qatools.ru

Page 24: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Logs - Video, Crash, Memory, CPU

Page 25: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Device Commands

Page 26: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Device Commands

Page 27: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Test Injector

Page 28: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Demo

Page 29: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

What next?

Page 30: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

What next?

Ideas for the future:

- Extend the runner for Selenium WebDriver- Add more functionality to the iOS device management and logs- Open source (some of) it

Page 31: Around Appium Building a Mobile Automation Framework · 2020-02-27 · Appium for Mobile App Automation An open source framework for Android and iOS

Questions?