利用 appium + robot framework 實現跨平台 app 互動測試
DESCRIPTION
Android 跟 iOS 在自動化測試上的支援漸趨成熟,要在單機上實作 App 自動化測試並不是太困難,但如果 App 支援多個設備間資料的同步,或使用者之間可以互動的社群功能呢?本議程將與大家分享如何利用 Appium 實現涉及多支手機、不同平台間互動的自動化測試,過程中也將介紹 Robot Framework 跟 Page-Object Pattern 在 "跨平台測試案例" 這個議題上所扮演的角色。TRANSCRIPT
![Page 1: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/1.jpg)
利⽤用 Appium + Robot Framework!實現跨平台 App 互動測試Jeremy Kao ( / imsardine)
![Page 2: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/2.jpg)
• 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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/3.jpg)
Test Cases Involving Multiple Devices
• Data synchronization • Social features
• Sharing • Following • Messaging
• …
![Page 4: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/4.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/5.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/6.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/7.jpg)
A central/remote controller is needed.
?
A B
![Page 8: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/8.jpg)
Automation for Apps
Test case Appium servers Android / iOS / Firefox OS
![Page 9: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/9.jpg)
Appium Platforms Support
Native automation frameworks
• Extended Selenium WebDriver API • Various language bindings
(Source: Dev::Coder)
![Page 10: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/10.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/11.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/12.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/13.jpg)
Essentials and Long-term Considerations…
![Page 14: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/14.jpg)
• 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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/15.jpg)
Test Cases in Natural Language
Readability
![Page 16: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/16.jpg)
Data-driven Support - Test Template
Arguments
![Page 17: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/17.jpg)
Results - Reports
![Page 18: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/18.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/19.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/20.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/21.jpg)
User Keywords and Library Keywords
User Keywords
Library Keywords
![Page 22: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/22.jpg)
Import Test Libraries
Application Library
Page/Screen Libraries
![Page 23: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/23.jpg)
Application Library
![Page 24: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/24.jpg)
A
B
Application Library
Open App <DEVICE_ID> [<ALIAS]
Switch Device <ALIAS>
![Page 25: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/25.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/26.jpg)
Library Keywords - High Level, Domain TermsiOSAndroid
![Page 27: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/27.jpg)
Library Keywords - Scenario
Reusable keywords as bricks, from multiple keyword libraries.
iOSAndroid
![Page 28: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/28.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/29.jpg)
• 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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/30.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/31.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/32.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/33.jpg)
Page Objects Impl. in KKBOX (Android)
Page Library Keyword
Page Object Impl. (Android)
![Page 34: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/34.jpg)
Page Objects Impl. in KKBOX (Android)
UI interaction and details
UI Mapping
![Page 35: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/35.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/36.jpg)
Page Objects Impl. in KKBOX (iOS)
UI Mapping
Implement the same interface.
![Page 37: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/37.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/38.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/39.jpg)
PyUIA and Your App (WordPress)
![Page 40: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/40.jpg)
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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/41.jpg)
• 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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/42.jpg)
Google Test Automation Conference
Oct 28-29 Live Stream
![Page 43: 利用 Appium + Robot Framework 實現跨平台 App 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/43.jpg)
• 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 互動測試](https://reader034.vdocuments.mx/reader034/viewer/2022050907/55986c6a1a28ab280b8b4851/html5/thumbnails/44.jpg)
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).