winappdriver - windows store apps test automation
TRANSCRIPT
12/11/2014
Windows Store Apps Test AutomationJeremy Kao (about.me/imsardine) @ KKBOX SQA Team
GTAC 2014 @ Google KirklandSeattle, WA
01
Agenda
✤ UI Automation (UIA)!
✤ UIA Security Model!
✤ Survey!
✤ WinAppDriver
01
UI Automation(UIA)
Bellevue TC Seattle, WA
UIA Overview
✤ Provider and Clients!
✤ Provider API - to create support for custom controls.!
✤ Client API - to create assistive technologies or implement automated testing.!
✤ Support various UI frameworks, including Win32, WinForms, WPF, HTML, Silverlight.!
✤ Provide a unified object model that masks any differences in the UI frameworks.
Testing Tools in Windows SDK
✤ Inspect (formerly known as UI Spy) - for inspecting element's accessibility data, including UIA properties and MSAA properties.!
✤ AccScope - for evaluating accessibility in the early phase of development, and finding out areas needed to be improved.!
✤ Both are good examples of UIA clients.
Key UIA Properties
✤ Automation ID - not localized, preferred.!
✤ Control Type!
✤ Name - may be localized.!
✤ Set a Unique Automation Property for Windows Store Controls for Testing
01
UIASecurity Model
✤ Be signed and trusted!
✤ uiAccess=“true” (manifest)!
✤ Be installed in a secure location
Pike Market Seattle, WA
Security Considerations
To use UIAccess, an assistive technology application needs to:!
✤ Be signed with a certificate to interact with applications running at a higher privilege level.!
✤ Be trusted by the system and run with administrative privileges. The application must be installed in a secure location that requires a user account control (UAC) prompt to write to (for example, the Program Files folder).!
✤ Be built with a manifest file that includes the UIAccess flag.
Source: Security Considerations for Assistive Technologies (Windows)
Be Signed and Trusted
To interact with applications running at a higher privilege level.
Process Explorer
uiAccess=“true” (manifest)
To gain access to the protected system UI.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <!-- omitted --> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> <security> <requestedPrivileges> <requestedExecutionLevel level="asInvoker" uiAccess="true"></requestedExecutionLevel> </requestedPrivileges> </security> </trustInfo> </assembly>
The manifest of Inspect.exe:
Test Code in C#
var accField = app.FindFirst(TreeScope.Descendants,
new PropertyCondition(AutomationElement.AutomationIdProperty, "txt_UserId"));
((ValuePattern)accField.GetCurrentPattern(ValuePattern.Pattern)).setValue("account");
! var pwdField = app.FindFirst(TreeScope.Descendants,
new PropertyCondition(AutomationElement.AutomationIdProperty, "txt_UserPwd"));
((ValuePattern)pwdField.GetCurrentPattern(ValuePattern.Pattern)).setValue("secret");
! var loginBtn = app.FindFirst(TreeScope.Descendants,
new PropertyCondition(AutomationElement.AutomationIdProperty, "btn_Login"));
((InvokePattern)loginBtn.GetCurrentPattern(InvokePattern.Pattern)).Invoke();
Test Code in Python
01
Survey✤ Code UI Test (VS Premium/Ultimate)!✤ IronPython!✤ Python for .NET!✤ WinAppDriver
Gum WallPike Market, Seattle, WA
Requirements
✤ Scriptable in Python ➠ Robot Framework and PyUIA integration!
✤ Support Windows Vista (.NET Framework 3.0 included) and above.!
✤ As a testing tool, it is important to have fewer dependencies.!
✤ Remote control (RC)
RF & PyUIA Integration
Python for .NET != IronPython
If you want to mainly base your code on the .NET framework, I'd highly recommend IronPython vs Python.NET. IronPython is pretty much native .NET - so it just works great when integrating with other .NET languages.!
Python.NET is good if you want to just integrate one or two components from .NET into a standard python application.
Source: IronPython vs. Python .NET - Stack Overflow
IronPython
✤ It works, but is slow and buggy?!
✤ Not 100% compatible with CPython, subtle differences may lead to big issues in the future.!
✤ No longer supported by Microsoft.
Python for .NET
✤ It works and performs very well.!
✤ We have to modify Python executable’s manifest and resign it. (tricky)!
✤ BTW, the Python code manipulating UIA API looks weird.
01
WinAppDriver
✤ Incubated by KKBOX SQA team.!
✤ imsardine/winappdriver (GitHub)!
✤ MIT License
First Starbucks Store Pike Market, Seattle, WA
Selenium for Browsers
Language bindings - Python, Ruby, Node.js, Java, C#, …
Source: http://imsardine.simplbug.com/note/selenium2/selenium2.html
Appium for Mobile Apps
Source: http://imsardine.simplbug.com/note/appium/appium.html
Test
WinAppDriver for Win (Store) Apps
WinAppDriver
UIA Client API
WPFWinFormsWin32
http://*:4444/wd/hub
Test
Windows DevicesWin & Unix-like
JSON/WebDriver!Wire Protocol
Lang. Bindings
JSON/WebDriver Wire Protocol
Source: The WebDriver Wire Protocol
WinAppDriver for Windows XYZ
WinAppDriver
UIA Client API
Win Phone?
Store Apps
Desktop!Apps
✤ Written in C#.!
✤ Implement JSON/WebDriver Wire Protocol.!
✤ Support desktop applications and store apps.!
✤ WP support is planned.
Test Code in Python
from selenium.webdriver import Remote, DesiredCapabilitiesdesired_caps = { 'app': 'http://.../AppPackages_0098.zip', 'appUserModelId': '2DE213C9.KKBOX_wttxem0f9q9s0!App', 'appWindowName': 'KKBOX', 'newCommandTimeout': 10 * 60, } driver = Remote('http://172.16.41.128:4444/wd/hub', desired_caps)
driver.find_element_by_id(‘txt_UserId’).set_value('account') driver.find_element_by_id(‘txt_UserPwd’).set_value('secret') driver.find_element_by_id(‘btn_Login’).click()
Test Code in C#
Benefits
✤ REPL (Read–Eval–Print Loop)!
✤ Freedom of choice!
✤ Programming languages!
✤ Testing frameworks!
✤ Operating systems on which test code will run.!
✤ Support Windows Vista and above.!
✤ Remote control - SUT and test code are not necessary to be run on the same machine. (deployment flexibility)
Similar Projects
✤ jasongdove/win-driver (prototyping? 08/05/2013)!
✤ Based on TestStask.White and ServiceStack (commercial licensing).!
✤ Does’t support store apps and touch gestures yet.!
✤ Twin (eBay, 08/21/2011)!
✤ Use UIA client API immediately.!
✤ Doesn’t support store apps and touch gestures yet.!
✤ Does not follow the standard, that’s why a dedicated Java client library is needed.
TODO
✤ Download, install and uninstall app packages automatically.!
✤ PyUIA Integration!
✤ Implement remaining commands defined in the protocol. (logs, screenshots, …)!
✤ Fast reset - clear data without uninstalling the package!
✤ WP support.!
✤ MacDriver for OS X test automation? (appium/appium-for-mac)
References
✤ UI Automation Overview, Using UI Automation for Automated Testing, Testing Tools - Windows Automation API!
✤ Automating the testing of Windows 8 apps - Windows 8 app developer blog - Site Home - MSDN Blogs (09-05-2012)!
✤ UI Automation Security Overview, Security Considerations for Assistive Technologies (Windows)!
✤ Windows Store Applications and Automated Testing – Part One, Two, Three (06/12/2013)
01
WinAppDriver Dev.✤ Env. - Windows SDK + Notepad!
✤ How To Build!
✤ Web server (HttpListener), request manager, session manager, sessions, endpoints, handlers, JSON (json.NET)
Sound TrainSeattle, WA