运行 个 Nightwatchjs 测试有问题
Problem with running individual Nightwatchjs tests
我有一个问题,如果我使用绝对路径,我似乎只能 运行 个人 nightwatchjs 测试测试脚本。
因此,举个例子,如果我 运行 从以下文件夹进行测试;
/Users/darrenharley/Documents/Git/uk-content-parkers/Tests/Functional/tests
与以下;
npm run test:live /Users/darrenharley/Documents/Git/uk-content-parkers/Tests/Functional/tests/current_functionality/gamAds/PAR-5139.js
它工作正常。
但是,我需要 运行 这个测试而不使用我的本地文件结构(因为最终 运行 通过 Jenkins 构建所以不能使用这个)。
但是如果我运行用下面的测试;
npm run test:live ./current_functionality/gamAds/PAR-5139.js
失败,出现以下错误;
Error: ENOENT: no such file or directory, stat
'./current_functionality/gamAds/PAR-5139.js'
我是不是做错了什么?
如果有帮助,我的 nightwatch.conf.js 文件中有这个;
src_folders: [
'tests/',
],
在我的 package.json 文件中我有这个;
"test:live": "nightwatch --config config/nightwatch.conf.js --env live --suiteRetries 3",
任何帮助将不胜感激,因为这似乎是一件很基本的事情,这让人发疯。
非常感谢。
给出的路径是问题所在。 路径需要相对于根。在相对路径的情况下,它们是相对于根(其中 package.json 位于顶层)选择的。
如果目录结构是:
root
--tests
----PAR-5139.js
----
--src
--config
----nightwatch.config.json
--package.json
命令将是 npm run test:live ./tests/PAR-5139.js
,无论您 运行 命令来自测试文件夹还是根文件夹。
在您的情况下,命令是来自测试文件夹的 运行,并且还给出了关于测试文件夹的路径,但该命令正在寻找关于根而不是测试文件夹的文件。
希望对您有所帮助。如有任何疑问,请回复。
首先,关于您的 Jenkins 工作的信息不足,无法做出有根据的猜测(从哪里触发 NPM 命令?项目根目录是什么?).所以,你最好的选择是在你的 NPM 调用之前添加一个 pwd
并且很好地理解项目根目录是什么。然后,相应地更新您的命令。
现在...
对于您手头的任务,最简单(更不用说最干净)的方法是利用 NightwatchJS test-groups & test-tags.
❒ 使用 test-tags:
module.exports = {
'@tags': ['PAR-5139', 'live', 'smoke'],
'This is the PAR-5139 test': function (browser) {
// > your code here <
}
};
要启用逻辑,您的命令将变为:
npm run test:live -- --tag PAR-5139
(请注意在添加额外的 NightwatchJS 开关之前必须预先添加 --
。需要将传递给 npm 命令本身的参数和传递给您的参数分开脚本.)
❒ 使用 test-groups:
让我们考虑以下 tests
结构:
tests/
├── current_functionality
| └── PAR-5139.js
├── critical_functionality
| └── PAR-5140.js
| └── PAR-5141.js
└── dated_functionality
├── OLD-90210.js
└── OLD-NO7-BRAND-SOUR-MASH.js
要启用该逻辑,您的命令将变为:npm run test:live -- --group current_functionality
。
group
开关将列表作为参数,因此您可以在同一命令中链接多个测试文件夹:npm run test:live -- --group current_functionality,critical_functionality
!注意:别忘了,你还可以使用--skipgroup
开关(也可以链接起来排除一系列测试文件夹)。您还可以使用 'disabled'
属性 true
:
专门禁用测试 运行 中的测试用例
module.exports = {
'@disabled': true, // This will prevent the test module from running.
'Not running this PAR': function (browser) {
// > your code here <
}
};
我有一个问题,如果我使用绝对路径,我似乎只能 运行 个人 nightwatchjs 测试测试脚本。
因此,举个例子,如果我 运行 从以下文件夹进行测试;
/Users/darrenharley/Documents/Git/uk-content-parkers/Tests/Functional/tests
与以下;
npm run test:live /Users/darrenharley/Documents/Git/uk-content-parkers/Tests/Functional/tests/current_functionality/gamAds/PAR-5139.js
它工作正常。
但是,我需要 运行 这个测试而不使用我的本地文件结构(因为最终 运行 通过 Jenkins 构建所以不能使用这个)。
但是如果我运行用下面的测试;
npm run test:live ./current_functionality/gamAds/PAR-5139.js
失败,出现以下错误;
Error: ENOENT: no such file or directory, stat './current_functionality/gamAds/PAR-5139.js'
我是不是做错了什么?
如果有帮助,我的 nightwatch.conf.js 文件中有这个;
src_folders: [
'tests/',
],
在我的 package.json 文件中我有这个;
"test:live": "nightwatch --config config/nightwatch.conf.js --env live --suiteRetries 3",
任何帮助将不胜感激,因为这似乎是一件很基本的事情,这让人发疯。
非常感谢。
给出的路径是问题所在。 路径需要相对于根。在相对路径的情况下,它们是相对于根(其中 package.json 位于顶层)选择的。
如果目录结构是:
root
--tests
----PAR-5139.js
----
--src
--config
----nightwatch.config.json
--package.json
命令将是 npm run test:live ./tests/PAR-5139.js
,无论您 运行 命令来自测试文件夹还是根文件夹。
在您的情况下,命令是来自测试文件夹的 运行,并且还给出了关于测试文件夹的路径,但该命令正在寻找关于根而不是测试文件夹的文件。
希望对您有所帮助。如有任何疑问,请回复。
首先,关于您的 Jenkins 工作的信息不足,无法做出有根据的猜测(从哪里触发 NPM 命令?项目根目录是什么?).所以,你最好的选择是在你的 NPM 调用之前添加一个 pwd
并且很好地理解项目根目录是什么。然后,相应地更新您的命令。
现在...
对于您手头的任务,最简单(更不用说最干净)的方法是利用 NightwatchJS test-groups & test-tags.
❒ 使用 test-tags:
module.exports = {
'@tags': ['PAR-5139', 'live', 'smoke'],
'This is the PAR-5139 test': function (browser) {
// > your code here <
}
};
要启用逻辑,您的命令将变为:
npm run test:live -- --tag PAR-5139
(请注意在添加额外的 NightwatchJS 开关之前必须预先添加 --
。需要将传递给 npm 命令本身的参数和传递给您的参数分开脚本.)
❒ 使用 test-groups:
让我们考虑以下 tests
结构:
tests/
├── current_functionality
| └── PAR-5139.js
├── critical_functionality
| └── PAR-5140.js
| └── PAR-5141.js
└── dated_functionality
├── OLD-90210.js
└── OLD-NO7-BRAND-SOUR-MASH.js
要启用该逻辑,您的命令将变为:npm run test:live -- --group current_functionality
。
group
开关将列表作为参数,因此您可以在同一命令中链接多个测试文件夹:npm run test:live -- --group current_functionality,critical_functionality
!注意:别忘了,你还可以使用--skipgroup
开关(也可以链接起来排除一系列测试文件夹)。您还可以使用 'disabled'
属性 true
:
module.exports = {
'@disabled': true, // This will prevent the test module from running.
'Not running this PAR': function (browser) {
// > your code here <
}
};