summaryrefslogtreecommitdiff
path: root/src/index.js
blob: 5345587a8fb54a715b7197f1c6438ba3185461d0 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require('dotenv').config();
const puppeteer = require('puppeteer');
const attendConference = require('./attendConference.js');
const { clickElementBySelector } = require('./utils.js');

const {
  EDUFPMI_URL,
  EDUFPMI_USERNAME,
  EDUFPMI_PASSWORD,
  COURSE_URL
} = process.env;

puppeteer.launch({ headless: true })
  .then(async browser => {
    const page = await browser.newPage();
    
    // Login
    await page.goto(EDUFPMI_URL, { waitUntil: 'domcontentloaded' });
    await page.type('input#username', EDUFPMI_USERNAME);
    await page.type('input#password', EDUFPMI_PASSWORD);
    await Promise.all([
      clickElementBySelector(page, 'button#loginbtn'),
      page.waitForNavigation()
    ]);
    console.log(`Logged in as ${EDUFPMI_USERNAME}`);

    // Find the course
    await page.goto(COURSE_URL);
    await Promise.all([
      clickElementBySelector(page, 'li.bigbluebuttonbn'),
      page.waitForNavigation() // Wait until the next page loads
    ]);

    // Launch a meeting
    const conferencePagePromise = new Promise(resolve => browser.on(
      'targetcreated',
      target => resolve(target.page())
    ));
    await clickElementBySelector(page, 'input#join_button_input');
    const conferencePage = await conferencePagePromise;
    await attendConference(conferencePage);

    // Fill up the attendance
    await page.goBack();
    await clickElementBySelector(page, 'li.attendance');
  })
  .catch(e => console.log(e));