Daily automation: eliminating the fragility of tests. Part 2


The logically next step, after we started searching for a control using a wildcard, is to get a window by part of its name.

Task: use UIAutomation to get a window by a fragment of its name.

Requirements: demonstrate how to use the technique.

Solution: code that is needed is as simple as it can be:

Set-StrictMode -Version Latest;
ipmo [path]\UIAutomation.dll;
Start-Process calc; Get-UIAWindow -Name *alc*r

After we started the calc process, all the lines of code below will work:

Set-StrictMode -Version Latest;
ipmo [path]\UIAutomation.dll;
Start-Process calc;
Get-UIAWindow -Name *alc*r
Get-UIAWindow -Name Calc*
Get-UIAWindow -Name CA?culator
Get-UIAWindow -pn calc
Get-UIAWindow -pid (Start-Process calc -PassThru).Id
Start-Process calc -PassThru | Get-UIAWindow

There should be placed a note: whereas the asterisk ‘*’ is a replacement for anything including an empty place, the question mark ‘?’ requires that something non-empty was under the sign. I.e., the following replacements are right:
Calc*
*Calculator*
C*l*l*
However, Cal?culator is not right. Ca?culator or Cal?ulator both are right.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: