利用 appium + robot framework 實現跨平台 app 互動測試

44
Appium + Robot Framework 實現跨平台 App 互動測試 Jeremy Kao ( / imsardine)

Upload: jeremy-kao

Post on 05-Jul-2015

1.748 views

Category:

Software


0 download

DESCRIPTION

Android 跟 iOS 在自動化測試上的支援漸趨成熟,要在單機上實作 App 自動化測試並不是太困難,但如果 App 支援多個設備間資料的同步,或使用者之間可以互動的社群功能呢?本議程將與大家分享如何利用 Appium 實現涉及多支手機、不同平台間互動的自動化測試,過程中也將介紹 Robot Framework 跟 Page-Object Pattern 在 "跨平台測試案例" 這個議題上所扮演的角色。

TRANSCRIPT

Page 1: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

利⽤用 Appium + Robot Framework!實現跨平台 App 互動測試Jeremy Kao ( / imsardine)

Page 2: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

• Test cases involving multiple devices • A test script that works! • Essentials and long-term considerations • PyUIA - Python UI Automation • Q&A

Agenda

Page 3: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Test Cases Involving Multiple Devices

• Data synchronization • Social features

• Sharing • Following • Messaging

• …

Page 4: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

KKBOX - Playlist Auto-Sync• Easy to manage and organize playlists on various devices. • More than one devices (generally with different platforms)

are involved.

Page 5: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

The Test Case (iOS > Android)

1. On device A, create a new playlist.

2. On device B, check if the playlist created in step 1 appears.

A B

iOS Android

Page 6: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

The Test Case (Android > iOS)

1. On device A, create a new playlist.

2. On device B, check if the playlist created in step 1 appears.

B A(the same test case)

iOS Android

Page 7: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

A central/remote controller is needed.

?

A B

Page 8: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Automation for Apps

Test case Appium servers Android / iOS / Firefox OS

Page 9: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Appium Platforms Support

Native automation frameworks

• Extended Selenium WebDriver API • Various language bindings

(Source: Dev::Coder)

Page 10: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Multiple Devices Support - Multiple Servers

Driver A / B

*:4723

*:4725

Driver A / B

(one-to-one)

NOTE: Currently, each Appium server only serves one session/device at a time. To work around this, run multiple Appium servers. (#462)

iOS

Android

Page 11: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

A (Pseudo) Test Script That Works!

Android > iOS

iOS > Android

Test scenario

Locate UI elements and interact with them (in different ways)

Page 12: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

A (Pseudo) Test Script That Works!

Bad smell?May lead to too many if/else statements

Easy to read ?

Page 13: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Essentials and Long-term Considerations…

Page 14: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

• Keyword-driven testing (KDT) support. • Reusable keywords. • Abstraction of layers. • Technology-independent

• Acceptance testing and A-TDD support. • Specified in business domain language/

terms (natural language), that are shared between stakeholders.

• Requirements as tests -> Executable • Data-driven testing (DDT) support. • RIDE - Robot Framework IDE.

Robot Framework and RIDE

Page 15: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Test Cases in Natural Language

Readability

Page 16: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Data-driven Support - Test Template

Arguments

Page 17: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Results - Reports

Page 18: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Results - Logs

Device logs collected during the execution of a keyword and a test case.

Logs generated by test code

Page 19: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Results - Embedded Screenshots

• Take screenshots automatically before (and after) keyword execution.

• Take screenshots on demand in the test code.

Page 20: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

PageObj. (iOS)

PageObj. (Android)

Abstraction of LayersRequirements

Keywords

Keyword Impl.

Application Under Test

Testing Tools

Test Data

Python Prog.

Page 21: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

User Keywords and Library Keywords

User Keywords

Library Keywords

Page 22: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Import Test Libraries

Application Library

Page/Screen Libraries

Page 23: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Application Library

Page 24: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

A

B

Application Library

Open App <DEVICE_ID> [<ALIAS]

Switch Device <ALIAS>

Page 25: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Page/Screen Libraries - Modeling

Generally, one for each page/screen.

Services offered by this page/screen. (Page Object Pattern)

iOSAndroid

Page 26: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Library Keywords - High Level, Domain TermsiOSAndroid

Page 27: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Library Keywords - Scenario

Reusable keywords as bricks, from multiple keyword libraries.

iOSAndroid

Page 28: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

PageObj. (iOS)

PageObj. (Android)

Abstraction of LayersRequirements

Keywords

Keyword Impl.

Application Under Test

Testing Tools

Test Data

Python Prog.

Page 29: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

• Maintainability - less code duplications. • Readability - test code is about intention and scenarios. • Scalability - test code that scales without losing control.

Page Object Pattern / Modeling (POM)

Problem

Tests are brittle to (inevitable) changes in the UI.

Benefits

Page 30: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

PageObj. (iOS)

PageObj. (Android)

Abstraction of LayersRequirements

Keywords

Keyword Impl.

Application Under Test

Testing Tools

Test Data

Python Prog.

Page 31: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

A

B

Page Library Impl. in KKBOX

PyUIA

self._page_object points to CURRENT device. (delegation)

A/B = iOS | Android

Page Library Keywords

Keyword Impl.

Page 32: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

PageObj. (iOS)

PageObj. (Android)

Abstraction of LayersRequirements

Keywords

Keyword Impl.

Application Under Test

Testing Tools

Test Data

Python Prog.

Page 33: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Page Objects Impl. in KKBOX (Android)

Page Library Keyword

Page Object Impl. (Android)

Page 34: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Page Objects Impl. in KKBOX (Android)

UI interaction and details

UI Mapping

Page 35: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

PageObj. (iOS)

PageObj. (Android)

Abstraction of LayersRequirements

Keywords

Keyword Impl.

Application Under Test

Testing Tools

Test Data

Python Prog.

Page 36: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Page Objects Impl. in KKBOX (iOS)

UI Mapping

Implement the same interface.

Page 37: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

PageObj. (iOS)

PageObj. (Android)

Abstraction of LayersRequirements

Keywords

Keyword Impl.

Application Under Test

Testing Tools

Test Data

Python Prog.

where PyUIA fits into

Page 38: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

PyUIA (imsardine/pyuia)

Fork me on GitHub

$ pip install pyuia

Example: imsardine/pyuia-example-wordpress

A library/framework aiming to facilitate the implementation of UI test automation on various platforms, including mobile and desktop OSs.

Incubated by KKBOX SQA Team

Page 39: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

PyUIA and Your App (WordPress)

Page 40: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

PageObj. (iOS)

PageObj. (Android)

PyUIA and Your App (WordPress)Requirements

Keywords

Keyword Impl.

Application Under Test

Testing Tools

Test Data

Python Prog.

• WordPress • SignInScreen • MainScreen

• SignInScreen • MainScreen • …

Page 41: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

• Appium • Robot Framework and RIDE • Keyword-driven testing • Page Object Pattern / Modeling • PyUIA - Python UI Automation • …

利⽤用 Appium + Robot Framework!實現跨平台 App 互動測試

PyUIA (imsardine/pyuia)Jeremy Kao ( / imsardine)

Page 42: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Google Test Automation Conference

Oct 28-29 Live Stream

Page 43: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

• Appium • Robot Framework, RIDE • Keyword-driven testing - Wikipedia, the free encyclopedia • Page Object - Martin Fowler • Page Objects - Selenium • Acceptance Test-Driven Development With Robot Framework

(PDF)

References

Page 44: 利用 Appium + Robot Framework 實現跨平台 App 互動測試

Page Object Pattern / Modeling (POM)Pattern

• Model areas/fragments (on a given page/screen) that test code interacts with as objects.

• Public methods as services offered by the page/screen. (abstract, high-level, application/domain-specific)

• Assertion-free, except for asserting it is on the correct page/screen. The tests should be responsible for making assertions.

• Except for getter methods, return a page object representing the (navigation) destination.

• Encapsulate UI interaction, details, async (wait for).