Skip to content

Commit ebf3a9a

Browse files
committed
ui-tests: prepare WaitForRegExInWindowsTerminal() for disruptions
I want to add an integration test that clones a repository via SSH. Unfortunately, I have not found a better way than to run OpenSSH for Windows' `sshd.exe` in debug mode, in which case every successful connection will open a terminal window. Let's be prepared for these annoying extra windows by forcefully activating the desired window as needed. This change is admittedly a bit intrusive; I did not find any more elegant way to achieve the same result, though. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent ab92942 commit ebf3a9a

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

ui-tests/ui-test-library.ahk

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ RunWaitOne(command) {
7878
; This _kinda_ works, the text is selected (all text, in fact), but the PowerShell itself
7979
; _also_ processes the keyboard events and therefore they leave ugly and unintended
8080
; `^Ac` characters in the prompt. So that alternative is not really usable.
81-
CaptureTextFromWindowsTerminal() {
81+
CaptureTextFromWindowsTerminal(winTitle := '') {
82+
if winTitle != ''
83+
WinActivate winTitle
8284
ControlGetPos &cx, &cy, &cw, &ch, 'Windows.UI.Composition.DesktopWindowContentBridge1', "A"
8385
titleBarHeight := 54
8486
scrollBarWidth := 28
@@ -87,23 +89,36 @@ CaptureTextFromWindowsTerminal() {
8789
SavedClipboard := ClipboardAll
8890
A_Clipboard := ''
8991
SendMode('Event')
92+
if winTitle != ''
93+
WinActivate winTitle
9094
MouseMove cx + pad, cy + titleBarHeight + pad
95+
if winTitle != ''
96+
WinActivate winTitle
9197
MouseClickDrag 'Left', , , cx + cw - scrollBarWidth, cy + ch - pad, , ''
98+
if winTitle != ''
99+
WinActivate winTitle
92100
MouseClick 'Right'
93101
ClipWait()
94102
Result := A_Clipboard
95103
Clipboard := SavedClipboard
96104
return Result
97105
}
98106

99-
WaitForRegExInWindowsTerminal(regex, errorMessage, successMessage, timeout := 5000) {
107+
WaitForRegExInWindowsTerminal(regex, errorMessage, successMessage, timeout := 5000, winTitle := '') {
100108
timeout := timeout + A_TickCount
101109
; Wait for the regex to match in the terminal output
102-
while not RegExMatch(CaptureTextFromWindowsTerminal(), regex)
110+
while true
103111
{
112+
capturedText := CaptureTextFromWindowsTerminal(winTitle)
113+
if RegExMatch(capturedText, regex)
114+
break
104115
Sleep 100
105-
if A_TickCount > timeout
116+
if A_TickCount > timeout {
117+
Info('Captured text:`n' . capturedText)
106118
ExitWithError errorMessage
119+
}
120+
if winTitle != ''
121+
WinActivate winTitle
107122
MouseClick 'WheelDown', , , 20
108123
}
109124
Info(successMessage)

0 commit comments

Comments
 (0)