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

时间:2018-01-20 11:54:46

标签: javascript json node.js nightwatch.js

我已经配置了Nightwatch JS,但是当我运行测试时,我收到的错误是“无效或意外的令牌”。我正在使用VS代码编写测试。我正在运行的命令是

  

节点nightwatch -e chrome

完全错误如下:

(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

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"
  }
}

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"
        }
      }
    }
  }

Nightwatch.js的详情

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

1 个答案:

答案 0 :(得分:0)

问题出在Nightwatch.js文件中。我改变了

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

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

并且有效。