0

这是我的设置。是否有正确的平行角度/非角度应用测试设置?有时,我的 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
}

4

2 回答 2

0

browser.ignoreSynchronization已弃用,因此您不需要设置它。但是,您确实需要设置browser.waitForAngularEnabled(false)而不是browser.waitForAngular(false)像您在 conf.xml 中设置的那样。当 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" },
],
于 2019-06-18T06:51:30.443 回答
0

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

于 2019-06-20T23:15:04.047 回答