nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.8k stars 1.31k forks source link

Error while running .getElementAttribute() protocol action: TypeError: Error while trying to create HTTP request for Request path contains unescaped characters #2200

Closed rike422 closed 5 years ago

rike422 commented 5 years ago

Describe the bug

I encountered the following error when writing a test using getAttribute.

 Error while running .getElementAttribute() protocol action: TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters
    at new ClientRequest (_http_client.js:139:13)
    at Object.request (http.js:44:10)

TypeError: Error while trying to create HTTP request for "/wd/hub/session/7bc35a012e5ad13bb58f6cc10497560f/element/[object Object]/attribute/src": Request path contains unescaped characters
       at new ClientRequest (_http_client.js:139:13)
       at Object.request (http.js:44:10)
       at new Promise (<anonymous>)

After examining it, I think that there is a problem with the following processing.

https://github.com/nightwatchjs/nightwatch/blob/master/lib/element/command.js#L203

GetAttribute expects a string, but executeProtocolAction it passes an object. https://github.com/nightwatchjs/nightwatch/blob/master/lib/api/element-commands/getAttribute.js#L18

I tried changing it as follows and the test worked correctly

// return this.transport.executeProtocolAction(actionName, [this.elementId, ...args]);
return this.transport.executeProtocolAction(actionName, [Object.values(this.elementId)[0], ...args]);

How To Reproduce

So far in my environment, it happens in all tests using getAttribute.

Your Environment:

Please include the following:

Additional context

Add any other context about the problem here.

beatfactor commented 5 years ago

You left out your config and nightwatch version.

rike422 commented 5 years ago

@beatfactor

sorry. I forgot to add.

nightwatch version: 1.2.2 nightwatch.json

{
  "src_folders": [
    'target file'
  ],
  "output_folder": "reports/e2e",
  "custom_commands_path": "./node_modules/nightwatch-xhr/es5/commands",
  "custom_assertions_path": "",
  "page_objects_path": "",
  "globals_path": "",
  "selenium": {
    "start_process": true,
    "server_path": "./node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-3.141.59.jar",
    "log_path": "",
    "host": "127.0.0.1",
    "port": 4444,
    "cli_args": {
      "marionette": true,
      "webdriver.chrome.driver": "node_modules/chromedriver/bin/chromedriver",
      "webdriver.ie.driver": "",
      "webdriver.gecko.driver": "node_modules/geckodriver/geckodriver"
    }
  },
  "test_settings": {
    "default": {
      "launch_url": "http://localhost",
      "selenium_port": 4444,
      "selenium_host": "localhost",
      "silent": true,
      "marionette": true,
      "webdriver.gecko.driver": "node_modules/geckodriver/geckodriver",
      "webdriver.firefox.profile": "webdriver",
      "screenshots": {
        "enabled": false,
        "path": ""
      },

      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    },
    "chrome": {
      "webdriver": {
        "port": 9515,
        "default_path_prefix": "",
        "server_path":  "node_modules/chromedriver/bin/chromedriver",
        "cli_args": [
          "--verbose"
        ]
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }
  }
}

I tried to delete custom_commands_path but it was the same error

beatfactor commented 5 years ago

Do you specifically need the Selenium server? You can change the config like here: https://github.com/nightwatchjs/nightwatch-website-tests/blob/master/nightwatch.conf.js

For now, you can try to update the chrome capabilities:

chrome: {
  desiredCapabilities : {
        browserName : 'chrome',
        chromeOptions: {
          w3c: false
        }
   }
}
rike422 commented 5 years ago

@beatfactor

Thank you for your quick response.

As an integration test, I am testing with browserstack. nightwatch.json is merged to nightwatch.json for browserstack and tested, so it exists as a base setting. I wrote this json for a long time, so the above is memorable...

For now, you can try to update the chrome capabilities:

It seems to have been solved. Thanks for the advice!