Skip to content

Remove dependency to devtools #4563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Nov 14, 2024
1 change: 0 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
@@ -591,7 +591,6 @@ Running with devtools protocol
WebDriver : {
url: "http://localhost",
browser: "chrome",
devtoolsProtocol: true,
desiredCapabilities: {
chromeOptions: {
args: [ "--headless", "--disable-gpu", "--no-sandbox" ]
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
@@ -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 = {}

@@ -180,7 +179,6 @@ const config = {}
* WebDriver : {
* url: "http://localhost",
* browser: "chrome",
* devtoolsProtocol: true,
* desiredCapabilities: {
* chromeOptions: {
* args: [ "--headless", "--disable-gpu", "--no-sandbox" ]
@@ -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) {
@@ -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
}

@@ -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())
}

@@ -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))
}

@@ -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)
@@ -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) {
@@ -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 }}
*/
@@ -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) {
3 changes: 0 additions & 3 deletions lib/plugin/coverage.js
Original file line number Diff line number Diff line change
@@ -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 = {
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
@@ -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",
@@ -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"
},
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
@@ -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')
1,251 changes: 0 additions & 1,251 deletions test/helper/WebDriver_devtools_test.js

This file was deleted.

10 changes: 0 additions & 10 deletions test/helper/WebDriver_test.js
Original file line number Diff line number Diff line change
@@ -1219,16 +1219,6 @@ describe('WebDriver', 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')
4 changes: 1 addition & 3 deletions test/helper/webapi.js
Original file line number Diff line number Diff line change
@@ -915,7 +915,6 @@ module.exports.tests = function () {

it('should wait for cookie and throw error when cookie not found', async () => {
if (isHelper('TestCafe')) return
if (process.env.DevTools) return

await I.amOnPage('https://google.com')
try {
@@ -927,7 +926,6 @@ module.exports.tests = function () {

it('should wait for cookie', async () => {
if (isHelper('TestCafe')) return
if (process.env.DevTools) return

await I.amOnPage('/')
await I.setCookie({
@@ -1503,7 +1501,7 @@ module.exports.tests = function () {
})

it('should check css property for several elements', async function () {
if (isHelper('TestCafe') || process.env.BROWSER === 'firefox' || process.env.DevTools === 'true') this.skip()
if (isHelper('TestCafe') || process.env.BROWSER === 'firefox') this.skip()

try {
await I.amOnPage('/')
15 changes: 0 additions & 15 deletions test/plugin/plugin_test.js
Original file line number Diff line number Diff line change
@@ -48,21 +48,6 @@ describe('CodeceptJS plugin', function () {
})
})

it('should generate the coverage report - WebDriver - Devtools protocol', (done) => {
exec(`${config_run_config('codecept.WebDriver.devtools.coverage.js', '@coverage')} --debug`, (err, stdout) => {
const lines = stdout.split('\n')
expect(lines).toEqual(
expect.arrayContaining([
expect.stringContaining('writing output/coverage'),
expect.stringContaining('generated coverage reports:'),
expect.stringContaining('output/coverage/index.html'),
]),
)
expect(err).toBeFalsy()
done()
})
})

it('should retry to failure', (done) => {
exec(
`${config_run_config('codecept.Playwright.retryTo.js', 'Should fail after reached max retries')} --verbose`,
7 changes: 0 additions & 7 deletions typings/tests/helpers/WebDriverIO.types.ts
Original file line number Diff line number Diff line change
@@ -405,11 +405,6 @@ expectType<void>(wd.scrollPageToTop());

expectType<void>(wd.scrollPageToBottom());

expectError(wd.setGeoLocation());
expectError(wd.setGeoLocation(num));
expectType<void>(wd.setGeoLocation(num, num));
expectType<void>(wd.setGeoLocation(num, num, num));

expectError(wd.dontSeeCookie());
expectType<void>(wd.dontSeeCookie(str));

@@ -480,8 +475,6 @@ psp.then(
},
);

expectType<Promise<{ latitude: number; longitude: number; altitude: number; }>>(wd.grabGeoLocation());

expectError(wd.grabElementBoundingRect());
//expectType<Promise<number>>(wd.grabElementBoundingRect('h3'));
//expectType<Promise<number>>(wd.grabElementBoundingRect('h3', 'width'));