Skip to content

Commit 0657c68

Browse files
author
ibizaman
committed
add playwright test for nextcloud
1 parent d13ed1c commit 0657c68

File tree

4 files changed

+53
-16
lines changed

4 files changed

+53
-16
lines changed

test/common.nix

+9-9
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@ in
153153
cfg = config.test.login;
154154
in {
155155
options.test.login = {
156-
usernameFieldLabel = mkOption {
156+
usernameFieldLabelRegex = mkOption {
157157
type = str;
158158
default = "username";
159159
};
160-
passwordFieldLabel = mkOption {
160+
passwordFieldLabelRegex = mkOption {
161161
type = str;
162162
default = "password";
163163
};
164-
loginButtonName = mkOption {
164+
loginButtonNameRegex = mkOption {
165165
type = str;
166166
default = "login";
167167
};
@@ -241,14 +241,14 @@ in
241241
page.goto(testCfg['startUrl'])
242242
243243
if u['username'] is not None:
244-
print(f"Filling field {testCfg['usernameFieldLabel']} with {u['username']}")
245-
page.get_by_label(testCfg['usernameFieldLabel']).fill(u['username'])
244+
print(f"Filling field {testCfg['usernameFieldLabelRegex']} with {u['username']}")
245+
page.get_by_label(re.compile(testCfg['usernameFieldLabelRegex'])).fill(u['username'])
246246
if u['password'] is not None:
247-
print(f"Filling field {testCfg['passwordFieldLabel']} with {u['password']}")
248-
page.get_by_label(testCfg['passwordFieldLabel']).fill(u['password'])
247+
print(f"Filling field {testCfg['passwordFieldLabelRegex']} with {u['password']}")
248+
page.get_by_label(re.compile(testCfg['passwordFieldLabelRegex'])).fill(u['password'])
249249
250-
print(f"Clicking button {testCfg['loginButtonName']}")
251-
page.get_by_role("button", name=testCfg['loginButtonName']).click()
250+
print(f"Clicking button {testCfg['loginButtonNameRegex']}")
251+
page.get_by_role("button", name=re.compile(testCfg['loginButtonNameRegex'])).click()
252252
253253
for line in u['nextPageExpect']:
254254
print(f"Running: {line}")

test/services/deluge.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ let
108108
};
109109

110110
test.login = {
111-
passwordFieldLabel = "Password";
112-
loginButtonName = "Login";
111+
passwordFieldLabelRegex = "Password";
112+
loginButtonNameRegex = "Login";
113113
testLoginWith = [
114114
{ password = "deluge"; nextPageExpect = [
115115
"expect(page.get_by_role('button', name='Login')).not_to_be_visible()"

test/services/forgejo.nix

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ let
8080

8181
test.login = {
8282
startUrl = "http://${config.test.fqdn}/user/login";
83-
usernameFieldLabel = "Username or email address";
84-
passwordFieldLabel = "Password";
85-
loginButtonName = "Sign In";
83+
usernameFieldLabelRegex = "Username or email address";
84+
passwordFieldLabelRegex = "Password";
85+
loginButtonNameRegex = "Sign In";
8686
testLoginWith = [
8787
{ username = "theadmin"; password = adminPassword + "oops"; nextPageExpect = [
8888
"expect(page.get_by_text('Username or password is incorrect.')).to_be_visible()"

test/services/nextcloud.nix

+39-2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ let
110110
};
111111

112112
basic = { config, ... }: {
113+
imports = [
114+
testLib.baseModule
115+
../../modules/services/nextcloud-server.nix
116+
];
117+
113118
test = {
114119
subdomain = "n";
115120
};
@@ -136,6 +141,35 @@ let
136141
};
137142
};
138143

144+
clientLogin = { config, ... }: {
145+
imports = [
146+
testLib.baseModule
147+
testLib.clientLoginModule
148+
];
149+
virtualisation.memorySize = 4096;
150+
151+
test = {
152+
subdomain = "n";
153+
};
154+
155+
test.login = {
156+
startUrl = "http://${config.test.fqdn}";
157+
usernameFieldLabelRegex = "[Uu]sername";
158+
passwordFieldLabelRegex = "^ *[Pp]assword";
159+
loginButtonNameRegex = "[Ll]og [Ii]n";
160+
testLoginWith = [
161+
{ username = adminUser; password = adminPass + "oops"; nextPageExpect = [
162+
"expect(page.get_by_text('Wrong username or password')).to_be_visible()"
163+
]; }
164+
{ username = adminUser; password = adminPass; nextPageExpect = [
165+
"expect(page.get_by_text('Wrong username or password')).not_to_be_visible()"
166+
"expect(page.get_by_role('button', name=re.compile('[Ll]og [Ii]n'))).not_to_be_visible()"
167+
"expect(page).to_have_title(re.compile('Dashboard'))"
168+
]; }
169+
];
170+
};
171+
};
172+
139173
https = { config, ...}: {
140174
shb.nextcloud = {
141175
ssl = config.shb.certs.certs.selfsigned.n;
@@ -234,10 +268,13 @@ in
234268
basic = pkgs.testers.runNixOSTest {
235269
name = "nextcloud_basic";
236270

271+
nodes.client = {
272+
imports = [
273+
clientLogin
274+
];
275+
};
237276
nodes.server = {
238277
imports = [
239-
testLib.baseModule
240-
../../modules/services/nextcloud-server.nix
241278
basic
242279
];
243280
};

0 commit comments

Comments
 (0)