# Copyright 2006 Adam Geras # Distributed under the BSD License (See accompanying file license.txt or copy at # http://www.opensource.org/licenses/bsd-license.php) set-psdebug -strict -trace 0 # Tests the Join-String cmdlet function Test-Command { # no separator # $contents = "Prefix","Suffix" # $expected = "PrefixSuffix" # $joined = join-string -Strings $contents # AssertEqual -Expected $expected -Actual $joined -Label "TC-JS-1" -Intent $Intention.ShouldPass write-host "`nBegin UI automation with PowerShell test" $pass = $true write-host "`nLaunching application to automate" invoke-item '.\TheAppToTest\bin\Debug\TheAppToTest.exe' [System.Threading.Thread]::Sleep(2000) $app = get-window "Form1" $cb = get-controlByIndex $app 4 $btn = get-control $app "Search" $tb = get-controlByIndex $app 3 write-host "`nHandle to Application is " $app write-host "Handle to ComboBox is" $cb write-host "Handle to Button is " $btn write-host "Handle to TextBox is " $tb write-host "`nClicking on search button" send-click $btn write-host "Finding Error Message box" [System.Threading.Thread]::Sleep(2000) $mbox = get-window "Error" write-host "Clicking Message Box away" $ok = get-control $mbox "OK" send-click $ok write-host "`nSending 'Product Name' to ComboBox" send-chars $cb "Product Name" write-host "Sending 'ad' to TextBox" send-chars $tb "ad" write-host "Re-clicking search button" send-click $btn write-host "`nChecking contents of ListBox for '222'" [System.Threading.Thread]::Sleep(2000) $lb = get-controlByIndex $app 1 write-host "Handle to ListBox is " $lb $result = get-listBox $lb "222" # if ($result -ge 0) { # write-host "Found '222' in ListBox!" # } # else { # write-host "Did NOT find '222' in ListBox" # $pass = $false # } AssertEqual -Expected 0 -Actual $result -Label "TC-1" -Intent $Intention.ShouldPass write-host "Checking contents of TextBox for 'ad'" [System.Threading.Thread]::Sleep(2000) $text = get-textBox $tb # if ($text -eq "ad") { # write-host "Found 'ad' in TextBox!" # } # else { # write-host "Did NOT find 'ad' in TextBox" # $pass = $false # } AssertEqual -Expected "ad" -Actual $text -Label "TC-2" -Intent $Intention.ShouldPass # if ($pass) { # write-host "`nTest scenario result = Pass" -foregroundcolor green # } # else { # write-host "`nTest scenario result = * FAIL *" -foregroundcolor red # } RaiseAssertions write-host "`nClicking File -> Exit in 5 seconds . . ." [System.Threading.Thread]::Sleep(5000) $dummy = read-host # pause to capture a screenshot send-menu $app 0 0 write-host "`nEnd UI automation with PowerShell test`n" # end script } # run the function library that contains the PowerShell Testing Functions # the functions are defined as global so you don't need to use dot sourcing if (!(Test-Path variable:_TESTLIB)) { c:\global\ps1TestLib\src\TestLib.ps1 } # run the function defined above that demonstrates the PowerShell Testing Functions Test-Command