Skip to content

Commit

Permalink
Remove dependency to devtools (#4563)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashohn authored Nov 14, 2024
1 parent df82454 commit b343cd2
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 1,833 deletions.
365 changes: 107 additions & 258 deletions docs/helpers/WebDriver.md

Large diffs are not rendered by default.

183 changes: 1 addition & 182 deletions lib/helper/WebDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const webRoot = 'body'
* @prop {object} [timeouts] [WebDriver timeouts](http://webdriver.io/docs/timeouts.html) defined as hash.
* @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
* @prop {string} [logLevel=silent] - level of logging verbosity. Default: silent. Options: trace | debug | info | warn | error | silent. More info: https://webdriver.io/docs/configuration/#loglevel
* @prop {boolean} [devtoolsProtocol=false] - enable devtools protocol. Default: false. More info: https://webdriver.io/docs/automationProtocols/#devtools-protocol.
*/
const config = {}

Expand Down Expand Up @@ -180,7 +179,6 @@ const config = {}
* WebDriver : {
* url: "http://localhost",
* browser: "chrome",
* devtoolsProtocol: true,
* desiredCapabilities: {
* chromeOptions: {
* args: [ "--headless", "--disable-gpu", "--no-sandbox" ]
Expand Down Expand Up @@ -614,11 +612,6 @@ class WebDriver extends Helper {
delete this.options.capabilities.hostname
delete this.options.capabilities.port
delete this.options.capabilities.path
if (this.options.devtoolsProtocol) {
if (!['chrome', 'chromium'].includes(this.options.browser.toLowerCase()))
throw Error('The devtools protocol is only working with Chrome or Chromium')
this.options.automationProtocol = 'devtools'
}
this.browser = await webdriverio.remote(this.options)
}
} catch (err) {
Expand Down Expand Up @@ -649,11 +642,6 @@ class WebDriver extends Helper {
this.browser.capabilities.platformName = this.browser.capabilities.platformName.toLowerCase()
}

if (this.options.automationProtocol) {
this.puppeteerBrowser = await this.browser.getPuppeteer()
this.page = (await this.puppeteerBrowser.pages())[0]
}

return this.browser
}

Expand Down Expand Up @@ -1143,10 +1131,6 @@ class WebDriver extends Helper {
assertElementExists(res, field, 'Field')
const elem = usingFirstElement(res)
highlightActiveElement.call(this, elem)
if (this.options.automationProtocol) {
const curentValue = await elem.getValue()
return elem.setValue(curentValue + value.toString())
}
return elem.addValue(value.toString())
}

Expand All @@ -1159,9 +1143,6 @@ class WebDriver extends Helper {
assertElementExists(res, field, 'Field')
const elem = usingFirstElement(res)
highlightActiveElement.call(this, elem)
if (this.options.automationProtocol) {
return elem.setValue('')
}
return elem.clearValue(getElementId(elem))
}

Expand Down Expand Up @@ -1231,7 +1212,7 @@ class WebDriver extends Helper {
const el = usingFirstElement(res)

// Remote Upload (when running Selenium Server)
if (this.options.remoteFileUpload && !this.options.automationProtocol) {
if (this.options.remoteFileUpload) {
try {
this.debugSection('File', 'Uploading file to remote server')
file = await this.browser.uploadFile(file)
Expand Down Expand Up @@ -2593,9 +2574,6 @@ class WebDriver extends Helper {
async switchTo(locator) {
this.browser.isInsideFrame = true
if (Number.isInteger(locator)) {
if (this.options.automationProtocol) {
return this.browser.switchToFrame(locator + 1)
}
return this.browser.switchToFrame(locator)
}
if (!locator) {
Expand Down Expand Up @@ -2734,44 +2712,6 @@ class WebDriver extends Helper {
return this.executeScript(getScrollPosition)
}

/**
* This method is **deprecated**.
*
*
* {{> setGeoLocation }}
*/
async setGeoLocation(latitude, longitude) {
if (!this.options.automationProtocol) {
console.log(`setGeoLocation deprecated:
* This command is deprecated due to using deprecated JSON Wire Protocol command. More info: https://webdriver.io/docs/api/jsonwp/#setgeolocation
* Switch to devtools protocol to use this command by setting devtoolsProtocol: true in the configuration`)
return
}
this.geoLocation = { latitude, longitude }

await this.browser.call(async () => {
const pages = await this.puppeteerBrowser.pages()
await pages[0].setGeolocation({ latitude, longitude })
})
}

/**
* This method is **deprecated**.
*
* {{> grabGeoLocation }}
*
*/
async grabGeoLocation() {
if (!this.options.automationProtocol) {
console.log(`grabGeoLocation deprecated:
* This command is deprecated due to using deprecated JSON Wire Protocol command. More info: https://webdriver.io/docs/api/jsonwp/#getgeolocation
* Switch to devtools protocol to use this command by setting devtoolsProtocol: true in the configuration`)
return
}
if (!this.geoLocation) return 'No GeoLocation is set!'
return this.geoLocation
}

/**
* {{> grabElementBoundingRect }}
*/
Expand Down Expand Up @@ -2810,127 +2750,6 @@ class WebDriver extends Helper {
runInWeb(fn) {
return fn()
}

/**
*
* _Note:_ Only works when devtoolsProtocol is enabled.
*
* {{> flushNetworkTraffics }}
*/
flushNetworkTraffics() {
if (!this.options.automationProtocol) {
console.log(
'* Switch to devtools protocol to use this command by setting devtoolsProtocol: true in the configuration',
)
return
}
this.requests = []
}

/**
*
* _Note:_ Only works when devtoolsProtocol is enabled.
*
* {{> stopRecordingTraffic }}
*/
stopRecordingTraffic() {
if (!this.options.automationProtocol) {
console.log(
'* Switch to devtools protocol to use this command by setting devtoolsProtocol: true in the configuration',
)
return
}
this.page.removeAllListeners('request')
this.recording = false
}

/**
*
* _Note:_ Only works when devtoolsProtocol is enabled.
*
* {{> startRecordingTraffic }}
*
*/
async startRecordingTraffic() {
if (!this.options.automationProtocol) {
console.log(
'* Switch to devtools protocol to use this command by setting devtoolsProtocol: true in the configuration',
)
return
}
this.flushNetworkTraffics()
this.recording = true
this.recordedAtLeastOnce = true

await this.page.setRequestInterception(true)

this.page.on('request', (request) => {
const information = {
url: request.url(),
method: request.method(),
requestHeaders: request.headers(),
requestPostData: request.postData(),
response: request.response(),
}

this.debugSection('REQUEST: ', JSON.stringify(information))

if (typeof information.requestPostData === 'object') {
information.requestPostData = JSON.parse(information.requestPostData)
}
request.continue()
this.requests.push(information)
})
}

/**
*
* _Note:_ Only works when devtoolsProtocol is enabled.
*
* {{> grabRecordedNetworkTraffics }}
*/
async grabRecordedNetworkTraffics() {
if (!this.options.automationProtocol) {
console.log(
'* Switch to devtools protocol to use this command by setting devtoolsProtocol: true in the configuration',
)
return
}
return grabRecordedNetworkTraffics.call(this)
}

/**
*
* _Note:_ Only works when devtoolsProtocol is enabled.
*
* {{> seeTraffic }}
*/
async seeTraffic({ name, url, parameters, requestPostData, timeout = 10 }) {
if (!this.options.automationProtocol) {
console.log(
'* Switch to devtools protocol to use this command by setting devtoolsProtocol: true in the configuration',
)
return
}
await seeTraffic.call(this, ...arguments)
}

/**
*
* _Note:_ Only works when devtoolsProtocol is enabled.
*
* {{> dontSeeTraffic }}
*
*/
dontSeeTraffic({ name, url }) {
if (!this.options.automationProtocol) {
console.log(
'* Switch to devtools protocol to use this command by setting devtoolsProtocol: true in the configuration',
)
return
}
dontSeeTraffic.call(this, ...arguments)
}
}

async function proceedSee(assertType, text, context, strict = false) {
Expand Down
3 changes: 0 additions & 3 deletions lib/plugin/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ module.exports = function (config) {

const helper = helpers[helperName]

if (helperName === 'WebDriver' && !helper.config.devtoolsProtocol)
throw Error('Coverage is currently supporting the WebDriver running with Devtools protocol.')

const v8Helper = v8CoverageHelpers[helperName]

const coverageOptions = {
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"test:unit:webbapi:puppeteer": "mocha test/helper/Puppeteer_test.js",
"test:unit:webbapi:webDriver": "mocha test/helper/WebDriver_test.js",
"test:unit:webbapi:webDriver:noSeleniumServer": "mocha test/helper/WebDriver.noSeleniumServer_test.js",
"test:unit:webbapi:webDriver:devtools": "mocha test/helper/WebDriver_devtools_test.js --exit",
"test:unit:webbapi:testCafe": "mocha test/helper/TestCafe_test.js",
"test:unit:expect": "mocha test/helper/Expect_test.js",
"test:plugin": "mocha test/plugin/plugin_test.js",
Expand Down Expand Up @@ -90,7 +89,6 @@
"cross-spawn": "7.0.5",
"css-to-xpath": "0.1.0",
"csstoxpath": "1.6.0",
"devtools": "8.40.2",
"envinfo": "7.14.0",
"escape-string-regexp": "4.0.0",
"figures": "3.2.0",
Expand Down Expand Up @@ -167,7 +165,7 @@
"typedoc-plugin-markdown": "4.2.10",
"typescript": "5.6.3",
"wdio-docker-service": "1.5.0",
"webdriverio": "8.39.1",
"webdriverio": "8.40.6",
"xml2js": "0.6.2",
"xpath": "0.0.34"
},
Expand Down
49 changes: 0 additions & 49 deletions test/acceptance/codecept.WebDriver.devtools.coverage.js

This file was deleted.

42 changes: 0 additions & 42 deletions test/acceptance/codecept.WebDriver.devtools.js

This file was deleted.

10 changes: 0 additions & 10 deletions test/helper/WebDriver.noSeleniumServer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1204,16 +1204,6 @@ describe('WebDriver - No Selenium server started', function () {
})
})

describe('GeoLocation', () => {
// deprecated JSON Wire method commands
it.skip('should set the geoLocation', async () => {
await wd.setGeoLocation(37.4043, -122.0748)
const geoLocation = await wd.grabGeoLocation()
assert.equal(geoLocation.latitude, 37.4043, 'The latitude is not properly set')
assert.equal(geoLocation.longitude, -122.0748, 'The longitude is not properly set')
})
})

describe('#grabElementBoundingRect', () => {
it('should get the element size', async () => {
await wd.amOnPage('/form/hidden')
Expand Down
Loading

0 comments on commit b343cd2

Please sign in to comment.