-
Notifications
You must be signed in to change notification settings - Fork 3
/
Calculator.Tests.ps1
94 lines (65 loc) · 2.87 KB
/
Calculator.Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$DebugPreference = 'SilentlyContinue'
$InformationPreference = 'Continue'
Describe "Calculator" {
BeforeAll {
. "$PSScriptRoot\common.ps1"
$deps = @{
'Interop.UIAutomationClient' = '10.19041.0';
'FlaUI.Core' = '4.0.0';
'FlaUI.UIA3' = '4.0.0';
}
Add-NuGetDependencies -NugetPackages $deps
$uia = New-Object FlaUI.UIA3.UIA3Automation
$cf = $uia.ConditionFactory
$aut = [Diagnostics.Process]::Start('calc')
$aut.WaitForInputIdle(5000) | Out-Null
Start-Sleep -s 2
# Retrieve the correct PID as this changes during application startup
$autPid = ((Get-Process).where{ $_.MainWindowTitle -eq 'Calculator' })[0].Id
$desktop = $uia.GetDesktop()
$mw = $desktop.FindFirstDescendant($cf.ByProcessId($autPid))
}
Context 'Can calculate' {
It 'Solves 5 + 9' {
(Get-AutomationButton $mw -Id 'num5Button').Click()
(Get-AutomationButton $mw -Id 'plusButton').Click()
(Get-AutomationButton $mw -Id 'num9Button').Click()
(Get-AutomationButton $mw -Id 'equalButton').Click()
$result = ((Get-AutomationTextBox $mw -Id 'CalculatorResults').Name) -replace '[^0-9]'
$result | Should -Be 14
}
It 'Solves 14 - 9' {
(Get-AutomationButton $mw -Id 'num1Button').Click()
(Get-AutomationButton $mw -Id 'num4Button').Click()
(Get-AutomationButton $mw -Id 'minusButton').Click()
(Get-AutomationButton $mw -Id 'num9Button').Click()
(Get-AutomationButton $mw -Id 'equalButton').Click()
$result = ((Get-AutomationTextBox $mw -Id 'CalculatorResults').Name) -replace '[^0-9]'
$result | Should -Be 5
}
It 'Solves 5 * 9' {
(Get-AutomationButton $mw -Id 'num5Button').Click()
(Get-AutomationButton $mw -Id 'multiplyButton').Click()
(Get-AutomationButton $mw -Id 'num9Button').Click()
(Get-AutomationButton $mw -Id 'equalButton').Click()
$result = ((Get-AutomationTextBox $mw -Id 'CalculatorResults').Name) -replace '[^0-9]'
$result | Should -Be 45
}
It 'Solves 45 / 9' {
(Get-AutomationButton $mw -Id 'num4Button').Click()
(Get-AutomationButton $mw -Id 'num5Button').Click()
(Get-AutomationButton $mw -Id 'divideButton').Click()
(Get-AutomationButton $mw -Id 'num9Button').Click()
(Get-AutomationButton $mw -Id 'equalButton').Click()
$result = ((Get-AutomationTextBox $mw -Id 'CalculatorResults').Name) -replace '[^0-9]'
$result | Should -Be 5
}
}
AfterAll {
$uia.Dispose()
$aut.Dispose()
Stop-Process -Force -Id $autPid
}
}