summaryrefslogtreecommitdiff
path: root/src/handlers/launchUserSession.js
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-11-14 17:21:21 +0300
committereug-vs <eug-vs@keemail.me>2020-11-14 17:21:21 +0300
commitae94313667b3abe257c0767439c6d3986ba0fde6 (patch)
tree212e5082cda719c1d26625b251d60452aea275ab /src/handlers/launchUserSession.js
parent4f0561acef93970f69b0ddda1cea132532355e7d (diff)
downloadbsu-fantom-ae94313667b3abe257c0767439c6d3986ba0fde6.tar.gz
feat: launch session on schedule for many users
Diffstat (limited to 'src/handlers/launchUserSession.js')
-rw-r--r--src/handlers/launchUserSession.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/handlers/launchUserSession.js b/src/handlers/launchUserSession.js
new file mode 100644
index 0000000..58dde62
--- /dev/null
+++ b/src/handlers/launchUserSession.js
@@ -0,0 +1,25 @@
+const puppeteer = require('puppeteer');
+const { clickElementBySelector } = require('./utils.js');
+
+const { EDUFPMI_URL } = process.env;
+
+const launchUserSession = (user, headless = true) => puppeteer.launch({ headless })
+ .then(async browser => {
+ const { username, password } = user;
+ const page = await browser.newPage();
+
+ // Login
+ await page.goto(EDUFPMI_URL, { waitUntil: 'domcontentloaded' });
+ await page.type('input#username', username);
+ await page.type('input#password', password);
+ await Promise.all([
+ clickElementBySelector(page, 'button#loginbtn'),
+ page.waitForNavigation()
+ ]);
+ console.log(`Logged in as ${username}`);
+
+ return browser;
+ });
+
+module.exports = launchUserSession;
+