-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.js
117 lines (110 loc) · 3.88 KB
/
users.js
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
var faker = require('faker');
const elements = {
addUserBtn:
"#users-container > div > div.boilerplate-app.personaBar-mainContainer > div > div > div.dnn-persona-bar-page-header > div > button",
addUserPanel: "div.new-user-box",
firstNameTextBox: "div.new-user-box input[type='text'][tabindex='1']",
lastNameTextBox: "div.new-user-box input[type='text'][tabindex='2']",
userNameTextBox: "div.new-user-box input[type='text'][tabindex='3']",
emailTextBox: "div.new-user-box input[type='text'][tabindex='4']",
passwordTextBox: "div.new-user-box input[type='password'][tabindex='7']",
passwordConfirmTextBox: "div.new-user-box input[type='password'][tabindex='8']",
switches: "div.new-user-box .dnn-switch",
emailNotificationCheckbox: "div.email-notification-line input",
saveNewUserBtn: "div.new-user-box button[role='primary']",
searchUserBox: "div.users-filter-container input[type='search']",
usersList: "div.persona-bar-page-body div.collapsible-component-users"
};
exports.addUser = async function (
page,
firstName,
lastName,
userName,
email,
authorized,
randomPw,
password,
sendEmail
) {
const frames = await page.frames();
const personaBar = frames.find(f => f.name() === "personaBar-iframe");
if (personaBar) {
await personaBar.waitForSelector(elements.addUserBtn);
await personaBar.click(elements.addUserBtn);
await personaBar.waitForSelector(elements.addUserPanel);
await personaBar.click(elements.firstNameTextBox);
await page.keyboard.type(firstName);
await personaBar.click(elements.lastNameTextBox);
await page.keyboard.type(lastName);
await personaBar.click(elements.userNameTextBox);
await page.keyboard.type(userName);
await personaBar.click(elements.emailTextBox);
await page.keyboard.type(email);
var switches = await personaBar.$$(elements.switches);
if (switches && switches.length == 2) {
if (!authorized) {
await switches[0].click();
}
if (randomPw) {
await switches[1].click();
} else {
await personaBar.click(elements.passwordTextBox);
await page.keyboard.type(password);
await personaBar.click(elements.passwordConfirmTextBox);
await page.keyboard.type(password);
}
}
if (sendEmail) {
await personaBar.click(elements.emailNotificationCheckbox);
}
await personaBar.click(elements.saveNewUserBtn);
await page.waitFor(5000); // wait for popup to fade
}
};
exports.addRandomUsers = async function (page, nrUsers, password) {
for (var i = 0; i < nrUsers; i++) {
await this.addRandomUser(page, true, password);
}
};
exports.addRandomUser = async function (page, authorized, password) {
var newUser = this.getRandomUserName();
await this.addUser(
page,
newUser.firstName,
newUser.lastName,
newUser.userName,
newUser.email,
authorized,
password === null,
password,
false
);
};
exports.getRandomUser = function () {
var res = {
firstName: faker.name.firstName(),
lastName: faker.name.lastName()
}
res.email = res.firstName.toLowerCase() + "@" + res.lastName.toLowerCase() + ".name";
res.userName = res.firstName.toLowerCase().substring(0, 1) +
res.lastName.toLowerCase() +
Math.floor(Math.random() * 100).toString();
res.displayName = res.firstName + " " + res.lastName;
return res;
};
exports.findUser = async function (page, userName) {
const frames = await page.frames();
const personaBar = frames.find(f => f.name() === "personaBar-iframe");
if (personaBar) {
await personaBar.click(elements.searchUserBox);
await page.keyboard.type(userName);
const uname = await personaBar.$eval(elements.usersList + " div.user-names p", el => el.textContent);
console.log(uname);
return uname;
}
}
var _getName = function (random, whichList) {
var list = names[whichList];
var idx = (random * list.length) >>> 0;
return list[idx];
};