-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.js
81 lines (74 loc) · 2.02 KB
/
session.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const { chromium } = require('playwright')
async function launchChromium () {
return await chromium.launch({
headless: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--ignore-certificate-errors',
'--unsafely-treat-insecure-origin-as-secure=https://localhost:4200/',
'--disable-notifications'
]
})
}
async function loginToBonnie (page) {
if (!page) {
throw new Error('page is missing')
}
await page.waitForSelector('.btn-login')
return await page.click('.btn-login')
}
async function loginToBonnieOkta (page, username, password) {
if (!username || !password) {
throw new Error('Username or Password missing for login')
}
await page.waitForSelector('#input28')
await page.fill('#input28', username)
await page.fill('#input36', password)
//await page.click('#tandc')
return await page.click('[class="button button-primary"]')
}
async function getLocalStorageData (page) {
return await page.evaluate(() => {
return Object.keys(localStorage).reduce(
(items, curr) => ({
...items,
[curr]: localStorage.getItem(curr)
}),
{}
)
})
}
async function getSessionStorageData (page) {
return page.evaluate(() => {
return Object.keys(sessionStorage).reduce(
(items, curr) => ({
...items,
[curr]: sessionStorage.getItem(curr)
}),
{}
)
})
}
module.exports = {
GetSession: async function (username, password, url) {
const browser = await launchChromium()
const context = await browser.newContext()
const page = await context.newPage()
await page.goto(url)
await loginToBonnie(page)
await loginToBonnieOkta(page, username, password)
await page.waitForNavigation({
waitUntil: 'networkidle',
timeout: 200000
})
const cookies = await context.cookies()
const lsd = await getLocalStorageData(page)
const ssd = await getSessionStorageData(page)
browser.close()
return {
cookies, lsd, ssd
}
}
}