Nightwatch: ReferenceError: browser is not defined - Nightwatch

Created on 17 Jun 2016  路  12Comments  路  Source: nightwatchjs/nightwatch

I麓ve upgraded Nightwatch from v9.0 to v9.4 and now i麓m getting this error!!!
What麓s causing this?
Can someone please help me??

ReferenceError: browser is not defined

Most helpful comment

No worries at all. At least now you know in future to look in the error message for which specific file is causing the issue, which will often take you directly to a syntax error or some other error.

All 12 comments

Hello! Can you show the code/test for which you're seeing this error?
when seeing this previously, it was down to not setting the argument for the test function, e.g:

module.exports = {  
  'Demo test' : function (browser) {
    // be sure you have browser in the line above

Although if all you've done is upgrade Nightwatch, then this may not apply.
Do share you config/test if you can.

Hello,

module.exports ={
    'Main Menu - Dropdown' : function(browser){
        browser
             .url()

This is what I have and was working till I upgraded nightwatch to v9.4

Can you share your nightwatch.json - should help provide clues as to what's wrong.
(also, can you confirm that the Nightwatch version change is the only change made?)

{
  "src_folders" : ["tests"],
  "output_folder" : "reports",
  "custom_commands_path" : "custom-commands",
  "custom_assertions_path" : "",
  "page_objects_path" : "pages",
  "globals_path" : "",

  "selenium" : {
    "start_process" : true,
    "server_path" : "bin/selenium-server-standalone-2.53.0.jar",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "bin/chromedriver.exe",
      "webdriver.ie.driver" : ""
    }
  },

  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
      "silent": true,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    },

    "chrome" : {
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }
  }
}

First I upgraded the Nightwatch, only after, trying to fix the error, I upgraded node.js

Can you run your nightwatch command with the --verbose command and paste the whole output here please?

Also, does your test work if you switch from using chrome to firefox in your Nightwatch config?
(this will help narrow down the issue to a potential chromedriver issue or mis-config)

'--verbose' is not recognized as an internal or external command,
operable program or batch file.

James, I was running the tests in firefox but since firefox automatically upgraded for v47 had to change to chrome

Hmm, I haven't used Windows in years, but I assume you're calling nightwatch with something like:

node nightwatch.js ?

If so, does appending --verbose not work for you:

node nightwatch.js --verbose

The error you posted above suggests you've typed --verbose into command prompt on its own.

i麓ve tried also with node nightwatch --verbose and what I get is this:

Starting selenium server... started - PID:  7528

[76] Test Suite
===================

ReferenceError: browser is not defined
    at Object.<anonymous> (C:\wamp\www\azercell-nightwatch\tests\77.js:5:1)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at new Module (C:\wamp\www\azercell-nightwatch\node_modules\nightwatch\lib\r
unner\module.js:7:23)
    at new TestSuite (C:\wamp\www\azercell-nightwatch\node_modules\nightwatch\li
b\runner\testsuite.js:19:17)

Can you paste the full contents of the tests\77.js file please?

(it's not clear to me what the issue is just yet - but no doubt information you've shared thus far will allow someone a little more familiar with Nightwatch than me to help out there)

James, i麓m so sorry for taking your time, just realised that the test 77 was unfinished and was not commented causing error to the rest of the tests but thank you a lot for trying to help me.

No worries at all. At least now you know in future to look in the error message for which specific file is causing the issue, which will often take you directly to a syntax error or some other error.

Was this page helpful?
0 / 5 - 0 ratings