-
Notifications
You must be signed in to change notification settings - Fork 1
/
1296.js
56 lines (46 loc) · 1.37 KB
/
1296.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
const Nightmare = require('nightmare')
const assert = require('assert')
main().catch(console.error)
async function main() {
assert(process.env.USER, 'missing USER env')
assert(process.env.PASS, 'missing PASS env')
CookieFlusher(Nightmare)
const nightmare = Nightmare({
show: true,
webPreferences: {
partition: 'persist:nightmare8'
},
paths: {
userData: process.cwd()
}
})
// console.log(await nightmare.engineVersions())
await nightmare.goto('https://github.com/segmentio/nightmare')
await nightmare
.click(
'body > div.position-relative.js-header-wrapper > header > div > div.HeaderMenu.HeaderMenu--bright.d-flex.flex-justify-between.flex-auto > div > span > div > a:nth-child(1)'
)
.type('#login_field', process.env.USER)
.type('#password', process.env.PASS)
.click(
'#login > form > div.auth-form-body.mt-3 > input.btn.btn-primary.btn-block'
)
.wait('#user-links')
await nightmare.flushCookies()
await nightmare.end()
}
// try to flush the session data
function CookieFlusher(Nightmare) {
Nightmare.action(
'flushCookies',
(name, options, parent, win, renderer, done) => {
parent.respondTo('flushCookies', done => {
win.webContents.session.cookies.flushStore(done)
})
done()
},
function(done) {
this.child.call('flushCookies', done)
}
)
}