1

我是 Node 新手,正在尝试设置 Nightwatch,以便我可以运行自动化测试并练习我的测试技能。我还想澄清一下,我使用的是 Windows 10 计算机。我目前在运行“npm run debug”时遇到问题,因为我在输入“npx which nightwatch”并看到“C:\Users\jtorres\nightwatch-tests\node_modules.bin\nightwatch.CMD”后将其设置为正确的目录. 之后,我运行调试器并打开“chrome://inspect/#devices”以验证调试器是否运行并正常运行,但只看到几条错误消息。我尝试将目录更改为“node_modules/nightwatch/bin/nightwatch”并创建了一个新的“nightwatch.cmd”文件,以查看自动创建后是否有错误,但这些方法都没有奏效。

错误:

(function (exports, require, module, __filename, __dirname) { @IF EXIST "%~dp0\node.exe" (
                                                              ^

SyntaxError: Invalid or unexpected token
    at new Script (vm.js:80:7)
    at createScript (vm.js:274:10)
    at Object.runInThisContext (vm.js:326:10)
    at Module._compile (internal/modules/cjs/loader.js:664:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    at startup (internal/bootstrap/node.js:283:19)

代码:

package.json file - 
    {
      "name": "nightwatch-tests",
      "version": "1.0.0",
      "description": "",
      "main": "sample.js",
      "scripts": {
        "lint": "eslint .",
        "debug": "node --inspect-brk C:/Users/jtorres/nightwatch-tests/node_modules/.bin/nightwatch.CMD",
        "test": "nightwatch"
      },
      "keywords": [],
      "author": "",
      "license": "ISC",
      "devDependencies": {
        "chromedriver": "^75.0.0",
        "nightwatch": "^1.1.12"
      }
    }

nightwatch.CMD file - 
@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe"  "%~dp0\..\nightwatch\bin\nightwatch" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node  "%~dp0\..\nightwatch\bin\nightwatch" %*
)
4

1 回答 1

2

您的"debug"参数中有错误的路径。尝试改用这个:

"debug": "node --inspect-brk node_modules/nightwatch/bin/nightwatch"
于 2019-08-07T13:22:00.463 回答