Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

The elements' object model in UIAutomation PowerShell Extensions, part 1

10,187 views

Published on

The slides give a start to use new elements' dynamic object model.

Published in: Technology
  • Be the first to comment

The elements' object model in UIAutomation PowerShell Extensions, part 1

  1. 1. The Software Testing Using PowerShell team presents New object model in UIAutomation PowerShell Extensions part 1
  2. 2. Problem What actions does a control support? Select? Toggle? Click?
  3. 3. Problem ● first, we need to examine the control $radioButton.GetSupportedPatterns() ● and search for a cmdlet that invokes an action we need Get-Command *radio* ● and after all we need to test whether it works Get-UiaRadioButton hex | InvokeUiaRadioButtonSelectItem
  4. 4. Solution Each control supports some patterns why do not use them fluently? $radioButton = Get-UiaRadioButton hex $radioButton.Select() Intellisense should help to write code, methods should be available only if they are supported
  5. 5. Solution The new elements' object model is the answer!
  6. 6. Example task Turn calculator into the Standard mode:
  7. 7. Example code $menuView = Start-Process calc -PassThru | ` Get-UiaWindow | Get-UiaMenuItem view ($menuView.Expand() | Get-UiaMenuItem standard).Click() # menu item View exposes method Expand() # menu item Standard accepts Click()
  8. 8. Chaining methods The majority of methods return the object the method was called on: $btn1 = Start-Process calc -PassThru | GetUiaWindow | Get-UiaButton 1 $btn1.Click().NavigateToNextSibling().Click().Cl ick().Highlight() # this code writes 100 and highlights button 0
  9. 9. ISupportsSelectionItemPattern Let's change dec to hex: $rbtn = Get-UiaRadioButton hex $rbtn.Select()
  10. 10. ISupportsTransformPattern Move, Resize, Rotate $wnd.Move(500, 500) check whether a control supports a method of pattern: if ($wnd.CanResize) { $wnd.Resize(300, 300) } # not resizable
  11. 11. ISupportsWindowPattern $visualState = [System.Windows.Automation.WindowVisualState] $wnd.SetWindowVisualState( $visualState::Maximized) $wnd.WaitForInputIdle(60000) $wnd.Close()
  12. 12. ISupportsScrollItemPattern services.msc # the following may require run as Administrator $gridItem = Get-UiaWindow -n services | GetUiaDataGrid | Get-UiaDataItem Workstation $gridItem.ScrollIntoView()
  13. 13. ISupportsScrollPattern services.msc # the following may require run as Administrator $grid = Get-UiaWindow -n services | Get-UiaDataGrid $scrollAmount = [System.Windows.Automation.ScrollAmount] $grid.Scroll( $scrollAmount::LargeIncrement, $scrollAmount::SmallIncrement) $grid.ScrollHorizontal($scrollAmount::LargeDecrement) $grid.ScrollVertical($scrollAmount::NoAmount)
  14. 14. ISupportsValuePattern $editPrice = Get-UiaWindow -n *calc* | GetUiaEdit -Value 123 $editPrice.Value = 1234
  15. 15. ISupportsSelectionPattern services.msc # the following may require run as Administrator $grid = Get-UiaWindow -n services | GetUiaDataGrid $grid.GetItem(1,1).Click() $grid.GetSelection()
  16. 16. ISupportsTogglePattern $chkBox = Start-Process charmap -PassThru | ` Get-UiaWindow | Get-UiaCheckBox $chkBox.ToggleState $chkBox.Toggle() # the Toggle method turns on and off
  17. 17. IntelliSense As usual, PowerShell (partially) supports IntelliSense after you ran a piece of code:
  18. 18. The end Happy testing!

×