diff options
author | eug-vs <eug-vs@keemail.me> | 2020-11-11 00:28:10 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-11-11 00:28:10 +0300 |
commit | 937dff7628820b54e7963f283618e639340e67ee (patch) | |
tree | ede1f3441b76a66be6bd7ea24170866d43da928a | |
parent | 4ac357c935fdcf07ad46301572a703f2fece56d7 (diff) | |
download | bsu-fantom-937dff7628820b54e7963f283618e639340e67ee.tar.gz |
feat: await navigation after clicks
-rw-r--r-- | src/index.js | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/index.js b/src/index.js index 507085a..9dafdb4 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,10 @@ 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, @@ -14,7 +18,7 @@ const { COURSE_URL } = process.env; -puppeteer.launch({ headless: true }) +puppeteer.launch({ headless: false }) .then(async browser => { const page = await browser.newPage(); @@ -22,12 +26,14 @@ puppeteer.launch({ headless: true }) await page.goto(EDUFPMI_URL, { waitUntil: 'networkidle0' }); await page.type('input#username', EDUFPMI_USERNAME); await page.type('input#password', EDUFPMI_PASSWORD); - await page.click('button#loginbtn'); - await page.waitForResponse(response => response.url().includes('index.php')); + await clickAndWait(page, 'button#loginbtn'); console.log(`Logged in as ${EDUFPMI_USERNAME}`); - // Launch a meeting + // 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()) @@ -35,6 +41,10 @@ puppeteer.launch({ headless: true }) 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'); |