require('dotenv').config(); const puppeteer = require('puppeteer'); const attendConference = require('./attendConference.js'); const clickAndWait = (page, selector) => Promise.all([ page.click(selector), page.waitForNavigation(), ]); const { EDUFPMI_URL, EDUFPMI_USERNAME, EDUFPMI_PASSWORD, COURSE_URL } = process.env; puppeteer.launch({ headless: false }) .then(async browser => { const page = await browser.newPage(); // Login await page.goto(EDUFPMI_URL, { waitUntil: 'networkidle0' }); await page.type('input#username', EDUFPMI_USERNAME); await page.type('input#password', EDUFPMI_PASSWORD); await clickAndWait(page, 'button#loginbtn'); console.log(`Logged in as ${EDUFPMI_USERNAME}`); // Find the course await page.goto(COURSE_URL, { waitUntil: 'networkidle0' }); await clickAndWait(page, 'li.bigbluebuttonbn'); // Launch a meeting const conferencePagePromise = new Promise(resolve => browser.on( 'targetcreated', target => resolve(target.page()) )); await page.click('input#join_button_input'); const conferencePage = await conferencePagePromise; await attendConference(conferencePage); // Fill up the attendance await page.goBack(); await clickAndWait(page, 'li.attendance'); }) .catch(e => console.log(e));