webdriverio: interceptRequest fails with "The arguments passed to a command are either invalid or malformed"

[//]: # NOTE: This repository only maintains packages that are listed in the Readme. Please make sure that your issue is directly caused by one of these packages and if not file an issue in the correct 3rd party package repository.

Environment (please complete the following information):

  • WebdriverIO version: [6.1.25]
  • Mode: [WDIO Testrunner]
  • If WDIO Testrunner, running sync/async: [sync]
  • Node.js version: [10.17.0]
  • NPM version: [6.13.4]
  • Browser name and version: [Chrome 79]
  • Platform name and version: [Windows 10]
  • Additional wdio packages used (if applicable): [@wdio/sauce-service]

Config of WebdriverIO N/A

Describe the bug Using interceptRequest() fails on SauceLabs with error: The arguments passed to a command are either invalid or malformed.

To Reproduce Use this

     browser.interceptRequest({
        url: 'https://saucelabs.com',
        redirect: 'https://google.com'
      })

[Include code or an example repository that can easily be set up]

Expected behavior This request should intercept the URL request for foo and send to bar. It should not error out.

Log If applicable, add logs to help explain your problem. Create a gist which is a paste of your full Selenium/WebdriverIO logs, and link them here. Do not paste your full Appium logs here, as it will make this issue very long and hard to read! If you are reporting a bug, always include Selenium/WebdriverIO logs!

Additional context Add any other context about the problem here.

Please use the correct markdown

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 28 (21 by maintainers)

Most upvoted comments

Tnx @christian-bromann Will prepare a PR for it later today

Sorry, no not really.

This is the endpoint

"/session/:sessionId/sauce/ondemand/intercept": {
    "POST": [{
      "command": "interceptRequest",
      "description": "Allows modifying any request made by the browser. You can blacklist, modify, or redirect these as required for your tests.",
      "ref": "https://wiki.saucelabs.com/display/DOCS/Custom+Sauce+Labs+WebDriver+Extensions+for+Network+and+Log+Commands#CustomSauceLabsWebDriverExtensionsforNetworkandLogCommands-InterceptNetworkRequests",
      "examples": [
        [
          "// redirect a request",
          "await browser.interceptRequest({",
          "  'https://saucelabs.com',",
          "  'https://google.com'",
          "})"
        ],
        [
          "// Modify requests to REST API (Mock REST API response)",
          "await browser.interceptRequest({",
          "  'http://sampleapp.appspot.com/api/todos',",
          "  null,",
          "  {",
          "    headers: {",
          "      'x-custom-headers': 'foobar'",
          "    },",
          "    body: [{",
          "      title: 'My custom todo',",
          "      order: 1,",
          "      completed: false,",
          "      url: 'http://todo-backend-express.herokuapp.com/15727'",
          "    }]",
          "  }",
          "})"
        ],
        [
          "// Blacklist requests to 3rd party vendors",
          "await browser.interceptRequest({",
          "  'https://api.segment.io/v1/p',",
          "   null,",
          "  'Failed'",
          "})"
        ]
      ],
      "parameters": [{
        "name": "url",
        "type": "string",
        "description": "An outgoing request URL. Wildcards are supported, for example https://saucelabs.com/rest/v1/* would redirect any v1 rest API requests.",
        "required": true
      },{
         "name": "redirect",
        "type": "string",
        "description": "An absolute URL to where the original request is redirected.",
        "required": false

      }]
    }]
  },
  • having 3 commands in here seems to be impossible
  • having 3 times the same endpoint is also not a thing
  • adding optional arguments also gives issues

seems like I’m stuck here, any ideas would be appreciated.

Temporary workaround would be not to use the API provided by the service but the “normal” options that Sauce Labs offers with extendedDebugging

My thoughts now are to create three different commands

Sounds good to me. The naming of the 3 commands make sense to me.

@adrian-brown , @nescalante , @ayroblu , it seems the documentation is invalid. I contacted the guys in SauceLabs and they said it is available in the following form:

await browser.execute('sauce:intercept', {
  url: 'https://www.saucedemo.com/v1/index.html',
  redirect: 'https://saucelabs.com/',
});

You need to set extendedDebugging to true. Here is the link to docs (ignore interceptRequest command in the examples, it doesn’t work, you should execute the script): https://docs.saucelabs.com/insights/debug/

FYI, @christian-bromann