-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathnetwork_commands.spec.js
81 lines (61 loc) · 2.74 KB
/
network_commands.spec.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 assert = require("assert")
const firefox = require('selenium-webdriver/firefox')
const Network = require('selenium-webdriver/bidi/network')
const {until, By, Builder} = require('selenium-webdriver')
const {AddInterceptParameters} = require("selenium-webdriver/bidi/addInterceptParameters");
const {InterceptPhase} = require("selenium-webdriver/bidi/interceptPhase");
describe('Network commands', function () {
let driver
let network
beforeEach(async function () {
driver = new Builder()
.forBrowser('firefox')
.setFirefoxOptions(new firefox.Options().enableBidi())
.build()
network = await Network(driver)
})
afterEach(async function () {
await network.close()
await driver.quit()
})
xit('can add intercept', async function () {
const intercept = await network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT))
assert.notEqual(intercept, null)
})
xit('can remove intercept', async function () {
const network = await Network(driver)
const intercept = await network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT))
assert.notEqual(intercept, null)
await network.removeIntercept(intercept)
})
xit('can continue with auth credentials ', async function () {
await network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED))
await network.authRequired(async (event) => {
await network.continueWithAuth(event.request.request, 'admin','admin')
})
await driver.get('https://the-internet.herokuapp.com/basic_auth')
const successMessage = 'Congratulations! You must have the proper credentials.'
let elementMessage = await driver.findElement(By.tagName('p')).getText()
assert.equal(elementMessage, successMessage)
})
xit('can continue without auth credentials ', async function () {
await network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED))
await network.authRequired(async (event) => {
await network.continueWithAuthNoCredentials(event.request.request)
})
await driver.get('https://the-internet.herokuapp.com/basic_auth')
const alert = await driver.wait(until.alertIsPresent())
await alert.dismiss()
let source = await driver.getPageSource()
assert.equal(source.includes('Not authorized'), true)
})
xit('can cancel auth ', async function () {
await network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED))
await network.authRequired(async (event) => {
await network.cancelAuth(event.request.request)
})
await driver.get('https://the-internet.herokuapp.com/basic_auth')
let source = await driver.getPageSource()
assert.equal(source.includes('Not authorized'), true)
})
})