blob: 58dde622976363539e9875b61541105e87ddec8d (
plain)
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
|
const puppeteer = require('puppeteer');
const { clickElementBySelector } = require('./utils.js');
const { EDUFPMI_URL } = process.env;
const launchUserSession = (user, headless = true) => puppeteer.launch({ headless })
.then(async browser => {
const { username, password } = user;
const page = await browser.newPage();
// Login
await page.goto(EDUFPMI_URL, { waitUntil: 'domcontentloaded' });
await page.type('input#username', username);
await page.type('input#password', password);
await Promise.all([
clickElementBySelector(page, 'button#loginbtn'),
page.waitForNavigation()
]);
console.log(`Logged in as ${username}`);
return browser;
});
module.exports = launchUserSession;
|