webdriverio/webdriverio

[🐛 Bug]: wdio-v9 Cucumber framework <mock.respond()> WebDriver Bidi command "network.continueRequest" failed with error

Open

#13.939 geöffnet am 2. Dez. 2024

Auf GitHub ansehen
 (4 Kommentare) (2 Reaktionen) (0 zugewiesene Personen)JavaScript (1.793 Forks)batch import
Bug 🐛help wanted

Repository-Metriken

Stars
 (6.029 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 15T 15h) (48 gemergte PRs in 30 T)

Beschreibung

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.4.1

Node.js Version

v20.16.0

Mode

WDIO Testrunner

Which capabilities are you using?

export const config = {
    // ====================
    // Runner Configuration
    // ====================
    // WebdriverIO supports running e2e tests as well as unit and component tests.
    runner: 'local',
    specs: [
        //'src/test.spec.js'
        'src/features/**.feature'
        // ToDo: define location for spec files here
    ],
    maxInstances: 1,
    capabilities: [{
        // capabilities for local browser web tests
        browserName: 'chrome', 
        browserVersion: '131',
     }],
    // Level of logging verbosity: trace | debug | info | warn | error | silent
    logLevel: 'info',
    // If you only want to run your tests until a specific amount of tests have failed use
    // bail (default is 0 - don't bail, run all tests).
    bail: 0,
    // Default timeout for all waitFor* commands.
    waitforTimeout: 10000,
    //
    // Default timeout in milliseconds for request
    // if browser driver or grid doesn't send response
    connectionRetryTimeout: 120000,
    //
    // Default request retries count
    connectionRetryCount: 3,
    //framework: 'mocha',
    framework: 'cucumber',
    cucumberOpts: {
        backtrace: true,
        requireModule: [],
        failAmbiguousDefinitions: true,
        failFast: false,
        ignoreUndefinedDefinitions: false,
        name: [],
        snippets: true,
        source: true,
        profile: [],
        require: [
            'src/features/step-definitions/*.js',
            
        ],
        snippetSyntax: '',
        order: 'defined',
        strict: true,
        tags: '',
        tagsInTitle: false,
        timeout: 120000,
        retry: 0
    }, 
    // Options to be passed to Mocha.
    // See the full list at http://mochajs.org/
    mochaOpts: {
        ui: 'bdd',
        timeout: 60000
    }
}

What happened?

The problem happens when we restore a mock and init the same mock pattern again with another or the same response in one worker (feature). Running several scenarios that restore and init mock using same pattern in a row in one feature file leads to an error:

Error: WebDriver Bidi command "network.continueRequest" failed with error: unknown error - Invalid state for continueInterceptedRequest
    at BidiHandler.send (file:///Users/Admin/work/wdio-v9-playground/node_modules/webdriver/build/node.js:411:23)
    at BidiHandler.networkContinueRequest (file:///Users/Admin/work/wdio-v9-playground/node_modules/webdriver/build/node.js:758:31)
    at Browser.value (file:///Users/Admin/work/wdio-v9-playground/node_modules/webdriver/build/node.js:1200:26)
    at Browser.wrapCommandFn (/Users/Admin/work/wdio-v9-playground/node_modules/@wdio/utils/build/index.js:884:32)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at     at new UnknownErrorException (<anonymous>:65:4646)
    at     at CommandProcessor.processCommand (<anonymous>:469:8614)

Same time when running similar tests using mocha framework all tests pass.

What is your expected behavior?

No response

How to reproduce the bug.

To reproduce the bug create a file

src/features/step-definitions/mock-steps.js

import { When } from '@cucumber/cucumber'

When('should demonstrate the mock.respond command', async () => {
  let mock = await browser.mock('**/objects/7', { fetchResponse: false })
  mock.respond({ "test": "passed" }).on('continue', async (requestId) => {
    console.log('======1==========', requestId)
  })
  await browser.url('https://api.restful-api.dev/objects/7')
  mock.respond({ "test2": "passed" }).on('continue', async (requestId) => {
    console.log('========2========', requestId)
  })
  await browser.url('https://api.restful-api.dev/objects/7')
  await mock.restore() // or use await browser.mockRestoreAll() 
})

When('should demonstrate the mock.respond does not work', async () => {
  let mockFail = await browser.mock('**/objects/7', { fetchResponse: false })
  mockFail.respond({ "test3": "failed" }).on('continue', async (requestId) => {
    console.log('=========3========', requestId)
  })
  await browser.url('https://api.restful-api.dev/objects/7')
  await mockFail.restore() // or use await browser.mockRestoreAll() 
  await browser.url('https://api.restful-api.dev/objects/7')
})

And create a feature file

mock-examples.feature
Feature: Mock Example

  Scenario: Verify mock work
    When should demonstrate the mock.respond command
    When should demonstrate the mock.respond does not work

Example

 https://github.com/ak-4ehov/wdio-v9-playground

Relevant log output

> wdio
> wdio run ./wdio.conf.js


Execution of 1 workers started at 2024-12-02T10:17:03.894Z

2024-12-02T10:17:03.900Z INFO @wdio/cli:launcher: Run onPrepare hook
2024-12-02T10:17:03.901Z INFO @wdio/utils: Setting up browser driver for: chrome@131
2024-12-02T10:17:03.905Z INFO @wdio/utils: Setting up browser binaries for: chrome@131
2024-12-02T10:17:04.155Z INFO webdriver: Using Chromedriver v131.0.6778.85 from cache directory /var/folders/pp/xc0c25hj2cgfm3hy0rt6td_40000gn/T
2024-12-02T10:17:04.491Z INFO webdriver: Setting up chrome v131.0.6778.85
2024-12-02T10:17:04.496Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2024-12-02T10:17:04.496Z INFO @wdio/local-runner: Start worker 0-0 with arg: run ./wdio.conf.js
[0-0] 2024-12-02T10:17:04.949Z INFO @wdio/local-runner: Run worker command: run
[0-0] RUNNING in chrome - file:///src/features/mock-examples.feature
[0-0] 2024-12-02T10:17:05.219Z INFO webdriver: Initiate new session using the WebDriver protocol
[0-0] 2024-12-02T10:17:06.002Z INFO webdriver: Setting up chrome v131.0.6778.85
[0-0] 2024-12-02T10:17:06.006Z INFO webdriver: Using Chromedriver v131.0.6778.85 from cache directory /var/folders/pp/xc0c25hj2cgfm3hy0rt6td_40000gn/T
[0-0] 2024-12-02T10:17:06.023Z INFO chromedriver: Starting ChromeDriver 131.0.6778.85 (3d81e41b6f3ac8bcae63b32e8145c9eb0cd60a2d-refs/branch-heads/6778@{#2285}) on port 57307
[0-0] 2024-12-02T10:17:06.023Z INFO chromedriver: Remote connections are allowed by an allowlist (0.0.0.0).
[0-0] 2024-12-02T10:17:06.023Z INFO chromedriver: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[0-0] 2024-12-02T10:17:06.025Z INFO chromedriver: ChromeDriver was started successfully on port 57307.
[0-0] 2024-12-02T10:17:07.018Z INFO @wdio/utils: Started Chromedriver v131.0.6778.85 with params --port=57307 --allowed-origins=* --allowed-ips=0.0.0.0 in 1627ms on port 57307
[0-0] 2024-12-02T10:17:07.029Z INFO webdriver: [POST] http://localhost:57307/session
[0-0] 2024-12-02T10:17:07.029Z INFO webdriver: DATA {
[0-0]   capabilities: {
[0-0]     alwaysMatch: {
[0-0]       browserName: 'chrome',
[0-0]       browserVersion: '131',
[0-0]       'goog:chromeOptions': [Object],
[0-0]       webSocketUrl: true,
[0-0]       unhandledPromptBehavior: 'ignore'
[0-0]     },
[0-0]     firstMatch: [ {} ]
[0-0]   }
[0-0] }
[0-0] 2024-12-02T10:17:07.671Z INFO webdriver: Register BiDi handler for session with id 038120fe9e016f73e4b4e98ab7d5f146
[0-0] 2024-12-02T10:17:07.672Z INFO webdriver: Connect to webSocketUrl ws://127.0.0.1:57307/session/038120fe9e016f73e4b4e98ab7d5f146
[0-0] 2024-12-02T10:17:07.676Z INFO webdriver: Connected session to Bidi protocol
[0-0] 2024-12-02T10:17:07.676Z INFO webdriver: COMMAND getWindowHandle()
[0-0] 2024-12-02T10:17:07.677Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["log.entryAdded","browsingContext.navigationStarted"]}
[0-0] 2024-12-02T10:17:07.677Z INFO webdriver: BIDI COMMAND script.addPreloadScript { functionDeclaration: <PreloadScript[1319 bytes]>, contexts: undefined }
[0-0] 2024-12-02T10:17:07.677Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.navigationStarted","network.responseCompleted","network.beforeRequestSent","network.fetchError"]}
[0-0] 2024-12-02T10:17:07.678Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.userPromptOpened"]}
[0-0] 2024-12-02T10:17:07.678Z INFO webdriver: COMMAND getWindowHandle()
[0-0] 2024-12-02T10:17:07.678Z INFO webdriver: Connected to WebDriver Bidi interface at ws://127.0.0.1:57307/session/038120fe9e016f73e4b4e98ab7d5f146
[0-0] 2024-12-02T10:17:07.678Z INFO webdriver: [GET] http://localhost:57307/session/038120fe9e016f73e4b4e98ab7d5f146/window
[0-0] 2024-12-02T10:17:07.678Z INFO webdriver: [GET] http://localhost:57307/session/038120fe9e016f73e4b4e98ab7d5f146/window
[0-0] 2024-12-02T10:17:07.679Z INFO webdriver: COMMAND getWindowHandle()
[0-0] 2024-12-02T10:17:07.679Z INFO webdriver: [GET] http://localhost:57307/session/038120fe9e016f73e4b4e98ab7d5f146/window
[0-0] 2024-12-02T10:17:07.681Z INFO webdriver: RESULT 0291C935B5233B895F95B385A9D9D3F5
[0-0] 2024-12-02T10:17:07.681Z INFO webdriver: BIDI COMMAND script.callFunction {"functionDeclaration":"<Function[220 bytes]>","awaitPromise":true,"arguments":[{"type":"string","value":"var __defProp = Object.defineProperty;var __name = function (target, value) { return __defProp(target, 'name', { value: value, configurable: true }); };var __globalThis = (typeof globalThis === 'object' && globalThis) || (typeof window === 'object' && window);__globalThis.__name = __name;"}],"target":{"context":"0291C935B5233B895F95B385A9D9D3F5"}}
[0-0] 2024-12-02T10:17:07.682Z INFO webdriver: RESULT 0291C935B5233B895F95B385A9D9D3F5
[0-0] 2024-12-02T10:17:07.683Z INFO webdriver: RESULT 0291C935B5233B895F95B385A9D9D3F5
[0-0] 2024-12-02T10:17:07.683Z INFO webdriver: BIDI COMMAND script.addPreloadScript { functionDeclaration: <PreloadScript[482 bytes]>, contexts: ["0291C935B5233B895F95B385A9D9D3F5"] }
[0-0] 2024-12-02T10:17:07.727Z INFO webdriver: BIDI RESULT {"id":1,"result":{},"type":"success"}
[0-0] 2024-12-02T10:17:07.734Z INFO webdriver: BIDI RESULT {"id":4,"result":{},"type":"success"}
[0-0] 2024-12-02T10:17:07.740Z INFO webdriver: BIDI RESULT {"id":2,"result":{"script":"98c05783-d342-4385-b349-01ef3806dc48"},"type":"success"}
[0-0] 2024-12-02T10:17:07.742Z INFO webdriver: BIDI RESULT {"id":3,"result":{},"type":"success"}
[0-0] 2024-12-02T10:17:07.743Z INFO webdriver: BIDI RESULT {"id":5,"result":{"realm":"6038971649959206144.2196730581851056310","result":{"type":"undefined"},"type":"success"},"type":"success"}
[0-0] 2024-12-02T10:17:07.744Z INFO webdriver: BIDI RESULT {"id":6,"result":{"script":"c75336af-3b96-4eb1-829e-12969d944c25"},"type":"success"}
[0-0] 2024-12-02T10:17:07.744Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["script.message"]}
[0-0] 2024-12-02T10:17:07.746Z INFO webdriver: BIDI RESULT {"id":7,"result":{},"type":"success"}
[0-0] 2024-12-02T10:17:07.747Z INFO webdriverio:PolyfillManager: polyfill script added
[0-0] 2024-12-02T10:17:07.796Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["network.beforeRequestSent","network.responseStarted"]}
[0-0] 2024-12-02T10:17:07.810Z INFO webdriver: BIDI RESULT {"id":8,"result":{},"type":"success"}
[0-0] 2024-12-02T10:17:07.811Z INFO WebDriverInterception: subscribed to network events
[0-0] 2024-12-02T10:17:07.811Z INFO webdriver: BIDI COMMAND network.addIntercept {"phases":["beforeRequestSent","responseStarted"],"urlPatterns":[{"type":"pattern","pathname":"\\*\\*/objects/7"}]}
[0-0] 2024-12-02T10:17:07.816Z INFO webdriver: BIDI RESULT {"id":9,"result":{"intercept":"412b4f58-809a-4075-8c6c-a26829ea91c9"},"type":"success"}
[0-0] 2024-12-02T10:17:07.817Z INFO webdriver: BIDI COMMAND browsingContext.navigate {"context":"0291C935B5233B895F95B385A9D9D3F5","url":"https://api.restful-api.dev/objects/7","wait":"complete"}
[0-0] ======1========== 4D78713004AB3B778707FF4D34863660
[0-0] 2024-12-02T10:17:07.823Z INFO webdriver: BIDI COMMAND network.continueRequest {"request":"4D78713004AB3B778707FF4D34863660"}
[0-0] 2024-12-02T10:17:07.825Z INFO webdriver: BIDI RESULT {"id":11,"result":{},"type":"success"}
[0-0] 2024-12-02T10:17:08.345Z INFO webdriver: BIDI COMMAND network.provideResponse {"request":"4D78713004AB3B778707FF4D34863660","body":{"type":"string","value":"{\"test\":\"passed\"}"}}
[0-0] 2024-12-02T10:17:08.348Z INFO webdriver: BIDI RESULT {"id":12,"result":{},"type":"success"}
[0-0] 2024-12-02T10:17:08.356Z INFO webdriver: BIDI RESULT {"id":10,"result":{"navigation":"832e16ad-19bd-4c00-8fa0-a5f8511f0af6","url":"https://api.restful-api.dev/objects/7"},"type":"success"}
[0-0] 2024-12-02T10:17:08.357Z INFO webdriver: BIDI COMMAND browsingContext.navigate {"context":"0291C935B5233B895F95B385A9D9D3F5","url":"https://api.restful-api.dev/objects/7","wait":"complete"}
[0-0] ======1========== 706682BF6B2CBEEF2A381AAA63EEC15A
[0-0] ========2======== 706682BF6B2CBEEF2A381AAA63EEC15A
[0-0] 2024-12-02T10:17:08.367Z INFO webdriver: BIDI COMMAND network.continueRequest {"request":"706682BF6B2CBEEF2A381AAA63EEC15A"}
[0-0] 2024-12-02T10:17:08.369Z INFO webdriver: BIDI RESULT {"id":14,"result":{},"type":"success"}
[0-0] 2024-12-02T10:17:08.718Z INFO webdriver: BIDI COMMAND network.provideResponse {"request":"706682BF6B2CBEEF2A381AAA63EEC15A","body":{"type":"string","value":"{\"test2\":\"passed\"}"}}
[0-0] 2024-12-02T10:17:08.720Z INFO webdriver: BIDI RESULT {"id":15,"result":{},"type":"success"}
[0-0] 2024-12-02T10:17:08.724Z INFO webdriver: BIDI RESULT {"id":13,"result":{"navigation":"22911152-bee9-4c58-93f7-6437f43a5304","url":"https://api.restful-api.dev/objects/7"},"type":"success"}
[0-0] 2024-12-02T10:17:08.725Z INFO webdriver: COMMAND getWindowHandle()
[0-0] 2024-12-02T10:17:08.725Z INFO webdriver: [GET] http://localhost:57307/session/038120fe9e016f73e4b4e98ab7d5f146/window
[0-0] 2024-12-02T10:17:08.727Z INFO webdriver: RESULT 0291C935B5233B895F95B385A9D9D3F5
[0-0] 2024-12-02T10:17:08.727Z INFO webdriver: BIDI COMMAND network.removeIntercept {"intercept":"412b4f58-809a-4075-8c6c-a26829ea91c9"}
[0-0] 2024-12-02T10:17:08.730Z INFO webdriver: BIDI RESULT {"id":16,"result":{},"type":"success"}
[0-0] 2024-12-02T10:17:08.731Z INFO webdriver: BIDI COMMAND network.addIntercept {"phases":["beforeRequestSent","responseStarted"],"urlPatterns":[{"type":"pattern","pathname":"\\*\\*/objects/7"}]}
[0-0] 2024-12-02T10:17:08.734Z INFO webdriver: BIDI RESULT {"id":17,"result":{"intercept":"71171ee0-bf1d-4ded-853a-3e174d8d0481"},"type":"success"}
[0-0] 2024-12-02T10:17:08.734Z INFO webdriver: BIDI COMMAND browsingContext.navigate {"context":"0291C935B5233B895F95B385A9D9D3F5","url":"https://api.restful-api.dev/objects/7","wait":"complete"}
[0-0] ======1========== D82C95501890B4F318A148A338DC8A78
[0-0] ========2======== D82C95501890B4F318A148A338DC8A78
[0-0] =========3======== D82C95501890B4F318A148A338DC8A78
[0-0] 2024-12-02T10:17:08.738Z INFO webdriver: BIDI COMMAND network.continueRequest {"request":"D82C95501890B4F318A148A338DC8A78"}
[0-0] 2024-12-02T10:17:08.738Z INFO webdriver: BIDI COMMAND network.continueRequest {"request":"D82C95501890B4F318A148A338DC8A78"}
[0-0] 2024-12-02T10:17:08.744Z INFO webdriver: BIDI RESULT {"id":19,"result":{},"type":"success"}
[0-0] 2024-12-02T10:17:08.745Z INFO webdriver: BIDI RESULT {"error":"unknown error","id":20,"message":"Invalid state for continueInterceptedRequest","stacktrace":"Error\n    at new UnknownErrorException (\u003Canonymous>:65:4646)\n    at CommandProcessor.processCommand (\u003Canonymous>:469:8614)","type":"error"}
[0-0] Error in "0: When should demonstrate the mock.respond does not work"
Error: WebDriver Bidi command "network.continueRequest" failed with error: unknown error - Invalid state for continueInterceptedRequest
    at BidiHandler.send (file:///Users/Admin/work/wdio-v9-playground/node_modules/webdriver/build/node.js:411:23)
    at BidiHandler.networkContinueRequest (file:///Users/Admin/work/wdio-v9-playground/node_modules/webdriver/build/node.js:758:31)
    at Browser.value (file:///Users/Admin/work/wdio-v9-playground/node_modules/webdriver/build/node.js:1200:26)
    at Browser.wrapCommandFn (/Users/Admin/work/wdio-v9-playground/node_modules/@wdio/utils/build/index.js:884:32)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at     at new UnknownErrorException (<anonymous>:65:4646)
    at     at CommandProcessor.processCommand (<anonymous>:469:8614)
[0-0] 2024-12-02T10:17:08.752Z INFO webdriver: COMMAND deleteSession()
[0-0] 2024-12-02T10:17:08.752Z INFO webdriver: [DELETE] http://localhost:57307/session/038120fe9e016f73e4b4e98ab7d5f146
[0-0] 2024-12-02T10:17:08.809Z INFO webdriver: RESULT null
[0-0] 2024-12-02T10:17:08.809Z INFO webdriver: Close Bidi connection to ws://127.0.0.1:57307/session/038120fe9e016f73e4b4e98ab7d5f146
[0-0] 2024-12-02T10:17:08.809Z INFO webdriver: Kill driver process with PID 78009
[0-0] FAILED in chrome - file:///src/features/mock-examples.feature
2024-12-02T10:17:08.922Z INFO @wdio/cli:launcher: Run onWorkerEnd hook
2024-12-02T10:17:08.922Z INFO @wdio/cli:launcher: Run onComplete hook

Spec Files:      0 passed, 1 failed, 1 total (100% completed) in 00:00:05  

2024-12-02T10:17:08.922Z INFO @wdio/local-runner: Shutting down spawned worker
2024-12-02T10:17:09.175Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully
2024-12-02T10:17:09.177Z INFO @wdio/local-runner: shutting down

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

Contributor Guide