简体   繁体   English

Nightwatch JS将错误抛出为“无效或意外令牌”

[英]Nightwatch JS is throwing error as 'Invalid or unexpected Token'

I have configured the Nightwatch JS, but when I am running a test I am getting as error 'Invalid or Unexpected token'. 我已经配置了Nightwatch JS,但是在运行测试时,出现错误“无效或意外令牌”。 I am using VS code for writing the tests. 我正在使用VS代码编写测试。 The command I am running is 我正在运行的命令是

node nightwatch -e chrome 节点Nightwatch -e chrome

Full Error is below: 完整错误如下:

(function (exports, require, module, __filename, __dirname) { require(‘./node_modules/nightwatch/bin/runner.js’);
                                                                      ^
SyntaxError: Invalid or unexpected token
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

Details of Package.json: Package.json的详细信息:

{
  "name": "nightwatch_learning",
  "version": "1.0.0",
  "description": "to learn nightwatch js automation",
  "main": "nightwatch.js",
  "scripts": {
    "test": ""
  },
  "author": "Alapan",
  "license": "ISC",
  "dependencies": {
    "nightwatch": "^0.9.19"
  }
}

Details of Nightwatch.json Nightwatch.json的详细信息

{
    "src_folders": ["tests"],
    "output_folder": "reports/XMLReports",
    "custom_commands_path": "",
    "custom_assertions_path": "",
    "page_objects_path": "pages",
    "selenium": {
      "start_process": true,
      "server_path": "lib/drivers/selenium-server-standalone-3.8.1.jar",
      "start_session": true,
      "log_path": "log/",
      "host": "127.0.0.1",
      "port": 4444,
      "cli_args": {
        "webdriver.chrome.driver": "lib/drivers/chromedriver.exe"
      }
    },
    "test_settings" : {
        "chrome": {
            "launch_url": "http://localhost",
            "selenium_port": 4444,
            "selenium_host": "localhost",
            "silent": true,
            "screenshots": {
              "enabled": false,
              "path": "screenshots/Chrome/"
            },
            "desiredCapabilities": {
              "browserName": "chrome",
              "chromeOptions": {
                "args": [
                  "disable-web-security",
                 "ignore-certificate-errors",
                 "--test-type"
                ]
              }
            }
          },

      "edge" : {
        "desiredCapabilities": {
          "browserName": "MicrosoftEdge"
        }
      }
    }
  }

Details of Nightwatch.js Nightwatch.js的详细信息

require(‘./node_modules/nightwatch/bin/runner.js’);

The issue was with the Nightwatch.js file. 问题出在Nightwatch.js文件上。 I changed 我变了

require(‘./node_modules/nightwatch/bin/runner.js’);

to

require("./node_modules/nightwatch/bin/runner.js");

and it worked. 而且有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM