-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathwindowsbasetest.pm
235 lines (206 loc) · 9.41 KB
/
windowsbasetest.pm
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# SUSE's openQA tests
#
# Copyright 2016 SUSE LLC
# SPDX-License-Identifier: FSFAP
package windowsbasetest;
use Mojo::Base qw(basetest);
use Utils::Architectures qw(is_aarch64);
use testapi;
sub windows_run {
my ($self, $cmd) = @_;
send_key 'super-r';
wait_still_screen;
send_key 'backspace';
assert_screen 'windows-run';
enter_cmd $cmd;
wait_still_screen;
}
sub _setup_serial_device {
if (is_aarch64) {
type_string '$port = new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one', max_interval => 125;
} else {
type_string '$port = new-Object System.IO.Ports.SerialPort COM1,9600,None,8,one', max_interval => 125;
}
wait_screen_change(sub { send_key 'ret' }, 10);
type_string '$port.open()', max_interval => 125;
wait_screen_change(sub { send_key 'ret' }, 10);
type_string '$port.WriteLine("Serial Port has been opened...")', max_interval => 125;
wait_screen_change(sub { send_key 'ret' }, 10);
wait_serial 'Serial Port has been opened...';
}
sub use_search_feature {
my ($self, $string_to_search) = @_;
return unless ($string_to_search);
send_key_until_needlematch "windows-search-bar", 'super-s';
wait_still_screen stilltime => 2, timeout => 15;
type_string "$string_to_search ", max_interval => 100, wait_still_screen => 0.5;
}
sub select_windows_in_grub2 {
return unless (get_var('DUALBOOT'));
assert_screen "grub-reboot-windows", 125;
send_key "down" for (1 .. 2);
send_key "ret";
}
sub open_powershell_as_admin {
my ($self, %args) = @_;
#If using windows server, and logged with Administrator, only open powershell
if (get_var('QAM_WINDOWS_SERVER')) {
send_key_until_needlematch 'windows-quick-features-menu', 'super-x';
wait_screen_change { send_key('shift-a') };
wait_screen_change { assert_and_click('window-max') };
assert_screen 'windows_server_powershell_opened', 30;
} else {
if (check_var('WIN_VERSION', '10')) {
send_key_until_needlematch 'windows-quick-features-menu', 'super-x';
wait_screen_change { send_key('shift-a') };
} elsif (check_var('WIN_VERSION', '11')) {
# In Win11 there's need to launch PowerShell from "Run command", as
# "Quick features menu" fails sometimes.
send_key_until_needlematch 'run-command-window', 'super-r';
wait_screen_change { type_string 'Powershell' };
# Ctrl+Shift+Return launchs command as Admin
send_key 'ctrl-shift-ret';
} else {
die("WIN_VERSION variable does not match '10' neither '11'!");
}
assert_screen(["windows-user-account-ctl-hidden", "windows-user-acount-ctl-allow-make-changes"], 240);
assert_and_click "windows-user-account-ctl-hidden" if match_has_tag("windows-user-account-ctl-hidden");
assert_and_click "windows-user-acount-ctl-yes";
wait_still_screen stilltime => 3, timeout => 12;
if (check_var('WIN_VERSION', '11')) {
# When opening Powershell, sometimes the startup menu window pops up.
assert_screen(['powershell-with-startup-menu', 'powershell-as-admin-window'], 240);
send_key 'esc' if match_has_tag('powershell-with-startup-menu');
}
assert_screen 'powershell-as-admin-window', timeout => 240;
assert_and_click 'window-max';
wait_still_screen stilltime => 3, timeout => 12;
_setup_serial_device unless (exists $args{no_serial});
}
}
sub run_in_powershell {
my ($self, %args) = @_;
my $rc_hash = testapi::hashed_string $args{cmd};
type_string $args{cmd}, max_interval => 125;
if (exists $args{code} && (ref $args{code} eq 'CODE')) {
wait_screen_change(sub { send_key 'ret' }, 10);
$args{code}->();
send_key 'ctrl-l';
} elsif (get_var('QAM_WINDOWS_SERVER')) {
save_screenshot;
wait_screen_change(sub { send_key 'ret' }, 10);
assert_screen($args{tags});
return;
} else {
type_string ';$port.WriteLine(\'' . $rc_hash . '\' + $?)', max_interval => 125;
wait_screen_change(sub { send_key 'ret' }, 10);
wait_serial("${rc_hash}True", timeout => (exists $args{timeout}) ? $args{timeout} : 60) or
die "Expected string (${rc_hash}True) was not found on serial";
}
}
sub reboot_or_shutdown {
my ($self, $is_reboot) = @_;
send_key_until_needlematch 'ms-quick-features', 'super-x';
wait_screen_change(sub { send_key 'u' }, 10);
sleep 1;
wait_screen_change(sub { send_key((!!$is_reboot) ? 'r' : 'u') }, 10);
#if using windows server
if (get_var('QAM_WINDOWS_SERVER')) {
send_key 'ret';
}
save_screenshot;
assert_shutdown unless ($is_reboot);
}
sub wait_boot_windows {
my ($self, $is_firstboot) = @_;
# Reset the consoles: there is no user logged in anywhere
reset_consoles;
# Installation process has become slower since 24H2
assert_screen 'windows-screensaver', 3600;
send_key_until_needlematch 'windows-login', 'esc';
type_password;
send_key 'ret';
if ($is_firstboot) {
record_info('Windows firstboot', 'Starting Windows for the first time');
wait_still_screen stilltime => 60, timeout => 300;
# When starting Windows for the first time, several screens or pop-ups may appear
# in a different order. We'll try to handle them until the desktop is shown
assert_screen(['windows-edge-welcome', 'windows-desktop', 'windows-edge-decline', 'networks-popup-be-discoverable', 'windows-start-menu', 'windows-qemu-drivers', 'windows-setup-browser'], timeout => 120);
while (not match_has_tag('windows-desktop')) {
assert_and_click 'windows-edge-welcome' if (match_has_tag 'windows-edge-welcome');
assert_and_click 'windows-setup-browser' if (match_has_tag 'windows-setup-browser');
assert_and_click 'network-discover-yes' if (match_has_tag 'networks-popup-be-discoverable');
assert_and_click 'windows-edge-decline' if (match_has_tag 'windows-edge-decline');
assert_and_click 'windows-start-menu' if (match_has_tag 'windows-start-menu');
assert_and_click 'windows-qemu-drivers' if (match_has_tag 'windows-qemu-drivers');
wait_still_screen stilltime => 15, timeout => 60;
assert_screen(['windows-edge-welcome', 'windows-desktop', 'windows-edge-decline', 'networks-popup-be-discoverable', 'windows-start-menu', 'windows-qemu-drivers', 'windows-setup-browser'], timeout => 120);
}
# These commands disable notifications that Windows shows randomly and
# make our windows lose focus
$self->open_powershell_as_admin;
$self->run_in_powershell(cmd => 'reg add "HKLM\Software\Policies\Microsoft\Windows" /v Explorer');
$self->run_in_powershell(cmd => 'reg add "HKLM\Software\Policies\Microsoft\Windows\Explorer" /v DisableNotificationCenter /t REG_DWORD /d 1');
$self->run_in_powershell(cmd => 'reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\PushNotifications" /v ToastEnabled /t REG_DWORD /d 0');
record_info 'Port close', 'Closing serial port...';
$self->run_in_powershell(cmd => '$port.close()', code => sub { });
$self->run_in_powershell(cmd => 'exit', code => sub { });
} else {
record_info("Win boot", "Windows started properly");
assert_screen ['finish-setting', 'windows-desktop'], 240;
if (match_has_tag 'finish-setting') {
assert_and_click 'finish-setting';
}
}
}
sub windows_server_login_Administrator {
#Login windows Server as Administrator
send_key "ctrl-alt-delete";
assert_screen "windows_server_login", timeout => 60;
type_string "N0tS3cr3t@";
send_key "ret";
#some times server_manager windows slow to open when Openqa high load, fix waiting few seconds more...
assert_screen "wint_manage_server", timeout => 150;
}
sub test_flags {
return {fatal => 1};
}
sub post_fail_hook {
sleep 30;
save_screenshot;
}
sub install_wsl2_kernel {
my $self = shift;
my $ms_kernel_link = 'https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi';
$ms_kernel_link = 'https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_arm64.msi' if is_aarch64;
# Download the WSL kernel and install it
$self->run_in_powershell(
cmd => "Invoke-WebRequest -Uri $ms_kernel_link -O C:\\kernel.msi -UseBasicParsing",
timeout => 300
);
$self->run_in_powershell(
cmd => q{ii C:\\kernel.msi},
code => sub {
assert_and_click 'wsl2-install-kernel-start', timeout => 60;
assert_and_click 'wsl2-install-kernel-finished', timeout => 60;
}
);
$self->run_in_powershell(
cmd => q{wsl --set-default-version 2}
);
}
sub power_configuration {
my $self = shift;
# turn off hibernation and fast startup
$self->run_in_powershell(cmd =>
q{Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Power' -Name HiberbootEnabled -Value 0}
);
$self->run_in_powershell(cmd => 'powercfg /hibernate off');
# disable screen's fade to black
$self->run_in_powershell(cmd => 'powercfg -change -monitor-timeout-ac 0');
# adjust visual effects to best performance
$self->run_in_powershell(cmd =>
q{Set-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects' -Name VisualFXSetting -Value 2}
);
}
1;