【问题标题】:Nightwatch JS is throwing error as 'Invalid or unexpected Token'Nightwatch JS 抛出错误为“无效或意外令牌”
【发布时间】:2018-01-20 20:28:07
【问题描述】:

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

node 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’);

【问题讨论】:

    标签: javascript json node.js nightwatch.js


    【解决方案1】:

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

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

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

    它成功了。

    【讨论】:

      猜你喜欢
      • 2017-12-19
      • 2019-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 2019-08-09
      • 1970-01-01
      • 2018-05-06
      相关资源
      最近更新 更多