我正在使用 Protractor 编写自动化测试脚本,现在我需要使用 Jenkins 为此设置 CI。
它需要执行的任务是:
- 启动 selenium 独立服务器。
- 使用conf.js文件开始测试。
- 停止 selenium 独立服务器。
有人可以在这方面提供帮助吗?
最佳答案
我创建了一个小的 bash 脚本来执行此操作。
# start selenium
./node_modules/protractor/bin/webdriver-manager start > /dev/null 2>&1 &
# wait until selenium is up
while ! curl http://localhost:4444/wd/hub/status &>/dev/null; do :; done
# run the build
grunt cibuild --force
# stop selenium
curl -s -L http://localhost:4444/selenium-server/driver?cmd=shutDownSeleniumServer > /dev/null 2>&1
此脚本是从 jenkins 中的自由式项目调用的(构建 > 执行 shell)
然后通过读取 Protractor 测试结果生成测试结果报告。因此,您必须从 Protractor 生成 junit 报告(查看 here ):
onPrepare: function() {
// The require statement must be down here, since jasmine-reporters
// needs jasmine to be in the global and protractor does not guarantee
// this until inside the onPrepare function.
require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmine.JUnitXmlReporter('xmloutput', true, true));
},
为了使报告在 jenkins 中可见,我在作业中添加了构建后操作:发布 JUnit 测试结果报告
:
关于selenium - 使用 Jenkins 设置 Protractor 的持续集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21338019/