Mobile Test Automation using one API and one infrastructure

59
1 30.09.2014 MOBILE TEST AUTOMATION SELENIUM SELENDROID IOS-DRIVER

description

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

Transcript of Mobile Test Automation using one API and one infrastructure

Page 1: Mobile Test Automation using one API and one infrastructure

1

30.09.2014

MOBILE TEST AUTOMATION SELENIUM SELENDROID IOS-DRIVER

Page 2: Mobile Test Automation using one API and one infrastructure

2

AGENDA

●  Welcome

●  Selenium Crash Course

●  ios-driver + Selendroid

●  Building a cross platform infrastructure

Page 3: Mobile Test Automation using one API and one infrastructure

3

WHO AM I ? Gridfusion Software Solutions Michael Palotas Dipl. Ing. (FH) Nachrichtentechnik Email: [email protected] 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

Page 4: Mobile Test Automation using one API and one infrastructure

4

WARM-UP

Why do you automate tests?

Which tests should be automated?

Who should automate?

What is different about mobile?

Page 5: Mobile Test Automation using one API and one infrastructure

5

DISCLAIMER

THIS IS NOT A SELENDROID OR IOS-DRIVER TRAINING

Page 6: Mobile Test Automation using one API and one infrastructure

6

MOBILE TEST AUTOMATION

Not as mature as web automation

Immature tools market

Tools are usually platform specific

Multi code base

Page 7: Mobile Test Automation using one API and one infrastructure

7

EMULATORS VS. DEVICES

What to test where?

Page 8: Mobile Test Automation using one API and one infrastructure

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

Page 9: Mobile Test Automation using one API and one infrastructure

9

TEST INFRASTRUCTURE

AUT

DB

API

Browsers Mobiles

Page 10: Mobile Test Automation using one API and one infrastructure

10

2. SELENIUM

Page 11: Mobile Test Automation using one API and one infrastructure

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.

Page 12: Mobile Test Automation using one API and one infrastructure

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

Page 13: Mobile Test Automation using one API and one infrastructure

13

WHAT IS SELENIUM?

Protocol which describes user interactions

Supports most browsers

Supports most programming languages

Page 14: Mobile Test Automation using one API and one infrastructure

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

Page 15: Mobile Test Automation using one API and one infrastructure

15

WHY OPEN SOURCE?

It is free (…)

Independent of 3rd parties

Faster innovation cycles

Motivated employees

Easier hiring

Page 16: Mobile Test Automation using one API and one infrastructure

16

THE SELENIUM „FLAVORS“

Selenium IDE Selenium Selenium GRID

Let’s forget about this one real quick

Page 17: Mobile Test Automation using one API and one infrastructure

17

5. WEBDRIVER PROTOCOL

Page 18: Mobile Test Automation using one API and one infrastructure

18

SELENIUM 2 / WEBDRIVER

JSON WIRE PROTOCOL

Client

Java

C#

Ruby

Python

Server

i.e. Selendroid, iOS-Driver

Server

Server

Page 19: Mobile Test Automation using one API and one infrastructure

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

Page 20: Mobile Test Automation using one API and one infrastructure

20

SELENIUM SERVER

Receives HTTP requests from server

Start and teardown of browser

Translates requests into browser specific commands

Communicates back to the client

Page 21: Mobile Test Automation using one API and one infrastructure

21

6. SELENIUM BASICS

Page 22: Mobile Test Automation using one API and one infrastructure

22

DOWNLOADS

-  http://www.seleniumhq.org/

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

-  Maven example:

Page 23: Mobile Test Automation using one API and one infrastructure

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

Page 24: Mobile Test Automation using one API and one infrastructure

24

DRIVER

Each driver implements the JSON Wire Protocol

Driver interacts with the browser (or mobile)

CLIENT

SERVER JSON Wire Protocol

BROWSER

DRIVER

Page 25: Mobile Test Automation using one API and one infrastructure

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(); }

Page 26: Mobile Test Automation using one API and one infrastructure

26

DRIVER API

Page 27: Mobile Test Automation using one API and one infrastructure

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(); }

Page 28: Mobile Test Automation using one API and one infrastructure

28

ASSERTS

Open a Firefox Browser

Go to: http://gridfusion.net

Verify Page Title = GRIDFUSION.net – Home

Close the browser

Page 29: Mobile Test Automation using one API and one infrastructure

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

Page 30: Mobile Test Automation using one API and one infrastructure

30

LOCATORS

id

cssSelector

linkText

name

partialLinkText

tagName

xpath

driver.findElement(By.XYZ)

Page 31: Mobile Test Automation using one API and one infrastructure

31

7. REMOTE WEBDRIVER

Page 32: Mobile Test Automation using one API and one infrastructure

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);

Page 33: Mobile Test Automation using one API and one infrastructure

33

DESIRED CAPABILITIES - BROWSER

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

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

Page 34: Mobile Test Automation using one API and one infrastructure

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(); }

Page 35: Mobile Test Automation using one API and one infrastructure

35

8. SELENIUM GRID

Page 36: Mobile Test Automation using one API and one infrastructure

36

WHY SELENIUM GRID?

Environment Management & Control

Scaling

Parallel execution of tests

Reduction of execution times

Crossover tests (web, mobile)

Page 37: Mobile Test Automation using one API and one infrastructure

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

Page 38: Mobile Test Automation using one API and one infrastructure

38

SCALING – SELENIUM GRID

CI

DEV

….

SELENIUM GRID HUB

IOS ANDROID

LINUX

WINDOWS

OSX

Page 39: Mobile Test Automation using one API and one infrastructure

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

Page 40: Mobile Test Automation using one API and one infrastructure

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

Page 41: Mobile Test Automation using one API and one infrastructure

41

SELENIUM NODE – STANDARD CONFIG

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

Standard Configuration:

5 Firefox

5 Chrome

1 Internet Explorer

Page 42: Mobile Test Automation using one API and one infrastructure

42

SCREENSHOTS

Page 43: Mobile Test Automation using one API and one infrastructure

43

10. REPORTING

Page 44: Mobile Test Automation using one API and one infrastructure

44

STANDARD REPORTS

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

-  Look for: emailable-report.html

Page 45: Mobile Test Automation using one API and one infrastructure

45

CUSTOM REPORTING

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

Page 46: Mobile Test Automation using one API and one infrastructure

46

SCREENSHOTS

- Screenshots can also be placed directly into the report

Page 47: Mobile Test Automation using one API and one infrastructure

47

12. MOBILE AUTOMATION

Page 48: Mobile Test Automation using one API and one infrastructure

48

SELENIUM 2 / WEBDRIVER

JSON WIRE PROTOCOL

Client

Java

C#

Ruby

Python

Server

i.e. Selendroid, iOS-Driver

Server

Server

Page 49: Mobile Test Automation using one API and one infrastructure

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

Page 50: Mobile Test Automation using one API and one infrastructure

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)

Page 51: Mobile Test Automation using one API and one infrastructure

51

ANDROID: MOBILE WEB

Page 52: Mobile Test Automation using one API and one infrastructure

52

ANDROID: NATIVE APP

Page 53: Mobile Test Automation using one API and one infrastructure

53

IOS: MOBILE WEB

Page 54: Mobile Test Automation using one API and one infrastructure

54

WRITE ONCE RUN EVERYWHERE

Page 55: Mobile Test Automation using one API and one infrastructure

55

WRITE ONCE RUN EVERYWHERE

Page 56: Mobile Test Automation using one API and one infrastructure

56

INSPECTOR

Page 57: Mobile Test Automation using one API and one infrastructure

57

SAUCELABS CLOUD

Page 58: Mobile Test Automation using one API and one infrastructure

58

WHAT HAVE YOU LEARNED TODAY?

Page 59: Mobile Test Automation using one API and one infrastructure

59

THANK YOU