我在编写npm脚本来启动我的量角器测试时遇到了问题。按照文档https://github.com/angular/protractor/blob/master/docs/server-setup.md的说明,首先我必须运行
webdriver-manager start在我开始实际测试的时候让它继续运行
./node_modules/.bin/protractor test/integration/conf.js我希望这两个步骤在一个npm脚本中执行,所以我会得到如下结果:
"scripts": {
"protractor-update": "./node_modules/.bin/webdriver-manager update",
"protractor-start": "./node_modules/.bin/webdriver-manager start",
"protractor-init": "npm run protractor-update && npm run protractor-start",
"test-protractor": "npm run protractor-start && ./node_modules/.bin/protractor test/integration/conf.js",
},现在,很明显,问题是./node_modules/.bin/webdriver-manager start没有返回退出代码,所以它永远不会执行下一个命令。
实现这一目标的正确方法是什么?
发布于 2016-08-31 22:40:47
我和你有同样的问题。这是我在StackOverflow上浏览后,在同事的帮助下找到的解决方案。
在package.json中:
"scripts": {
"e2e": "bash run-e2e-tests.sh"
}bash文件:
# Start selenium server and trash the verbose error messages from webdriver
webdriver-manager start 2>/dev/null &
# Wait 3 seconds for port 4444 to be listening connections
while ! nc -z 127.0.0.1 4444; do sleep 3; done
# run protractor
protractor test/e2e/conf.js发布于 2016-03-18 01:22:06
答案在于shell脚本基础知识。
使用&将webdriver放在后台
举个例子
webdriver-manager start &这将运行webdriver-manager,然后立即将控制权返回给shell,从而允许您输入后续命令。
在通过某种机制(如kill %1或pkill webdriver-manager )完成测试后,您会想要杀死webdriver-manager。否则,你最终会有几十个未使用的webdriver进程在运行……
发布于 2019-09-24 00:16:33
您可以同时使用来解决您的问题。
使用以下命令并发安装。
npm install concurrently --save然后在package.json中使用,如下所示:
"e2e:all-steps": "concurrently -k -s first \"./node_modules/.bin/webdriver-manager update\" \"./node_modules/.bin/webdriver-manager start\" \"npm run protractor-update && npm run protractor-start\" \"npm run protractor-start && ./node_modules/.bin/protractor test/integration/conf.js\""希望这能有所帮助。:-)
https://stackoverflow.com/questions/36066695
复制相似问题