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.79k stars 1.31k forks source link

Selenium 3 web protocol issue #1786

Closed gettingtired closed 5 years ago

gettingtired commented 6 years ago

Fetching session with nightwatch v0.9.20, selenium 3.11.0

Request: POST http://localhost:4444/wd/hub/session
    { desiredCapabilities:
      { browserName : 'firefox',
        javascriptEnabled: true,
        acceptSslCerts: true,
        platform:'ANY',
        acceptInsecureCerts: true,
        elementScrollBehavior: 1,
        idleTimeout: 300 }}

Response 200 POST http://localhost:4444/wd/hub/session
    { status: 0,                                            
    sessionId: '7b53710dee0b6f74a3a71df47aff2fc9',
    value: 
        { capabilies... }

Fetching session with v1.0.4, selenium 3.11.0

Request POST http://localhost:4444 /session
   { desiredCapabilities: 
      { browserName: 'firefox',                                  
        acceptSslCerts: true,                                       
        platform: 'ANY',                                     
        javascriptEnabled: true,                              
        acceptInsecureCerts: true,                                
        elementScrollBehavior: 1,                                               
        idleTimeout: 300 }

Response 200 POST http://localhost:4444/session                                                  
   { status: -1,                                        
     value: '<!DOCTYPE html>\n<html lang="en">\n<head>\n  <meta charset="UTF-8">\n  <link rel="stylesheet" type="text/css" href="/assets/displayhelpservlet.css" media="all"/>\n  <link href="/assets/favicon.ico" rel="icon" type="image/x-icon" />\n  <script src="/assets/jquery-3.1.1.min.js" type="text/javascript"></script>\n  <script src="/assets/displayhelpservlet.js" type="text/javascript"></script>\n  <script type="text/javascript">\n    var json = Object.freeze(\'{"consoleLink":"/grid/console","type":"Grid Hub","version":"3.11.0","class":"org.openqa.grid.web.servlet.DisplayHelpServlet$DisplayHelpServletConfig"}\');\n  </script>\n</head>\n<body>\n\n<div id="content">\n  <div id="help-heading">\n    <h1><span id="logo"></span></h1>\n    <h2>Selenium <span class="se-type"></span> v.<span class="se-version"></span></h2>\n  </div>\n\n  <div id="content-body">\n    <p>\n      Whoops! The URL specified routes to this help page.\n    </p>\n    <p>\n      For more information about Selenium <span class="se-type"></span> please see the\n      <a class="se-docs">docs</a> and/or visit the <a class="se-wiki">wiki</a>.\n      <span id="console-item">\n        Or perhaps you are looking for the Selenium <span class="se-type"></span> <a class="se-console">console</a>.\n      </span>\n    </p>\n    <p>\n      Happy Testing!\n    </p>\n  </div>\n\n  <div>\n    <footer id="help-footer">\n      Selenium is made possible through the efforts of our open source community, contributions from\n      these <a href="https://github.com/SeleniumHQ/selenium/blob/master/AUTHORS">people</a>, and our\n      <a href="http://www.seleniumhq.org/sponsors/">sponsors</a>.\n   </footer>\n  </div>\n </div>\n\n</body>\n</html>' }

I can't seem to retrieve any session without the /wh/hub path

beatfactor commented 6 years ago

Could you share your config please?

gettingtired commented 6 years ago

I have a selenium server (zalenium) hosted in aws.

{
  "src_folders": [
    "C:\\Users\\kcid\\nightwatch\\scripts"
  ],
  "custom_commands_path": "C:\\Users\\nightwatch\\custom-commands",
  "custom_assertions_path": "C:\\Users\\kcid\\nightwatch\\custom-assertions",
  "waitForConditionPollInterval": 200,
  "test_settings": {
    "default": {
      "selenium": {
        "start_process": false,
        "host": "selenium-docker.service.ccp.org",
        "port": "4445"
      },
      "silent": true,
      "disable_colors": true,
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "acceptInsecureCerts": true,
        "elementScrollBehavior": 1
      },
      "request_timeout_options": {
        "timeout": 300000
      }
    }
  }
}

I was able to run tests after modifying nightwatch's /lib/protocol/transport.js

get defaultPathPrefix() {
  return '/wd/hub';
}
beatfactor commented 6 years ago

Yes, I see the problem. You can also fix it by explicitly setting "default_path_prefix" : "/wd/hub" in the "selenium" settings, which should be set by default for selenium.

gettingtired commented 6 years ago

I see, that solves it.

gettingtired commented 6 years ago

Tried running my script on firefox and got this response from verbose logging. Selenium v3.11.0, Firefox v59.0.2, Nightwatch v1.0.4

Request POST http://selenium-docker:4445/wd/hub/session/8a183f25-3d58-436e-8ce5-b46af3c5c220/execute

        { script: 'return document.readyState;', args: [] }

Response 404 POST http://selenium-docker:4445/wd/hub/session/8a183f25-3d58-436e-8ce5-b46af3c5c220/execute (654ms)

        { value: 
            { error: 'unknown command',
                message: 'POST /session/8a183f25-3d58-436e-8ce5-b46af3c5c220/execute did not match a known command',
                stacktrace: '' } }

Error while running .executeScript() protocol action: POST /session/8a183f25-3d58-436e-8ce5-b46af3c5c220/execute did not match a known command

Everything works on chrome as expected. I can put this in a separate issue.

Dobbychen commented 6 years ago

This is exactly what I have been experiencing with nightwatch against Firefox + selenium.

@kmcid Please create a separate issue so that @beatfactor can see this issue more clearly :) Thanks!

beatfactor commented 6 years ago

Could you please verify this with v1.0.6?

Dobbychen commented 6 years ago

@beatfactor So after v1.0.6, testing against firefox gives: An occurred error while retrieving a new session.

Settings:

    "src_folders": [
        "tests"
    ],
    "output_folder": "./reports",
    "page_objects_path": "./page-objects",
    "webdriver": {
        "default_path_prefix": "/wd/hub",
        "ssl": true
    },
    "test_settings": {
        "default": {
            "selenium": {
                "start_process": false,
                "host": "selenium.xxx.com",
                "port": 443
            },
            "desiredCapabilities": {
                "browserName": "chrome"
            }
        },
        "firefox": {
            "desiredCapabilities": {
                "browserName": "firefox",
                "acceptInsecureCerts": true
            }
        }
}
beatfactor commented 5 years ago

This should be fixed in v1.0.12. Please open a new issue if the problem still persists.

Dobbychen commented 5 years ago

@beatfactor It still persists. See my comment: https://github.com/nightwatchjs/nightwatch/issues/1874#issuecomment-438250024