-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Labels
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
WebdriverIO Version
9.20.0
Node.js Version
22.17.1
Mode
WDIO Testrunner
Which capabilities are you using?
capabilities: [{
browserName: 'chrome'
}],What happened?
I am trying to use browser.mock to set up basic auth for a given URL. The URL has more than one basic auth challenge under different paths. Since I don't want to specify each one of the URLs, I want to use wildcards. When I specify the complete URL, it works, but when I use wildcards, it does not.
I am running this test on Sauce Labs, but the result is the same when I run it locally.
What is your expected behavior?
I would like to use wildcards in browser.mock combined with basic auth.
How to reproduce the bug.
it('sets auth through mocks', async () => {
const mock = await browser.mock('https://the-internet.herokuapp.com/**');
const encodedAuth = Buffer.from('admin:admin', 'utf8').toString('base64')
mock.request({
headers: {
Authorization: `Basic ${encodedAuth}`,
},
})
await browser.url('https://the-internet.herokuapp.com/');
// Load basic auth url
await browser.url('https://the-internet.herokuapp.com/basic_auth');
const bodyText = await $('body').getText();
expect(bodyText).toContain('Congratulations! You must have the proper credentials.');
});Relevant log output
❯ npm run wdio
> wdio
> wdio run ./wdio.conf.js
Execution of 1 workers started at 2025-10-08T17:00:49.460Z
2025-10-08T17:00:49.472Z INFO @wdio/cli:launcher: Run onPrepare hook
2025-10-08T17:00:49.474Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2025-10-08T17:00:49.474Z INFO @wdio/xvfb: XvfbManager.init() called
2025-10-08T17:00:49.474Z INFO @wdio/xvfb: Xvfb not needed on current platform
2025-10-08T17:00:49.474Z INFO @wdio/local-runner: Start worker 0-0 with arg: run ./wdio.conf.js
2025-10-08T17:00:49.509Z INFO @wdio/xvfb:ProcessFactory: xvfb-run not found, falling back to regular fork
2025-10-08T17:00:49.509Z INFO @wdio/xvfb:ProcessFactory: ProcessFactory: shouldRun=false, isAvailable=false
2025-10-08T17:00:49.509Z INFO @wdio/xvfb:ProcessFactory: Creating worker process with regular fork
[0-0] 2025-10-08T17:00:50.184Z INFO @wdio/local-runner: Run worker command: run
[0-0] RUNNING in chrome - file:///test/specs/test.e2e.js
[0-0] 2025-10-08T17:00:50.294Z INFO webdriver: Initiate new session using the WebDriver protocol
[0-0] 2025-10-08T17:00:50.295Z INFO @wdio/utils: Connecting to existing driver at https://ondemand.eu-central-1.saucelabs.com:443/wd/hub
[0-0] 2025-10-08T17:00:50.300Z INFO webdriver: [POST] https://ondemand.eu-central-1.saucelabs.com/wd/hub/session
[0-0] 2025-10-08T17:01:00.238Z INFO webdriver: Register BiDi handler for session with id 7cf9ed8229ef43b3952bf31295ef8dd3
[0-0] 2025-10-08T17:01:00.238Z INFO webdriver: Connecting to webSocketUrl wss://ws.eu-west-3-lnbf.saucelabs.com/selenium/session/7cf9ed8229ef43b3952bf31295ef8dd3/se/bidi
[0-0] 2025-10-08T17:01:00.468Z INFO webdriver: Connected to Bidi protocol at wss://ws.eu-west-3-lnbf.saucelabs.com/selenium/session/7cf9ed8229ef43b3952bf31295ef8dd3/se/bidi
[0-0] 2025-10-08T17:01:00.468Z INFO webdriver: Connected to WebDriver Bidi interface at wss://ws.eu-west-3-lnbf.saucelabs.com/selenium/session/7cf9ed8229ef43b3952bf31295ef8dd3/se/bidi
[0-0] 2025-10-08T17:01:00.469Z INFO webdriver: COMMAND getWindowHandle()
[0-0] 2025-10-08T17:01:00.470Z INFO webdriver: BIDI COMMAND browsingContext.getTree {}
[0-0] 2025-10-08T17:01:00.471Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.contextCreated"]}
[0-0] 2025-10-08T17:01:00.471Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["log.entryAdded","browsingContext.navigationStarted"]}
[0-0] 2025-10-08T17:01:00.472Z INFO webdriver: BIDI COMMAND script.addPreloadScript { functionDeclaration: <PreloadScript[1319 bytes]>, contexts: undefined }
[0-0] 2025-10-08T17:01:00.472Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.navigationStarted","browsingContext.fragmentNavigated","network.responseCompleted","network.beforeRequestSent","network.fetchError"]}
[0-0] 2025-10-08T17:01:00.472Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.userPromptOpened"]}
[0-0] 2025-10-08T17:01:00.472Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.navigationStarted"]}
[0-0] 2025-10-08T17:01:00.472Z INFO webdriver: [GET] https://ondemand.eu-central-1.saucelabs.com/wd/hub/session/7cf9ed8229ef43b3952bf31295ef8dd3/window
[0-0] 2025-10-08T17:01:00.599Z INFO webdriver: BIDI RESULT {"id":1,"result":{"contexts":[{"children":[],"clientWindow":"1713054813","context":"29F3BAB39EE2A770898E5FAA17B4F56D","originalOpener":null,"parent":null,"url":"about:blank","userContext":"default"}]},"type":"success"}
[0-0] 2025-10-08T17:01:00.601Z INFO webdriverio:PolyfillManager: Adding polyfill script to context with id 29F3BAB39EE2A770898E5FAA17B4F56D
[0-0] 2025-10-08T17:01:00.602Z INFO webdriver: BIDI COMMAND script.callFunction {"functionDeclaration":"<Function[443 bytes] webdriverioPolyfill>","target":{"children":[],"clientWindow":"1713054813","context":"29F3BAB39EE2A770898E5FAA17B4F56D","originalOpener":null,"parent":null,"url":"about:blank","userContext":"default"},"awaitPromise":false}
[0-0] 2025-10-08T17:01:00.602Z INFO webdriver: BIDI COMMAND script.addPreloadScript { functionDeclaration: <PreloadScript[443 bytes]>, contexts: ["29F3BAB39EE2A770898E5FAA17B4F56D"] }
[0-0] 2025-10-08T17:01:00.606Z INFO webdriver: BIDI RESULT {"id":2,"result":{"subscription":"0752bbfe-9e19-4bd0-af05-231deb7411ae"},"type":"success"}
[0-0] 2025-10-08T17:01:00.607Z INFO webdriver: BIDI RESULT {"id":3,"result":{"subscription":"8bc458c9-1d94-4234-bc93-533aa13bd4e9"},"type":"success"}
[0-0] 2025-10-08T17:01:00.607Z INFO webdriver: BIDI RESULT {"id":5,"result":{"subscription":"f70c358a-7e76-4558-b1cd-e2bdc8e56e55"},"type":"success"}
[0-0] 2025-10-08T17:01:00.607Z INFO webdriver: BIDI RESULT {"id":6,"result":{"subscription":"6cfa1b18-f36f-4954-8939-09945553d382"},"type":"success"}
[0-0] 2025-10-08T17:01:00.608Z INFO webdriver: BIDI RESULT {"id":7,"result":{"subscription":"b40dd669-8ee4-4e5d-9a0b-a69279742a6c"},"type":"success"}
[0-0] 2025-10-08T17:01:00.608Z INFO webdriver: BIDI RESULT {"id":4,"result":{"script":"df8139ed-0de0-4e1b-8481-af205eb83769"},"type":"success"}
[0-0] 2025-10-08T17:01:00.649Z INFO webdriver: BIDI RESULT {"id":8,"result":{"realm":"5880762078718980314.-3238902219241098586","result":{"type":"undefined"},"type":"success"},"type":"success"}
[0-0] 2025-10-08T17:01:00.656Z INFO webdriver: BIDI RESULT {"id":9,"result":{"script":"359910d5-ba87-418d-9d5e-ceb837beab29"},"type":"success"}
[0-0] 2025-10-08T17:01:00.734Z INFO webdriver: RESULT 29F3BAB39EE2A770898E5FAA17B4F56D
[0-0] 2025-10-08T17:01:00.741Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["network.beforeRequestSent","network.responseStarted"]}
[0-0] 2025-10-08T17:01:00.791Z INFO webdriver: BIDI RESULT {"id":10,"result":{"subscription":"78c04418-2199-426b-ae06-254f3d707fde"},"type":"success"}
[0-0] 2025-10-08T17:01:00.791Z INFO WebDriverInterception: subscribed to network events
[0-0] 2025-10-08T17:01:00.791Z INFO webdriver: BIDI COMMAND network.addIntercept {"phases":["beforeRequestSent","responseStarted"],"urlPatterns":[{"type":"pattern","protocol":"https","hostname":"the-internet.herokuapp.com","pathname":"/\\*\\*","port":"443"}]}
[0-0] 2025-10-08T17:01:00.866Z INFO webdriver: BIDI RESULT {"id":11,"result":{"intercept":"2a700f3e-72c7-40a3-8447-2664fe7dcca9"},"type":"success"}
[0-0] 2025-10-08T17:01:00.866Z INFO webdriver: BIDI COMMAND browsingContext.navigate {"context":"29F3BAB39EE2A770898E5FAA17B4F56D","url":"https://the-internet.herokuapp.com/","wait":"complete"}
[0-0] 2025-10-08T17:01:05.419Z INFO webdriverio:PolyfillManager: Adding polyfill script to context with id 309A2ADB92CCBE30159B074B02FB3B8A
[0-0] 2025-10-08T17:01:05.419Z INFO webdriver: BIDI COMMAND browsingContext.getTree {}
[0-0] 2025-10-08T17:01:05.420Z INFO webdriver: BIDI COMMAND script.callFunction {"functionDeclaration":"<Function[443 bytes] webdriverioPolyfill>","target":{"children":null,"clientWindow":"1713054813","context":"309A2ADB92CCBE30159B074B02FB3B8A","originalOpener":null,"parent":"29F3BAB39EE2A770898E5FAA17B4F56D","url":"about:blank","userContext":"default"},"awaitPromise":false}
[0-0] 2025-10-08T17:01:05.476Z INFO webdriver: BIDI RESULT {"id":13,"result":{"contexts":[{"children":[{"children":[],"clientWindow":"1713054813","context":"309A2ADB92CCBE30159B074B02FB3B8A","originalOpener":null,"url":"","userContext":"default"}],"clientWindow":"1713054813","context":"29F3BAB39EE2A770898E5FAA17B4F56D","originalOpener":null,"parent":null,"url":"https://the-internet.herokuapp.com/","userContext":"default"}]},"type":"success"}
[0-0] 2025-10-08T17:01:05.843Z INFO webdriver: BIDI RESULT {"error":"unknown error","id":14,"message":"execution contexts cleared","stacktrace":"Error\n at new UnknownErrorException (\u003Canonymous>:65:5328)\n at \u003Canonymous>:679:9165\n at \u003Canonymous>:1:271\n at Array.map (\u003Canonymous>)\n at Object.emit (\u003Canonymous>:1:254)\n at MapperCdpClient.emit (\u003Canonymous>:17:333)\n at #onMessage (\u003Canonymous>:888:2529)\n at WindowCdpTransport.window.cdp.onmessage (\u003Canonymous>:968:4443)\n at \u003Canonymous>:1:18","type":"error"}
[0-0] 2025-10-08T17:01:05.868Z INFO webdriver: BIDI RESULT {"id":12,"result":{"navigation":"f0f2c01a-8fa5-4f0b-96ea-03a5dac43d8a","url":"https://the-internet.herokuapp.com/"},"type":"success"}
[0-0] 2025-10-08T17:01:05.869Z INFO webdriver: BIDI COMMAND browsingContext.navigate {"context":"29F3BAB39EE2A770898E5FAA17B4F56D","url":"https://the-internet.herokuapp.com/basic_auth","wait":"complete"}
[0-0] 2025-10-08T17:01:10.080Z INFO webdriverio:PolyfillManager: Adding polyfill script to context with id 1756FD56D76B20779F0752B4554CA2EE
[0-0] 2025-10-08T17:01:10.080Z INFO webdriver: BIDI COMMAND browsingContext.getTree {}
[0-0] 2025-10-08T17:01:10.081Z INFO webdriver: BIDI COMMAND script.callFunction {"functionDeclaration":"<Function[443 bytes] webdriverioPolyfill>","target":{"children":null,"clientWindow":"1713054813","context":"1756FD56D76B20779F0752B4554CA2EE","originalOpener":null,"parent":"29F3BAB39EE2A770898E5FAA17B4F56D","url":"about:blank","userContext":"default"},"awaitPromise":false}
[0-0] 2025-10-08T17:01:10.086Z INFO webdriver: BIDI RESULT {"id":15,"result":{"navigation":"2201d49a-d733-47fe-9ca6-ba7eb1c7ea23","url":"https://the-internet.herokuapp.com/basic_auth"},"type":"success"}
[0-0] 2025-10-08T17:01:10.091Z INFO webdriver: BIDI COMMAND browsingContext.locateNodes {"locator":{"type":"css","value":"body"},"context":"29F3BAB39EE2A770898E5FAA17B4F56D"}
[0-0] 2025-10-08T17:01:10.127Z INFO webdriver: BIDI RESULT {"id":16,"result":{"contexts":[{"children":[{"children":[],"clientWindow":"1713054813","context":"1756FD56D76B20779F0752B4554CA2EE","originalOpener":null,"url":"https://www.herokucdn.com/error-pages/application-error.html","userContext":"default"}],"clientWindow":"1713054813","context":"29F3BAB39EE2A770898E5FAA17B4F56D","originalOpener":null,"parent":null,"url":"https://the-internet.herokuapp.com/basic_auth","userContext":"default"}]},"type":"success"}
[0-0] 2025-10-08T17:01:10.127Z INFO webdriver: BIDI RESULT {"id":17,"result":{"realm":"-571655836462547153.-1143415812100174975","result":{"type":"undefined"},"type":"success"},"type":"success"}
[0-0] 2025-10-08T17:01:10.139Z INFO webdriver: BIDI RESULT {"id":18,"result":{"nodes":[{"sharedId":"f.29F3BAB39EE2A770898E5FAA17B4F56D.d.220CF44C3F9A945324687AB88892F8B0.e.5","type":"node","value":{"attributes":{},"childNodeCount":3,"localName":"body","namespaceURI":"http://www.w3.org/1999/xhtml","nodeType":1,"shadowRoot":null}}]},"type":"success"}
[0-0] 2025-10-08T17:01:10.143Z INFO webdriver: COMMAND getElementText("f.29F3BAB39EE2A770898E5FAA17B4F56D.d.220CF44C3F9A945324687AB88892F8B0.e.5")
[0-0] 2025-10-08T17:01:10.143Z INFO webdriver: [GET] https://ondemand.eu-central-1.saucelabs.com/wd/hub/session/7cf9ed8229ef43b3952bf31295ef8dd3/element/f.29F3BAB39EE2A770898E5FAA17B4F56D.d.220CF44C3F9A945324687AB88892F8B0.e.5/text
[0-0] 2025-10-08T17:01:10.326Z INFO webdriver: RESULT
[0-0] Error in "Basic Auth with Sauce Labs.sets auth through mocks"
Error: expect(received).toContain(expected) // indexOf
Expected substring: "Congratulations! You must have the proper credentials."
Received string: ""
at Context.<anonymous> (file:///Users/diegomolina/projects/github.com/diemol/selenium-issues/wdio/bidi-auth-example/wdio-v9/test/specs/test.e2e.js:29:26)
[0-0] 2025-10-08T17:01:10.329Z INFO webdriver: COMMAND deleteSession()
[0-0] 2025-10-08T17:01:10.329Z INFO webdriver: [DELETE] https://ondemand.eu-central-1.saucelabs.com/wd/hub/session/7cf9ed8229ef43b3952bf31295ef8dd3
[0-0] 2025-10-08T17:01:12.839Z INFO webdriver: RESULT
[0-0] 2025-10-08T17:01:12.840Z INFO webdriver: Close Bidi connection to wss://ws.eu-west-3-lnbf.saucelabs.com/selenium/session/7cf9ed8229ef43b3952bf31295ef8dd3/se/bidi
[0-0] FAILED in chrome - file:///test/specs/test.e2e.js
2025-10-08T17:01:12.949Z INFO @wdio/cli:launcher: Run onWorkerEnd hook
"spec" Reporter:
------------------------------------------------------------------
[chrome 141.0.7390.55 Windows 10 #0-0] Running: chrome (v141.0.7390.55) on Windows 10
[chrome 141.0.7390.55 Windows 10 #0-0] Session ID: 7cf9ed8229ef43b3952bf31295ef8dd3
[chrome 141.0.7390.55 Windows 10 #0-0]
[chrome 141.0.7390.55 Windows 10 #0-0] » test/specs/test.e2e.js
[chrome 141.0.7390.55 Windows 10 #0-0] Basic Auth with Sauce Labs
[chrome 141.0.7390.55 Windows 10 #0-0] ✖ sets auth through mocks
[chrome 141.0.7390.55 Windows 10 #0-0]
[chrome 141.0.7390.55 Windows 10 #0-0] 1 failing (12.1s)
[chrome 141.0.7390.55 Windows 10 #0-0]
[chrome 141.0.7390.55 Windows 10 #0-0] 1) Basic Auth with Sauce Labs sets auth through mocks
[chrome 141.0.7390.55 Windows 10 #0-0] expect(received).toContain(expected) // indexOf
Expected substring: "Congratulations! You must have the proper credentials."
Received string: ""
[chrome 141.0.7390.55 Windows 10 #0-0] Error: expect(received).toContain(expected) // indexOf
[chrome 141.0.7390.55 Windows 10 #0-0]
[chrome 141.0.7390.55 Windows 10 #0-0] Expected substring: "Congratulations! You must have the proper credentials."
[chrome 141.0.7390.55 Windows 10 #0-0] Received string: ""
[chrome 141.0.7390.55 Windows 10 #0-0] at Context.<anonymous> (file:///Users/diegomolina/projects/github.com/diemol/selenium-issues/wdio/bidi-auth-example/wdio-v9/test/specs/test.e2e.js:29:26)
[chrome 141.0.7390.55 Windows 10 #0-0]
[chrome 141.0.7390.55 Windows 10 #0-0] Check out job at https://app.eu-central-1.saucelabs.com/tests/7cf9ed8229ef43b3952bf31295ef8dd3?auth=6606ac5e8326f51cb9525c17864d1d05
Spec Files: 0 passed, 1 failed, 1 total (100% completed) in 00:00:23
2025-10-08T17:01:12.950Z INFO @wdio/local-runner: Shutting down spawned worker
2025-10-08T17:01:13.201Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully
2025-10-08T17:01:13.202Z INFO @wdio/local-runner: shutting down
2025-10-08T17:01:13.202Z INFO @wdio/cli:launcher: Run onComplete hook
~/projects/github.com/diemol/selenium-issues/wdio/bidi-auth-example/wdio-v9 master +21 !6 ?1 ······································································································································································································ 25s
❯Code of Conduct
- I agree to follow this project's Code of Conduct
Is there an existing issue for this?
- I have searched the existing issues
Reactions are currently unavailable