【问题标题】:Protractor Headless browser Testing using XVFB+Grunt runner on centos 7 linux distribution在 centos 7 linux 发行版上使用 XVFB+Grunt runner 进行量角器无头浏览器测试
【发布时间】:2017-09-06 23:52:11
【问题描述】:

下面是我的 gruntfile.js 。我可以使用 'grunt protractor:run 命令在 UI 上运行量角器测试。

但是,当我尝试运行命令“grunt protractor-xvfb”以便我可以在无头模式下运行测试时,浏览器仍会启动并以与使用 grunt protractor:run 命令相同的方式执行测试。

我期待的是测试在后台运行。

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'
  ]);

}

我尝试从 grunt.registerTask 中注释掉行代码 'protractor:run' 并运行 grunt protractor-xvfb 给我以下输出,根据代码是正确的。这执行得如此之快,就好像什么都没发生一样。我认为我在配置/代码中缺少一些东西来实现无头测试。

运行“shell:xvfb”(shell)任务

运行“env:xvfb”(env) 任务

运行“shell:xvfb:kill”(shell)任务

完成。

我实际上如何继续使用 xvfb + grunt+ protractor 进行无头测试?

【问题讨论】:

    标签: gruntjs protractor xvfb headless-browser


    【解决方案1】:

    如果您想要无头 Chrome 或 Firefox 测试、视频录制、VNC 实时预览、本地dashboard.html 以及其他功能,那么使用Zalenium 可能更实用。

    您可以开始使用单线:

    curl -sSL https://raw.githubusercontent.com/dosel/t/i/p | bash -s start
    

    和/或还观看演示:

    https://www.youtube.com/watch?v=W5qMsVrob6I

    【讨论】:

      【解决方案2】:

      您没有指定正确运行 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 protractor:run”。

      如果要使用 xvfb 运行,请使用命令“grunt protractor-xvfb”

      【讨论】:

      • 您好,感谢您的回复。我遵循了这些步骤,但是,在运行 grunt protractor-xvfb 时,它仍然会启动浏览器并且不会在无头模式下运行测试。
      • 粘贴完整的 gruntfile.js
      【解决方案3】:

      我找到了一种解决方法,可以使用以下命令并指定 conf.js -

      xvfb-run --server-args='-screen 0, 1600x1200x24' 量角器 app/Conf/conf.js

      这样做可以让我在无头模式下运行我的测试。

      即使您的项目中没有使用 Grunt,您也可以直接执行 npm install xvfb 并使用此命令...将其传递给 teamcity 命令行参数,它也可以在那里工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-10-24
        • 1970-01-01
        • 2015-03-26
        • 1970-01-01
        • 1970-01-01
        • 2018-02-11
        • 1970-01-01
        相关资源
        最近更新 更多