forked from Contrast-Security-OSS/demo-netflicks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise.js
186 lines (137 loc) · 6.17 KB
/
exercise.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
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
const puppeteer = require('puppeteer');
(async () => {
if (!process.env.BASEURL) {
console.log('Please specify a base url. E.g. `BASEURL=http://example.org node exercise.js`');
} else {
var browser;
if (process.env.DEBUG) {
browser = await puppeteer.launch({
headless: false,
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
});
} else {
browser = await puppeteer.launch();
}
function delay(time) {
return new Promise(function(resolve) {
setTimeout(resolve, time)
});
}
const page = await browser.newPage()
await page.setViewport({ width: 1366, height: 768});
page.setDefaultNavigationTimeout(120000) //2 mins
const navigationPromise = page.waitForNavigation()
const pageOptions = {waitUntil: 'domcontentloaded'}
const selectorOptions = {"timeout": 120000} //2 mins
try {
//Add error handling here in case the endpoint is not ready.
await page.goto(process.env.BASEURL, pageOptions);
} catch (error) {
console.log(error);
browser.close();
}
//Log in
console.log('Logging in');
await page.goto(process.env.BASEURL + '/Movie/ViewAll', pageOptions);
await page.waitForSelector('input#Email', selectorOptions);
await page.type('input#Email', 'admin@dotnetflicks.com');
await page.waitForSelector('input#Password', selectorOptions)
await page.type('input#Password', 'p@ssWORD471')
await page.waitForSelector('form button', selectorOptions)
await page.click('form button')
await navigationPromise
await delay(5000);
//Browse Movies
console.log('Browse movies');
await page.goto(process.env.BASEURL + '/Movie/ViewAll', pageOptions);
//Movies for user
console.log('Movies for user');
await page.goto(process.env.BASEURL + '/Movie/ViewAllForUser', pageOptions);
//Movies admin
console.log('Movies search');
await page.goto(process.env.BASEURL + '/Movie', pageOptions);
await page.waitForSelector('input[name="Search"]', selectorOptions);
await page.type('input[name="Search"]', 'Coco');
await (await page.$('input[name="Search"]')).press('Enter');
//Edit movie
console.log('Edit movie');
await page.goto(process.env.BASEURL + '/Movie/Edit/185', pageOptions);
await page.waitForSelector('.body-content form button[type="submit"]');
await page.click('.body-content form button[type="submit"]');
await navigationPromise
//People
console.log('People');
await page.goto(process.env.BASEURL + '/Person', pageOptions);
//Edit person
console.log('Edit person');
await page.goto(process.env.BASEURL + '/Person/Edit/1215657', pageOptions);
await page.waitForSelector('#Biography', selectorOptions);
await page.type('#Biography', 'Bloody nice chap');
await page.waitForSelector('.body-content form button[type="submit"]');
await page.click('.body-content form button[type="submit"]');
await navigationPromise
//Genre
console.log('Genres');
await page.goto(process.env.BASEURL + '/Genre', pageOptions);
//Add genre
console.log('Add genre');
await page.goto(process.env.BASEURL + '/Genre/Edit', pageOptions);
await page.waitForSelector('#Name', selectorOptions);
await page.type('#Name', 'Snuff');
await page.waitForSelector('.body-content form button[type="submit"]');
await page.click('.body-content form button[type="submit"]');
//Department
console.log('Departments');
await page.goto(process.env.BASEURL + '/Department', pageOptions);
//Add Department
console.log('Add Department');
await page.goto(process.env.BASEURL + '/Department/Edit', pageOptions);
await page.waitForSelector('#Name', selectorOptions);
await page.type('#Name', 'Rider');
await page.waitForSelector('.body-content form button[type="submit"]');
await page.click('.body-content form button[type="submit"]');
await navigationPromise
//Profile
console.log('Profile');
await page.goto(process.env.BASEURL + '/Manage/Index', pageOptions);
await page.waitForSelector('#PhoneNumber', selectorOptions);
await page.type('#PhoneNumber', '0870277277');
await page.waitForSelector('.body-content form button[type="submit"]');
await page.click('.body-content form button[type="submit"]');
await navigationPromise
//Change Password
console.log('Change Password');
await page.goto(process.env.BASEURL + '/Manage/ChangePassword', pageOptions);
await page.waitForSelector('#OldPassword', selectorOptions);
await page.type('#OldPassword', 'p@ssWORD471');
await page.waitForSelector('#NewPassword', selectorOptions);
await page.type('#NewPassword', 'p@ssWORD471');
await page.waitForSelector('#ConfirmPassword', selectorOptions);
await page.type('#ConfirmPassword', 'p@ssWORD471');
await page.waitForSelector('.body-content form button[type="submit"]');
await page.click('.body-content form button[type="submit"]');
await navigationPromise
//Forgot Password
console.log('Forgot Password');
await page.goto(process.env.BASEURL + '/Account/ForgotPassword', pageOptions);
await page.waitForSelector('#Email', selectorOptions);
await page.type('#Email', 'admin@dotnetflicks.com');
await page.waitForSelector('.body-content form button[type="submit"]');
await page.click('.body-content form button[type="submit"]');
await navigationPromise
//Register User
console.log('Register User');
await page.goto(process.env.BASEURL + '/Account/Register', pageOptions);
await page.waitForSelector('#Email', selectorOptions);
await page.type('#Email', Math.random().toString(36).substring(7) + '@dotnetflicks.com');
await page.waitForSelector('#Password', selectorOptions);
await page.type('#Password', 'p@ssWORD471');
await page.waitForSelector('#ConfirmPassword', selectorOptions);
await page.type('#ConfirmPassword', 'p@ssWORD471');
await page.waitForSelector('.body-content form button[type="submit"]');
await page.click('.body-content form button[type="submit"]');
await navigationPromise
//Quit
if (!process.env.DEBUG) {await browser.close()}
}
})()