PowerShell UIAtomation

9.075 Aufrufe

Veröffentlicht am

Talks about PowerShell UIAutomation used by Y Soft for automating GUI Windows installer testing in multiple languages. How to integrate PowerShell with continuous integration system Jenkins.

Veröffentlicht in: Technologie, Bildung

PowerShell UIAtomation

  1. 1. Powershell UI Automation Jakub Čupera Technology Hour 24.10.2013
  2. 2. Installer
  3. 3. Installer Need of automated GUI tests!
  4. 4. Which tool? GUI Tools ● Scripting languages / API ● QAliber ● .NET, Java libraries ● SilkTest (Java, .NET, ...) ● Plugins into VS/Eclipse ● Jemmy (Java) ● UI Automation (.NET) ● Powershell UI Automation ● TestComplete ● TestAutomationFX ● AutoHotkey (macros) ● Sikuli (image recognition) ● Selenium (web) ...
  5. 5. And winner is... Powershell UI Automation
  6. 6. Why? ● Free tool, open-source ● ● Simple implementation ● ● ● Known technology Jenkins integration Other tools (Pester) Screenshot generation
  7. 7. Powershell ● Scripting language ● Management framework ● Integrated since Windows XP
  8. 8. Powershell Scripting language ● Dynamically typed variables ($) ● Conditions ● Loops (while, do, for, foreach) ● Lambda expressions ● Exception handling ● Access to .NET ( [string]::Format(...) ) ● Can run Cmdlets, PS scripts, functions, executables
  9. 9. Powershell Scripting language ● Pipeline (| operator) ● Tab completion ● Support wildcards (*) ● External modules
  10. 10. Powershell Cmdlets Management Framework ● Services ● Server Management ● Windows Server Update ● Scheduled Tasks ● DNS/IP management ● Active Directory ● Exchange ● ...
  11. 11. UI Automation ● API to access/manipulate GUI elements ● Successor to MSAA ● Released by Microsoft in 2005 ● Native part since Vista/Server 2008 ● Separate packages down to Windows XP ● Managed API since .NET 3.0 ● Used also for assistive technologies
  12. 12. Powershell UI Automation ● Powershell module using UIA API ● Wide range of supported UI operations ● ● Supports Win32, Windows Forms, WPF, Metro UI, Java SWT, PowerBuilder, Delphi Requires Powershell 2.0+ and .NET 3.5+
  13. 13. Installation ● Download http://uiautomation.codeplex.com ● Extract ~DocumentsWindowsPowershellModules ● Run Powershell and import Import-Module (ipmo)
  14. 14. Available actions ● Getting window (Get-UIAWindow) ● Getting components (Get-UIAButton, Get-UIAEdit,) ● Invoking actions (Invoke-UIACheckBoxToggle) ● Setting values (Set-UIAEditText) ● Getting values (Get-UIAEditText) ● Browsing menu (Get-UIAMenuItem, Invoke-UIAMenuItem) ● Checking state (Test-UIAControl) ● Screenshots (Save-UIAScreenshot) ● Get component attributes (Read-UIAControlName) ● Waiting for element state (Wait-UIAButtonEnabled) ● Start-UIARecorder ● …....
  15. 15. Getting Window Get-UIAWindow ● Process Name (-ProcessName, -pn) ● Process Id (-ProcessId, -pid) ● By Title (-Name) ● From process ● Wildcards can be used ● Returns AutomationElement object ● Get-UIAActiveWindow ● What if more processes are started?
  16. 16. Getting a Control Get-UIAControl ● Various Cmdlets to obtain all possible GUI elements Get-UIAButton, Get-UIAEdit, Get-UIARadioButton, ... ● Returns AutomationElement object ● Many aliases Get-UIAEdit = Get-UIATextBox ● Cmdlets wrap Get-UIAControl ● Name (-Name, -n) ● Automation Id (-AutomationId) ● Wildcards can be used ● Multiple objects can be selected ([x-y]) ● Popups are also processed
  17. 17. Actions Invoke-UIAAction ● Mouse clicking Invoke-UIAButtonClick, Invoke-UIAMenuItemClick, Invoke-UIACheckBoxToggle ... ● Scrolling Invoke-UIAScrollBarScroll ● Handling texts Get-UIAEditText, Set-UIAEditText ● And many others Invoke-UIAMenuItemExpand, Invoke-UIACalendarScroll, Set-UIAFocus,... ● Actions are type and context specific
  18. 18. Other Cmdlets Other Cmdlets ● Read-UIAControlName, Read-UIAControlAutomationId Get-UIAButton | Read-UIAControlName ● Save-UIAScreenshot Save-UIAScreenShot -Path “c:temp“ -Name 'test.jpg' -As jpeg ● Test-UIAControlState Test-UIAControlState -SearchCriteria @{Name=“OK“, ControlType=“button“ } ● Wait-UIAControlState Get-UIAButton | Wait-UIAButtonEnabled -Timeout 20 ● Start-UIARecorder ● Move-UIACursor ● ...
  19. 19. Passing Objects ● Passing control object as parameter $btn = Get-UIAButton -Name „Next“ Invoke-UIAButtonClick -InputObject $btn ● Passing object through pipe Get-UIAButton -Name „Next“ | Invoke-UIAButtonClick ● No need to pass window
  20. 20. Global Settings ● Global settings can be modified Logging, Timeouts, Highlighting, Screenshots, Error handling, ... ● Usage: [UIAutomation.Preferences]::Key = $value ● Cmdlet Show-UIAModuleSettings ● Some settings can be overriden locally Get-UIAButton -Timeout 20
  21. 21. Other Functionality Other Functionality ● ● Custom event handling -OnErrorEvent, -OnSuccess Cmdlets as tests -TestResultName ● Save screenshot on error ● Detailed logging
  22. 22. Examples
  23. 23. Tips & Tricks ● Tools UIVerify, UISpy, Spy++ ● Getting control nane Get-UIAWindow | Get-UIAButton | Read-UIAControlName Get-UIAWindow | Get-UIAControl | Read-UIAControlName ● Get cmdlets related to control Get-Command -Module UIA* *Button*
  24. 24. Gotchas ● Lack of documentation ● Last update in February 2013 ● Still officially Beta ● Loosing focus on window ● Needs to set focus on element to perform action ● User account limitations ● Save screenshot on error by default
  25. 25. Do you want to know more? ● http://msdn.microsoft.com (UIA API, .NET) ● http://uiautomation.codeplex.com ● http://softwaretestingusingpowershell.com

×