【问题标题】:What is the correct config settings to automate test in parallel using Protractor?使用 Protractor 并行自动化测试的正确配置设置是什么?
【发布时间】:2019-10-31 13:51:57
【问题描述】:

这是我的设置。是否有正确的平行角度/非角度应用测试设置?有时,我的 firefox 或 chrome 在另一个运行时挂起。 ignoreSynchronization 是否应该设置为 truewaitForAngular 是否设置为 false?我觉得有太多时间同步问题导致其中一个浏览器挂起?

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    getPageTimeout: 600000,
    allScriptsTimeout: 500000,
    defaultTimeoutInterval: 30000,
    framework: 'custom',
    // path relative to the current config file
    frameworkPath: require.resolve('protractor-cucumber-framework'),
    multiCapabilities:
    [{
      'browserName': 'firefox',
      specs: 'features/firefox/*.feature',
    },
    {
      'browserName': 'chrome',
      specs: 'features/chrome/*.feature',
    }],
    maxSessions: 2,
    baseUrl: 'https://localhost:8080',
    cucumberOpts: {
      strict: true,
      require: [
        'hooks/hooks.js',
        'specs/*Spec.js'
      ],
      tags: [
        "@runThis", 
        "~@ignoreThis"
      ],
      profile: false,
      format: 'json:./e2e/reports/cucumber-report.json',
      resultJsonOutputFile: './e2e/reports/cucumber-report.json'
    },
    beforeLaunch: function() {
      const fs = require('fs');
      const path = require('path');

      const directory = './e2e/reports';

      //cleans up the json results from the previous build when using node flake
      fs.readdir(directory, (err, files) => {
        if (err) throw err;

        for (const file of files) {
          fs.unlink(path.join(directory, file), err => {
            if (err) throw err;
          });
        }
      });
    },
    onPrepare: function() {
      var chai = require('chai');
      chai.use(require('chai-as-promised'));
      global.expect = chai.expect;
      browser.ignoreSynchronization = true;
      browser.manage().window().maximize();
      browser.waitForAngular(false);           
      browser.manage().timeouts().implicitlyWait(30000); 

    },
    ghostMode:false
}

【问题讨论】:

  • 只需在功能中添加这两行就足够了:shardTestFiles: truemaxInstances: 2

标签: selenium automation protractor


【解决方案1】:

browser.ignoreSynchronization 已弃用,因此您无需设置它。但是,您确实需要设置 browser.waitForAngularEnabled(false) 而不是 browser.waitForAngular(false) 就像您在 conf 中设置的那样。当 waitForAngularEnabled 为 true 时,waitForAngular 是在每个操作之前调用的。

像这样设置你的 onPrepare

onPrepare: function() {
  var chai = require('chai');
  chai.use(require('chai-as-promised'));
  global.expect = chai.expect;
  browser.manage().window().maximize();
  browser.waitForAngularEnabled(false);           
  browser.manage().timeouts().implicitlyWait(30000); 
},

您的具体情况将取决于您试图从并行执行中获得什么。

此设置会将您的测试划分为 2 种浏览器类型(chrome 和 firefox),并并行执行您的测试。它将同时支持 3 个 chrome 和 2 个 firefox 浏览器同时运行。测试是根据先完成的来划分的

multiCapabilities: [
    { browserName: "chrome", shardTestFiles: true, maxInstances: 3 },
    { browserName: "firefox", shardTestFiles: true, maxInstances: 2 },
],
maxSessions: 10, //controls the total number of instances, won't be relevant in this case 

此设置将在 chrome 和 firefox 浏览器上执行您的所有测试。如果您运行 5 个规范,您将得到 10 个结果。

multiCapabilities: [
    { browserName: "firefox" },
    { browserName: "chrome" },
],

【讨论】:

    【解决方案2】:

    上面给出的答案是添加 shardTestFiles: true,并且 maxInstances 的数量应该可以工作。但是我仍然想强调,如果您使用 webdriver-manager start 启动 selenium 服务器(我认为您是基于配置文件中给出的 selenium 地址),那么不要指望它会像 selenium 网格解决方案一样顺利运行在不同的浏览器上并行运行测试。 Webdriver-manager 被设计为启动 selenium 服务器的最快解决方案,而不是 selenium-grid 的替代品。

    【讨论】:

      猜你喜欢
      • 2016-02-15
      • 2020-09-13
      • 2018-02-17
      • 2016-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-21
      相关资源
      最近更新 更多