summaryrefslogtreecommitdiff
path: root/src/handlers/launchUserSession.js
blob: 5e490e0b2441b8a8abdb4c9cc51755bfd5d8337d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const { clickElementBySelector } = require('./utils.js');

const { EDUFPMI_URL } = process.env;

const launchUserSession = async (user, 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 page;
};

module.exports = launchUserSession;