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;