diff options
author | eug-vs <eug-vs@keemail.me> | 2020-11-11 00:47:40 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-11-11 00:47:40 +0300 |
commit | a52bf99bbf2d394685f92aa13b5bff438ff8ef0a (patch) | |
tree | 929c5c4117527fe007421d308cab5d1c3047b34a | |
parent | 937dff7628820b54e7963f283618e639340e67ee (diff) | |
download | bsu-fantom-a52bf99bbf2d394685f92aa13b5bff438ff8ef0a.tar.gz |
refactor: move attendConference() to separate file
-rw-r--r-- | src/attendConference.js | 21 | ||||
-rw-r--r-- | src/index.js | 24 |
2 files changed, 25 insertions, 20 deletions
diff --git a/src/attendConference.js b/src/attendConference.js new file mode 100644 index 0000000..b7f744f --- /dev/null +++ b/src/attendConference.js @@ -0,0 +1,21 @@ +const clickElementByXPath = (page, xPath) => page + .waitForXPath(xPath) + .then(item => item.click()); + +const attendConference = async page => { + // Join as "Listen only" + await clickElementByXPath(page, '//span[contains(text(),"Listen only")]'); + console.log('Joined the conference'); + + // Wait 5 seconds + await page.waitForTimeout(5000); + console.log('Time to leave!') + + // Leave audio and close the tab + await clickElementByXPath(page, '//button[contains(@aria-label,"Leave audio")]'); + await page.waitForTimeout(1500); + await page.close(); + console.log('Left the conference'); +}; + +module.exports = attendConference; diff --git a/src/index.js b/src/index.js index 9dafdb4..1432923 100644 --- a/src/index.js +++ b/src/index.js @@ -1,11 +1,8 @@ require('dotenv').config(); const puppeteer = require('puppeteer'); +const attendConference = require('./attendConference.js'); -const clickElementByXPath = (page, xPath) => page - .waitForXPath(xPath) - .then(item => item.click()); - const clickAndWait = (page, selector) => Promise.all([ page.click(selector), page.waitForNavigation(), @@ -34,30 +31,17 @@ puppeteer.launch({ headless: false }) await clickAndWait(page, 'li.bigbluebuttonbn'); // Launch a meeting - const moodlePagePromise = new Promise(resolve => browser.on( + const conferencePagePromise = new Promise(resolve => browser.on( 'targetcreated', target => resolve(target.page()) )); await page.click('input#join_button_input'); - const moodlePage = await moodlePagePromise; + const conferencePage = await conferencePagePromise; + await attendConference(conferencePage); // 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)); |