Mobile Test Automation using one API and one infrastructure

Post on 05-Dec-2014

118 views 2 download

description

Presentation at Mobile App Europe Conference, Potsdam Germany October 2014.

Transcript of Mobile Test Automation using one API and one infrastructure

1

30.09.2014

MOBILE TEST AUTOMATION SELENIUM SELENDROID IOS-DRIVER

2

AGENDA

●  Welcome

●  Selenium Crash Course

●  ios-driver + Selendroid

●  Building a cross platform infrastructure

3

WHO AM I ? Gridfusion Software Solutions Michael Palotas Dipl. Ing. (FH) Nachrichtentechnik Email: michael.palotas@gridfusion.net LinkedIn: http://ch.linkedin.com/in/michaelpalotas/ Xing: https://www.xing.com/profile/Michael_Palotas Twitter: @michael_palotas Kontakt: Gerbiweg 2 8853 Lachen SWITZERLAND Tel.: +41 79 6690708

Founder / Principal Consultant Gridfusion Software Solutions

Head of Productivity & Test Engineering eBay International

4

WARM-UP

Why do you automate tests?

Which tests should be automated?

Who should automate?

What is different about mobile?

5

DISCLAIMER

THIS IS NOT A SELENDROID OR IOS-DRIVER TRAINING

6

MOBILE TEST AUTOMATION

Not as mature as web automation

Immature tools market

Tools are usually platform specific

Multi code base

7

EMULATORS VS. DEVICES

What to test where?

8

SAME AUTOMATION CODE BETWEEN PLATFORMS?

Sounds good first

but

Most apps are different between platforms

Different element locator strategy

Do reuse the helper functions

9

TEST INFRASTRUCTURE

AUT

DB

API

Browsers Mobiles

10

2. SELENIUM

11

A LITTLE SELENIUM HISTORY

Selenium was so named because Huggins, dissatisfied with testing tools on the market, was seeking a name that would position the product as an alternative to Mercury Interactive QuickTest Professional commercial testing software. The name, Selenium, was selected because selenium mineral supplements serve as a cure for mercury poisoning, Huggins explained.

12

WHAT IS SELENIUM?

SELENIUM AUTOMATES BROWSERS

THAT'S IT

... One more thing ...

Selenium is becoming a W3C standard: http://www.w3.org/TR/webdriver

13

WHAT IS SELENIUM?

Protocol which describes user interactions

Supports most browsers

Supports most programming languages

14

SELENIUM – WHAT IT IS NOT

a drag & drop tool

a network testing / monitoring tool

a performance testing tool

a reporting tool

a testcase management tool

15

WHY OPEN SOURCE?

It is free (…)

Independent of 3rd parties

Faster innovation cycles

Motivated employees

Easier hiring

16

THE SELENIUM „FLAVORS“

Selenium IDE Selenium Selenium GRID

Let’s forget about this one real quick

17

5. WEBDRIVER PROTOCOL

18

SELENIUM 2 / WEBDRIVER

JSON WIRE PROTOCOL

Client

Java

C#

Ruby

Python

Server

i.e. Selendroid, iOS-Driver

Server

Server

19

SELENIUM CLIENT

Is seen as Selenium by the users

Generates HTTP request, which are received by the server

Is called by the test framework or the CI server

Supported languages: Java, C#, Python, Ruby, Perl, PHP, JS

20

SELENIUM SERVER

Receives HTTP requests from server

Start and teardown of browser

Translates requests into browser specific commands

Communicates back to the client

21

6. SELENIUM BASICS

22

DOWNLOADS

-  http://www.seleniumhq.org/

-  http://selenium.googlecode.com/files/selenium-server-standalone-2.42.2.jar

-  Maven example:

23

DRIVER

Each browser has its own driver

Firefox driver is part of the standalone jar http://selenium.googlecode.com/files/selenium-server-standalone-2.42.2.jar

Chrome: https://code.google.com/p/selenium/wiki/ChromeDriver

Opera: https://code.google.com/p/selenium/wiki/OperaDriver

Internet Explorer: https://code.google.com/p/selenium/wiki/InternetExplorerDriver

24

DRIVER

Each driver implements the JSON Wire Protocol

Driver interacts with the browser (or mobile)

CLIENT

SERVER JSON Wire Protocol

BROWSER

DRIVER

25

OUR FIRST TEST

Open a Firefox Browser

Go to http://gridfusion.net

Close the browser @Test public void myFirstTest() { WebDriver driver = new FirefoxDriver(); driver.get("http://gridfusion.net"); driver.quit(); }

26

DRIVER API

27

PAGE TITLE

Open a Firefox browser

Go to http://gridfusion.net

Print the page title in the console

Close the browser

@Test public void pageTitleTest() { WebDriver driver = new FirefoxDriver(); driver.get("http://gridfusion.net"); String pageTitle = driver.getTitle(); System.out.println(pageTitle); driver.quit(); }

28

ASSERTS

Open a Firefox Browser

Go to: http://gridfusion.net

Verify Page Title = GRIDFUSION.net – Home

Close the browser

29

WEBELEMENT

Represents an HTML Element

Interactions on a page happen via WebElement

http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html

30

LOCATORS

id

cssSelector

linkText

name

partialLinkText

tagName

xpath

driver.findElement(By.XYZ)

31

7. REMOTE WEBDRIVER

32

REMOTE WEBDRIVER

Decouples tests from browsers

Machine 1 Eclipse TestNG CI

Machine 2 Browser HTTP

WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities);

33

DESIRED CAPABILITIES - BROWSER

DesiredCapabilities capability = new DesiredCapabilities(); capability.setBrowserName(“firefox”);

https://code.google.com/p/selenium/wiki/DesiredCapabilities

34

REMOTEWEBDRIVER

●  Start a selenium server:

●  java –jar selenium-server-standalone-2.42.2.jar

●  Use RemoteWebDriver and set DesiredCapabilities to Firefox

●  Open a Firefox browser

●  Go to: http://gridfusion.net

●  Close the browser

@Test public void remoteWebdriverFireFoxTest() throws MalformedURLException { DesiredCapabilities capability = DesiredCapabilities.firefox(); WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability); driver.get("http://gridfusion.net"); driver.quit(); }

35

8. SELENIUM GRID

36

WHY SELENIUM GRID?

Environment Management & Control

Scaling

Parallel execution of tests

Reduction of execution times

Crossover tests (web, mobile)

37

SELENIUM GRID

TEST TEST TEST TEST

SEQUENTIAL EXECUTION

TIME

n

TEST TEST TEST TEST

TEST TEST TEST TEST

PARALLEL EXECUTION

TEST TEST TEST TEST

TEST TEST TEST TEST

TIME

n

38

SCALING – SELENIUM GRID

CI

DEV

….

SELENIUM GRID HUB

IOS ANDROID

LINUX

WINDOWS

OSX

39

1. STEP– START THE GRID HUB

Open a new terminal window

Start the Selenium GRID hub by typing:

java -jar selenium-server-standalone-2.42.jar -role hub

Enter http://localhost:4444/grid/console into the browser

40

2. STEP– REGISTER A NODE

Open a second terminal window

Start and register a Selenium node by entering:

java -jar selenium-server-standalone-x.y.z.jar –role wd -hub http://localhost:4444/grid/register

41

SELENIUM NODE – STANDARD CONFIG

- Go to: http://localhost:4444/grid/console

Standard Configuration:

5 Firefox

5 Chrome

1 Internet Explorer

42

SCREENSHOTS

43

10. REPORTING

44

STANDARD REPORTS

-  TestNG reports are put into: **/test-output

-  Look for: emailable-report.html

45

CUSTOM REPORTING

-  By calling Reporter.log(“your log message”), you can add additional information to the report

46

SCREENSHOTS

- Screenshots can also be placed directly into the report

47

12. MOBILE AUTOMATION

48

SELENIUM 2 / WEBDRIVER

JSON WIRE PROTOCOL

Client

Java

C#

Ruby

Python

Server

i.e. Selendroid, iOS-Driver

Server

Server

49

(SOME) MOBILE AUTOMATION REQUIREMENTS

* Reuse of the existing Selenium infrastructure for the web

* Implementation of the Selenium protocol (JSON wire protocol)

* The application under test (aut) should not need to be modified

* Support for emulators/simulators as well as real devices

* Parallel execution of tests in a Selenium Grid

* Management of multiple applications, versions, languages

* Support for runtime inspection for the app

* Hybrid app support

* No jailbreaking of device required

50

IOS-DRIVER + SELENDROID

IOS: http://ios-driver.github.io/ios-driver/index.html

ANDROID: http://selendroid.io/

Both projects implement the Webdriver API (JSON Wire Protocol)

51

ANDROID: MOBILE WEB

52

ANDROID: NATIVE APP

53

IOS: MOBILE WEB

54

WRITE ONCE RUN EVERYWHERE

55

WRITE ONCE RUN EVERYWHERE

56

INSPECTOR

57

SAUCELABS CLOUD

58

WHAT HAVE YOU LEARNED TODAY?

59

THANK YOU