Skip to content

Commit c0252a4

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 e4e1dd5 commit c0252a4

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
@@ -67,7 +67,9 @@ RunWaitOne(command) {
6767
return Result
6868
}
6969

70-
CaptureTextFromWindowsTerminal() {
70+
CaptureTextFromWindowsTerminal(winTitle) {
71+
if winTitle != ''
72+
WinActivate winTitle
7173
ControlGetPos &cx, &cy, &cw, &ch, 'Windows.UI.Composition.DesktopWindowContentBridge1', "A"
7274
titleBarHeight := 54
7375
scrollBarWidth := 28
@@ -76,23 +78,36 @@ CaptureTextFromWindowsTerminal() {
7678
SavedClipboard := ClipboardAll
7779
A_Clipboard := ''
7880
SendMode('Event')
81+
if winTitle != ''
82+
WinActivate winTitle
7983
MouseMove cx + pad, cy + titleBarHeight + pad
84+
if winTitle != ''
85+
WinActivate winTitle
8086
MouseClickDrag 'Left', , , cx + cw - scrollBarWidth, cy + ch - pad, , ''
87+
if winTitle != ''
88+
WinActivate winTitle
8189
MouseClick 'Right'
8290
ClipWait()
8391
Result := A_Clipboard
8492
Clipboard := SavedClipboard
8593
return Result
8694
}
8795

88-
WaitForRegExInWindowsTerminal(regex, errorMessage, successMessage, timeout := 5000) {
96+
WaitForRegExInWindowsTerminal(regex, errorMessage, successMessage, timeout := 5000, winTitle := '') {
8997
timeout := timeout + A_TickCount
9098
; Wait for the regex to match in the terminal output
91-
while not RegExMatch(CaptureTextFromWindowsTerminal(), regex)
99+
while true
92100
{
101+
capturedText := CaptureTextFromWindowsTerminal(winTitle)
102+
if RegExMatch(capturedText, regex)
103+
break
93104
Sleep 100
94-
if A_TickCount > timeout
105+
if A_TickCount > timeout {
106+
Info('Captured text:`n' . capturedText)
95107
ExitWithError errorMessage
108+
}
109+
if winTitle != ''
110+
WinActivate winTitle
96111
MouseClick 'WheelDown', , , 20
97112
}
98113
Info(successMessage)

0 commit comments

Comments
 (0)