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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
require('dotenv').config();
const puppeteer = require('puppeteer');
const clickElementByXPath = (page, xPath) => page
.waitForXPath(xPath)
.then(item => item.click());
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 moodlePagePromise = new Promise(resolve => browser.on(
'targetcreated',
target => resolve(target.page())
));
await page.click('input#join_button_input');
const moodlePage = await moodlePagePromise;
// Fill up the attendance
await page.goBack();
await clickAndWait(page, 'li.attendance');
// Join as "Listen only"
await clickElementByXPath(moodlePage, '//span[contains(text(),"Listen only")]');
console.log('Joined the meeting');
// Wait 5 seconds
await new Promise(resolve => setTimeout(resolve, 5000));
console.log('Time to leave!')
// Leave audio and close the browser
await clickElementByXPath(moodlePage, '//button[contains(@aria-label,"Leave audio")]');
await new Promise(resolve => setTimeout(resolve, 1500));
await browser.close();
console.log('Left the meeting');
})
.catch(e => console.log(e));
|