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

Errors when working with Firefox against selenium hub (only) #2151

Closed eyal919 closed 5 years ago

eyal919 commented 5 years ago

NW version: 1.1.14 Node version: v10.16.0 NPM version: 6.9.0 Firefox Version: 67.0 Gecko Driver: 0.24.0 Selenium Hub Version: 3.141.59

The errors not occurs when working directly against selenium node but only when working against selenium hub

you can see the first error when trying to navigate to url when the navigation results value is null (while in chrome the results are as expected see below code):


"simple test against selenium hub" : function(browser) {
      browser.url("https://nightwatchjs.org/", function(results){
        console.log("Nav Results: " + JSON.stringify(results));
      })
    }
// Nav Results: {"value":null} - firefox
// Nav Results: {"sessionId":"6b6a3b345d1a8206583e30eaa5e8b54b","status":0,"value":null} - chrome

here is the verbose log:

Request POST http://myhub:4444 /wd/hub/session
{ desiredCapabilities: { browserName: 'firefox', acceptSslCerts: true, platform: 'ANY', javascriptEnabled: true, acceptInsecureCerts: true, elementScrollBehavior: 1, name: 'my test' } } Response 200 POST http://myhub:4444/wd/hub/session (2910ms) { value: { sessionId: '541f6274-0025-4352-a06d-efc96608e8c5', capabilities: { acceptInsecureCerts: true, browserName: 'firefox', browserVersion: '67.0.4', 'moz:accessibilityChecks': false, 'moz:buildID': '20190619235627', 'moz:geckodriverVersion': '0.24.0', 'moz:headless': false, 'moz:processID': 1948, 'moz:profile': 'C:\Users\qa\AppData\Local\Temp\rust_mozprofile.2Wz4QHdbjotc', 'moz:shutdownTimeout': 60000, 'moz:useNonSpecCompliantPointerOrigin': false, 'moz:webdriverClick': true, pageLoadStrategy: 'normal', platformName: 'windows', platformVersion: '6.1',
rotatable: false, setWindowRect: true, strictFileInteractability: false, timeouts: { implicit: 0, pageLoad: 300000, script: 30000 }, unhandledPromptBehavior: 'dismiss and notify', 'webdriver.remote.sessionid': '541f6274-0025-4352-a06d-efc96608e8c5' } } } Received session with ID: 541f6274-0025-4352-a06d-efc96608e8c5

Another example is when try to execute js: - here i'm getting 'execute did not match a known command' error

 "simple test against selenium hub (js)" : function(browser) {
      browser.url("https://nightwatchjs.org/", function(results){
        console.log("Nav Results: " + JSON.stringify(results));
      });

      browser.execute(function(){
        console.log("browser log test")
      },[],function(results) {
        console.log("execute results: " + JSON.stringify(results))
      })
    }
// execute results: {"status":-1,"state":"","value":{"error":[],"message":"POST /session/be23eed8-73a2-40a2-bb21-8e4cf1b99966/execute did not match a known command"},"errorStatus":"","error":"POST /session/be23eed8-73a2-40a2-bb21-8e4cf1b99966/execute did not match a known command","httpStatusCode":404}
vlad-vinogradov commented 5 years ago

try #2109

eyal919 commented 5 years ago

Looks good, thank you

eyal919 commented 5 years ago

User error (sorry)... this is still not working after changing to next config:

  "firefox": {
      "screenshots": {
        "path": "./reports/firefox/screenshots"
      },
      "desiredCapabilities": {
        "browserName": "firefox",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "acceptInsecureCerts": true
      },
      "webdriver": {
        "host": "myhub.com",
        "port": 4444,
        "default_path_prefix": "/wd/hub"
      }
    },
vlad-vinogradov commented 5 years ago

@eyal919 show full config and verbose log

eyal919 commented 5 years ago

Here is the full config:

{
  "src_folders": [
    "./tests"
  ],
  "live_output": true,
  "test_workers": {
    "enabled": true,
    "workers": "auto"
  },
  "output_folder": "./reports",
  "custom_commands_path": [
    "./lib/utils/custom_commands"
  ],
  "custom_assertions_path": [
    "./lib/utils/custom_asserts"
  ],
  "page_objects_path": [
    "./pages"
  ],
  "globals_path": "./lib/configuration/globals.js",
  "selenium": {
    "start_process": false,
    "server_path": "",
    "log_path": "./lib",
    "host": "myhub.com",
    "port": 4444,
    "cli_args": {
      "webdriver.chrome.driver": "",
      "webdriver.ie.driver": "",
      "webdriver.gecko.driver": "",
      "webdriver.edge.driver": ""
    }
  },
  "test_settings": {
    "default": {
      "launch_url": "http://localhost",
      "selenium_port": 4444,
      "selenium_host": "myhub.com",
      "silent": true,
      "output": true,
      "skip_testcases_on_fail": false,
      "screenshots": {
        "enabled": true,
        "on_failure": false,
        "on_error": false,
        "path": "./reports/screenshots"
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    },
    "ie-11": {
      "screenshots": {
        "path": "./reports/ie-11/screenshots"
      },
      "desiredCapabilities": {
        "browserName": "internet explorer",
        "version": "11",
        "elementScrollBehavior": 1,
        "javascriptEnabled": true,
        "requireWindowFocus": true,
        "EnableNativeEvents": true,
        "acceptSslCerts": true,
        "applicationCacheEnabled": false,
        "Enhanced Protected Mode": false,
        "RequireWindowFocus": true,
        "ignoreProtectedModeSettings": true,
        "enablePersistentHover": false,
        "unexpectedAlertBehaviour": "accept",
        "ie.ensureCleanSession": true,
        "ignoreZoomSetting": true
      }
    },
    "firefox": {
      "screenshots": {
        "path": "./reports/firefox/screenshots"
      },
      "desiredCapabilities": {
        "browserName": "firefox",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "acceptInsecureCerts": true
      },
      "webdriver": {
        "host": "myhub.com",
        "port": 4444,
        "default_path_prefix": "/wd/hub"
      }
    },
    "chrome": {
      "screenshots": {
        "path": "./reports/chrome/screenshots"
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "chromeOptions": {
          "args": [
            "disable-web-security",
            "disable-infobars"
          ]
        }
      }
    }
  }
}

and this is the verbose log for the test above:

   Request POST http://myhub:4444 /wd/hub/session
   { desiredCapabilities:
      { browserName: 'firefox',
        acceptSslCerts: true,
        platform: 'ANY',
        javascriptEnabled: true,
        acceptInsecureCerts: true,
        name: 'my test'
         } }
   Response 200 POST http://myhub:4444/wd/hub/session (2766ms)
   { value:
      { sessionId: 'd50ae062-0a2a-415a-a8ef-46d8169614f1',
        capabilities:
         { acceptInsecureCerts: true,
           browserName: 'firefox',
           browserVersion: '67.0.4',
           'moz:accessibilityChecks': false,
           'moz:buildID': '20190619235627',
           'moz:geckodriverVersion': '0.24.0',
           'moz:headless': false,
           'moz:processID': 4392,
           'moz:profile': 'C:\\Users\\qa\\AppData\\Local\\Temp\\rust_mozprofile.OciYCp3nLHbj',
           'moz:shutdownTimeout': 60000,
           'moz:useNonSpecCompliantPointerOrigin': false,
           'moz:webdriverClick': true,
           pageLoadStrategy: 'normal',
           platformName: 'windows',
           platformVersion: '6.1',          
           rotatable: false,
           setWindowRect: true,
           strictFileInteractability: false,
           timeouts: { implicit: 0, pageLoad: 300000, script: 30000 },
           unhandledPromptBehavior: 'dismiss and notify',
           'webdriver.remote.sessionid': 'd50ae062-0a2a-415a-a8ef-46d8169614f1' } } }
 Received session with ID: d50ae062-0a2a-415a-a8ef-46d8169614f1

17:46:18: End beforeEach Test
17:46:18:
17:46:20: Nav Results: {"value":null}
17:46:20:
17:46:20: execute results: {"status":-1,"state":"","value":{"error":[],"message":"POST /session/d50ae062-0a2a-415a-a8ef-46d8169614f1/execute did not match a known command"},"errorStatus":"","error":"POST /session/d50ae062-0a2a-415a-a8ef-46d8169614f1/execute did not match a known command","httpStatusCode":404}
17:46:20: No assertions ran.
17:46:20:
17:46:20:
17:46:20: Globals.js AFTER EACH

17:46:27: Globals.js AFTER

Process finished with exit code 0
vlad-vinogradov commented 5 years ago

@eyal919 you didn't read carefully #2109.
Remove selenium section, remove selenium_... settings in the default section - just add webdriver settings to the default section. Do not use any settings with "selenium" string/substring at all!

eyal919 commented 5 years ago

Thanks, i removed all selenium_... and add the webdriver setting only to the default and now i'm not getting any errors when running execute command but the results are still not full (like in chrome), no session id and no status: Nav Results: {"value":null} execute results: {"value":null}

here is the config:

"default": {
      "launch_url": "http://localhost",
      "silent": true,
      "output": true,
      "skip_testcases_on_fail": false,
      "screenshots": {
        "enabled": true,
        "on_failure": false,
        "on_error": false,
        "path": "./reports/screenshots"
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      },
      "webdriver": {
        "host": "myhub.com",
        "port": 4444,
        "default_path_prefix": "/wd/hub"
      }
    },
vlad-vinogradov commented 5 years ago

For chrome add the following settings:

"chrome": {
   webdriver: { use_legacy_jsonwire: true },
   desiredCapabilities: {
      browserName: "chrome",
      "goog:chromeOptions": { w3c: false },
       ...
   }
}

See #2118

vlad-vinogradov commented 5 years ago

... but the results are still not full (like in chrome), no session id and no status:

Yes, it's true. But it's not selenium hub related behavior. It is simply the result of using different protocols. For Firefox W3C Webdriver protocol is using. For Chrome - legacy JSON Wire protocol.

The Nav Results value is just appropriate protocol response value (see verbose log).

eyal919 commented 5 years ago

got it, thank you, i will wait with this changes since many of my tests are checking the state or the status of the commands (in the callback results)

vlad-vinogradov commented 5 years ago

@eyal919

... i will wait with this changes

What "changes" do you mean?
It is a bad idea to use protocol's internals unspecified in the API. Note that W3C WebDriver responses do not match the ones of legacy JSON Wire protocol.

streLer commented 5 years ago

i had the same issue ,

my config is :

selenium: { use_legacy_jsonwire: true, start_process: true, server_path: seleniumserver.path, host: '127.0.0.1', port: 4444, cli_args: { 'webdriver.chrome.driver': chromedriver.path, 'webdriver.gecko.driver': geckodriver.path } },

test_settings: { default: { selenium_port: 4444, selenium_host: 'localhost', silent: true, }, chrome: { desiredCapabilities: { browserName: 'chrome', javascriptEnabled: true, acceptSslCerts: true, chromeOptions: { w3c: false, args: [ '--no-sandbox', '--disable-web-security', '--start-maximized', '--disable-gpu' ] } } },

nightwatch 0.9.21 , nightwatch-cucumber , chrome v75 , chromedriver 75.0.1

vlad-vinogradov commented 5 years ago

@streLer Npm package chromedriver@75.0.1 installs ChromeDriver 75.0.3770.8 that has a bug. I have posted this issue to package owner.

Npm package chromedriver@75.1.0 is available now, that installs ChromeDriver 75.0.3770.90.

streLer commented 5 years ago

@vlad-vinogradov thanks! when update chromedriver manually (replace exe in node module ) it works.

taitelman commented 5 years ago

ok. this bug happens to me without selenium. only on firefox (FF) . chrome works perfectly: here is my test

'Some Login Test': function (browser) {
browser.url('http://www.myhost.com/getJSONInfo', result => {
       if (result !== null) {
//both FF and chrome will enter here however,  FF result is {value: null} while chrome has real data
           console.log(`got response: ${JSON.stringify(result)}`);
       } 
    })
}

this is with NightWatch 1.1.13 . no selenium server. just WebDriver. geckodriver 0.24.0 ( 2019-01-28) Firefox 60.7.2esr (64-bit) on RHEL v7.6

should I open a dedicated defect for this ?

vlad-vinogradov commented 5 years ago

@taitelman

ok. this bug happens to me without selenium. only on firefox (FF) . chrome works perfectly: ...

This isn't Nightwatch bug - this is your "bug"! You try to handle callback arg as Json Wire protocol response. But in reality, W3C Protocol is used with Firefox!
See answer to eyal919 above...

taitelman commented 5 years ago

This isn't Nightwatch bug - this is your "bug"! ...

ok. I got you. I just want to call some endpoint and parse the response. I guess this might work


'Demo test NightwatchJS.org' : function (client) {
    client
      .url('http://nightwatchjs.org')
      .element('css selector', 'body', function(res) {
        let bodyId = res.value;
        for (firstKey in bodyId);
        client.elementIdText(bodyId[firstKey], (result) => {
            const body = JSON.parse(result.value);
            parseBody(body);                
    });
      });
      .end();
  }
};```
vlad-vinogradov commented 5 years ago

@taitelman Resources for further reading:

vlad-vinogradov commented 5 years ago

@taitelman
... see also: