未为自定义 protractor.conf 文件创建 Webdriver 实例
Webdriver instances not created for custom protractor.conf file
我想在 Travis 中集成我的 E2E 套件,所以我关注了 this 文章。如文章中所述,我创建了一个自定义的 protractor.ci.conf.js
Travis 构建文件。我已将此文件放入我的 e2e
文件夹(路径:e2e/protractor.ci.conf.js
)。
我的自定义 e2e/protractor.ci.conf.js
和 angular 生成的 protractor.conf.js
文件的唯一区别是下面显示的 args
属性 中的值。
e2e/protractor.ci.conf.js
chromeOptions: {
args: [
'--headless',
'window-size=1920,1080'
]
}
protractor.conf.js
const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
shardTestFiles: true,
maxInstances: 2,
'browserName': 'chrome',
chromeOptions: {
args: ['--start-maximized']
}
},
directConnect: true,
baseUrl: 'localhost:4000/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 300000,
print: function () {
}
},
useAllAngular2AppRoots: true,
onPrepare: function () {
jasmine.getEnv().addReporter(new SpecReporter());
require('ts-node').register({
project: 'e2e/tsconfig.json'
});
}
};
在我的 package.json
文件中有 2 个脚本,一个用于 运行 测试本地,一个用于 Travis .
Package.json(与protractor.conf.js同级)
"scripts": {
...
"test": "ng test --watch=false",
"pree2e": "webdriver-manager update",
"e2e": "concurrently --kill-others \"ng e2e --port=4000\" \"npm run _server:run\"",
"e2e:ci": "concurrently --kill-others \"ng e2e --port=4000 --protractor-config=e2e/protractor.ci.conf.js\" \"npm run _server:run\"",
"_server:run": "tsc -p ./server && concurrently \"tsc -w -p ./server\" \"nodemon dist/server/index.js\" ",
...
},
.travis.yml
branches:
only:
- staging
- prod
- functional-testing
script:
...
- if [[ $TRAVIS_COMMIT_MESSAGE == *"[skip e2e]"* ]]; then echo "skipping E2E test"; else npm run e2e:ci; fi
...
before_deploy:
- sed -i '/dist/d' .gitignore
- git add . && git commit -m "latest build"
- cd $TRAVIS_BUILD_DIR/dist
问题
当简单地 运行 npm run e2e
时,每个测试都运行良好。但是当我使用 npm run e2e:ci
命令脚本挂起并且没有 WebDriver 实例运行时。
I/launcher — Running 0 instances of WebDriver
即将到来,而不是 1 或 2 个实例。
那是因为你创建了一个新的配置文件并且显然放在了文件夹中
/e2e
而不是默认的根文件夹。
您案例中测试文件的路径也应更新。
因此 './e2e/**/*.e2e-spec.ts'
将更改为 './**/*.e2e-spec.ts'
因为目前测试无法找到任何指定的文件,所以它 运行 没有任何实例。
我想在 Travis 中集成我的 E2E 套件,所以我关注了 this 文章。如文章中所述,我创建了一个自定义的 protractor.ci.conf.js
Travis 构建文件。我已将此文件放入我的 e2e
文件夹(路径:e2e/protractor.ci.conf.js
)。
我的自定义 e2e/protractor.ci.conf.js
和 angular 生成的 protractor.conf.js
文件的唯一区别是下面显示的 args
属性 中的值。
e2e/protractor.ci.conf.js
chromeOptions: {
args: [
'--headless',
'window-size=1920,1080'
]
}
protractor.conf.js
const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
shardTestFiles: true,
maxInstances: 2,
'browserName': 'chrome',
chromeOptions: {
args: ['--start-maximized']
}
},
directConnect: true,
baseUrl: 'localhost:4000/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 300000,
print: function () {
}
},
useAllAngular2AppRoots: true,
onPrepare: function () {
jasmine.getEnv().addReporter(new SpecReporter());
require('ts-node').register({
project: 'e2e/tsconfig.json'
});
}
};
在我的 package.json
文件中有 2 个脚本,一个用于 运行 测试本地,一个用于 Travis .
Package.json(与protractor.conf.js同级)
"scripts": {
...
"test": "ng test --watch=false",
"pree2e": "webdriver-manager update",
"e2e": "concurrently --kill-others \"ng e2e --port=4000\" \"npm run _server:run\"",
"e2e:ci": "concurrently --kill-others \"ng e2e --port=4000 --protractor-config=e2e/protractor.ci.conf.js\" \"npm run _server:run\"",
"_server:run": "tsc -p ./server && concurrently \"tsc -w -p ./server\" \"nodemon dist/server/index.js\" ",
...
},
.travis.yml
branches:
only:
- staging
- prod
- functional-testing
script:
...
- if [[ $TRAVIS_COMMIT_MESSAGE == *"[skip e2e]"* ]]; then echo "skipping E2E test"; else npm run e2e:ci; fi
...
before_deploy:
- sed -i '/dist/d' .gitignore
- git add . && git commit -m "latest build"
- cd $TRAVIS_BUILD_DIR/dist
问题
当简单地 运行 npm run e2e
时,每个测试都运行良好。但是当我使用 npm run e2e:ci
命令脚本挂起并且没有 WebDriver 实例运行时。
I/launcher — Running 0 instances of WebDriver
即将到来,而不是 1 或 2 个实例。
那是因为你创建了一个新的配置文件并且显然放在了文件夹中
/e2e
而不是默认的根文件夹。
您案例中测试文件的路径也应更新。
因此 './e2e/**/*.e2e-spec.ts'
将更改为 './**/*.e2e-spec.ts'
因为目前测试无法找到任何指定的文件,所以它 运行 没有任何实例。