-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuppeteerScript.js
47 lines (41 loc) · 1.16 KB
/
puppeteerScript.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
/**
* @param {puppeteer.Browser} browser
* @param {{url: string, options: LHCI.CollectCommand.Options}} context
*/
let counter = 1;
const selector = {
class(attribute, className) {
return `${attribute}[class='${className}']`
},
type(attribute, value) {
return `${attribute}[type='${value}']`
},
id(value) {
return `#${value}`
}
}
async function doLogin(page) {
const loginUrl = 'https://localhost:7003/Identity/Account/Login'
await page.waitForTimeout(2000)
await page.goto(loginUrl);
await page.type(selector.id('Input_Email'), 'demo@demo.com');
await page.type(selector.id('Input_Password'), 'P@$$w0rd');
console.log(`Entered user credentials`)
await page.click(selector.type('button', 'submit'));
console.log(`Login is successful`)
}
async function setup(browser, context) {
// launch browser for LHCI
const page = await browser.newPage();
await page.setCacheEnabled(true)
if (counter === 1) {
await doLogin(page)
}
else {
await page.goto(context.url);
}
// close session for next run
await page.close();
counter++
}
module.exports = setup