-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
intercept.js
36 lines (30 loc) · 935 Bytes
/
intercept.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
/**
* in order to run this file make sure you have `webdriverio`
* installed using NPM before running it:
*
* $ npm install webdriverio
*
*/
import { remote } from 'webdriverio'
const browser = await remote({
capabilities: {
browserName: 'chrome'
}
})
await browser.url('https://v6.webdriver.io')
// switch to Puppeteer
const puppeteerBrowser = await browser.getPuppeteer()
const page = (await puppeteerBrowser.pages())[0]
await page.setRequestInterception(true)
page.on('request', interceptedRequest => {
if (interceptedRequest.url().endsWith('webdriverio.png')) {
return interceptedRequest.continue({
url: 'https://user-images.githubusercontent.com/10379601/29446482-04f7036a-841f-11e7-9872-91d1fc2ea683.png'
})
}
interceptedRequest.continue()
})
// continue with WebDriver commands
await browser.refresh()
await browser.pause(2000)
await browser.deleteSession()