下面是我的gruntfile.js。我可以使用'grunt protractor:run命令在UI上运行量角器测试。
然而,当我尝试运行命令'grunt protractor-xvfb'以便我可以在无头模式下运行我的测试时,浏览器仍然以与使用grunt量角器:运行命令相同的方式启动和测试执行。
我期待的是测试在后台运行。
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
protractor: {
options: {
keepAlive: true,
configFile: "../spike-protractor/app/Conf/conf.js",
noColor: false,
args: {
baseUrl: 'https://xxx/xxx/'
}
},
run: {}
},
shell: {
xvfb: {
command: 'Xvfb :99 -ac -screen 0 1600x1200x24',
options: {
async: true
}
}
},
env: {
xvfb: {
DISPLAY: ':99'
}
}
});
grunt.loadNpmTasks('grunt-protractor-runner');
grunt.loadNpmTasks('grunt-shell-spawn');
grunt.loadNpmTasks('grunt-env');
grunt.loadNpmTasks('grunt-protractor-webdriver');
grunt.registerTask('protractor-chrome', ['protractor:chrome']);
grunt.registerTask('protractor-xvfb', [
'shell:xvfb',
'env:xvfb',
'protractor:run',
'shell:xvfb:kill'
]);
}
我尝试评论行代码'protractor:run'from grunt.registerTask并运行grunt protractor-xvfb给出了下面的输出,这是根据代码是正确的。如果没有发生任何事情,这执行速度很快我认为在配置/代码中缺少一些东西来实现无头测试。
运行“shell:xvfb”(shell)任务
运行“env:xvfb”(env)任务
运行“shell:xvfb:kill”(shell)任务
完成。
我如何使用xvfb + grunt +量角器进行无头测试?
答案 0 :(得分:0)
如果你想要无头Chrome或Firefox测试,视频录制,VNC实时预览,本地dashboard.html以及其他功能,那么使用Zalenium的用例可能更实用。
您可以开始使用单行代码:
curl -sSL https://raw.githubusercontent.com/dosel/t/i/p | bash -s start
和/或观看演示文稿:
答案 1 :(得分:0)
您没有指定正确运行conf.js. 删除部分
grunt.registerTask('protractor-chrome', ['protractor:chrome']);
来自您问题中指定的gruntfile.js。 编辑你的gruntfile.js并在下面添加:
grunt.registerTask('protractor-xvfb', [
'shell:xvfb',
'env:xvfb',
'protractor:run',
'shell:xvfb:kill'
]);
如果你想在不使用xvfb的情况下运行,请使用命令" grunt量角器:运行"。
如果你想使用xvfb运行,那么使用命令" grunt protractor-xvfb"
答案 2 :(得分:0)
我找到了一个解决方法,使用下面的命令并指定conf.js -
xvfb-run --server-args =' - 屏幕0,1600x1200x24'量角器app / Conf / conf.js
这样做可以让我在无头模式下运行我的测试。
即使您没有在项目中使用Grunt,也可以直接执行npm install xvfb并使用此命令...将其传递给teamcity命令行参数,它也可以在那里工作。