1
1
import logging
2
2
import os
3
- from os .path import isfile
4
3
import signal
5
4
import shutil
6
5
import subprocess
@@ -58,7 +57,7 @@ def get_screen_manager():
58
57
else :
59
58
return HostScreenManager ()
60
59
else :
61
- pytest . skip ( f"Platform ' { sys . platform } ' is not supported" )
60
+ return HostScreenManager ( )
62
61
63
62
64
63
def set_keyboard_layout (lang ):
@@ -91,20 +90,22 @@ def set_keyboard_layout(lang):
91
90
def screen_manager ():
92
91
with get_screen_manager () as _ :
93
92
94
- # this is a trick to keep one keyboard layout for full display lifetime,
95
- # otherwise server would regenerate layout on last client disconection
96
- # https://stackoverflow.com/questions/75919741/how-to-add-keyboard-layouts-to-xvfb
97
- # 1. run some app in the background for full duration on test
98
- # 2. configure keyboard layout
99
- # 3. test
100
- dummy = subprocess .Popen (["xlogo" ])
101
- time .sleep (0.5 )
93
+ if sys .platform == "linux" :
94
+ # this is a trick to keep one keyboard layout for full display lifetime,
95
+ # otherwise server would regenerate layout on last client disconection
96
+ # https://stackoverflow.com/questions/75919741/how-to-add-keyboard-layouts-to-xvfb
97
+ # 1. run some app in the background for full duration on test
98
+ # 2. configure keyboard layout
99
+ # 3. test
100
+ dummy = subprocess .Popen (["xlogo" ])
101
+ time .sleep (0.5 )
102
102
103
- set_keyboard_layout ("pl" )
103
+ set_keyboard_layout ("pl" )
104
104
105
105
yield
106
106
107
- dummy .kill ()
107
+ if sys .platform == "linux" :
108
+ dummy .kill ()
108
109
109
110
110
111
def log_config (tmpdir ) -> None :
@@ -139,6 +140,7 @@ def run_process_capture_logs(command, cwd, name="", process_holder=None) -> None
139
140
stderr = subprocess .STDOUT ,
140
141
text = True ,
141
142
cwd = cwd ,
143
+ encoding = "utf-8" ,
142
144
)
143
145
assert process , "Process creation failed"
144
146
assert process .stdout , "Could not get stdout"
@@ -152,6 +154,20 @@ def run_process_capture_logs(command, cwd, name="", process_holder=None) -> None
152
154
process .wait ()
153
155
154
156
157
+ def run_typing_process (workdir , text : str ) -> None :
158
+ if sys .platform == "win32" :
159
+ with open (workdir / "type.ahk" , "w" , encoding = "utf-8" ) as f :
160
+ f .write ("SetKeyDelay 400, 100\n " ) # 400ms between keys, 100ms between down/up.
161
+ f .write (f"SendEvent \" { text } \" \n " )
162
+ f .write ("exit" )
163
+ result = subprocess .run (["AutoHotkey.exe" , "/ErrorStdOut" , "type.ahk" ], cwd = workdir )
164
+ else :
165
+ result = subprocess .run (["xdotool" , "type" , "--delay" , "400" , text ])
166
+ logger .info (f"stdout: { result .stdout } " )
167
+ logger .info (f"stderr: { result .stderr } " )
168
+ assert result .returncode == 0
169
+
170
+
155
171
def __get_parameters ():
156
172
texts = [
157
173
"The quick brown fox jumps over the lazy dog" ,
@@ -190,9 +206,9 @@ def test_record_and_render(app_isolation, text: str, example) -> None:
190
206
args = ([app , "--record" , "events.bin" ], app_dir , "klawa" , processes ,)
191
207
)
192
208
thread .start ()
193
- time .sleep (2 )
209
+ time .sleep (10 )
194
210
195
- subprocess . run ([ "xdotool" , "type" , "--delay" , "400" , text ] )
211
+ run_typing_process ( app_dir , text )
196
212
197
213
process = processes .get ("klawa" )
198
214
if process and process .poll () is None :
@@ -202,3 +218,5 @@ def test_record_and_render(app_isolation, text: str, example) -> None:
202
218
203
219
args = [app , "--replay" , "events.bin" , "--render" , "output.webm" ]
204
220
run_process_capture_logs (args , app_dir )
221
+ assert (app_dir / "output.webm" ).is_file ()
222
+
0 commit comments