【问题标题】:WebdriverIO config file for multiple browsers多个浏览器的 WebdriverIO 配置文件
【发布时间】:2018-05-12 21:30:31
【问题描述】:

我需要在多个浏览器上运行测试用例,同时使用 webdriverIO。尽管浏览了几篇关于 WDIO 的文章和文档,但我还是找不到可行的方法。

这是我的 wdio.conf.js。

exports.config = {
    baseUrl: 'http://127.0.0.1:8100/',
    path: '/wd/hub',
    specs: [
        './e2e/**/*-wdio.e2e-spec.ts'
    ],
    maxInstances: 10,
    // capabilities: [
    //   {
    //       browserName: 'Chrome',
    //   }, 
    //   {
    //       browserName: 'Firefox',
    //   }
    // ],
    capabilities: {
        myChromeBrowser: {
            desiredCapabilities: {
                browserName: 'Chrome',
            }
        },
        myFirefoxBrowser: {
            desiredCapabilities: {
                browserName: 'Firefox',
            }
        }
    },
    
    sync: true,
    waitforTimeout: 10000,
    services: ['selenium-standalone'],
    framework: 'jasmine',
    jasmineNodeOpts: {
        defaultTimeoutInterval: 50000,
        expectationResultHandler: function(passed, assertion) {  }
    },
    before: function () {
        require('ts-node/register');
        require('ts-node').register({
            project: 'e2e'
        });
    },
}

这些是我在 package.json 中使用的 devDependencies:

"devDependencies": {
   "ts-node": "^3.3.0",
   "wdio-appium-service": "^0.2.3",
   "wdio-firefox-profile-service": "^0.1.0",
   "wdio-jasmine-framework": "^0.3.2",
   "wdio-selenium-standalone-service": "0.0.9",
   "wdio-spec-reporter": "^0.1.2",
   "wdio-typescript-service": "0.0.3",
   "webdriverio": "^4.9.8"
}

如您所见,我尝试了"capabilities": []"capabilities": {},但遵循official docs,即使在此之后,也只有two instances of Chrome 运行。我还尝试按照installation doc 安装Firefox's 插件/依赖项。

谁能指出,我错过了什么或配置错误? 目前google Chrome 的两个实例启动并在其上运行测试用例,而我希望测试用例分别在 chrome 和 firefox 中运行。

【问题讨论】:

    标签: selenium testing e2e-testing webdriver-io browser-testing


    【解决方案1】:

    另外,请检查您浏览器名称上的“Camel Casing”。因为您有 Firefox 而不是 firefox - 您可能正在让它启动 Chrome 的第二个实例。

    ...
    capabilities: [
    {
        // maxInstances can get overwritten per capability. So if you have an in-house Selenium
        // grid with only 5 firefox instances available you can make sure that not more than
        // 5 instances get started at a time.
        maxInstances: 1,
        browserName: 'chrome'
    },
    {
        maxInstances: 1,
        browserName: 'firefox'
    }
    ],
    ...
    

    【讨论】:

      【解决方案2】:

      如果您想要多个浏览器测试,请使用不同的环境变量运行单个测试套件。你应该定义矩阵;

      matrix:
      - _BROWSER: "firefox"
        _PLATFORM: "Linux"
        _VERSION: "26"
      - _BROWSER: "firefox"
        _PLATFORM: "Windows_7"
        _VERSION: "26"
      - _BROWSER: "chrome"
        _PLATFORM: "Windows_7"
        _VERSION: "31"
      

      然后只需创建具有给定容量的 WebdriverJS 实例

      var BROWSERNAME = (process.env._BROWSER || process.env.BROWSER || 'chrome').replace(/_/g,' ');
      var BROWSERVERSION = process.env._VERSION || process.env.VERSION || '*';
      var BROWSERPLATFORM = (process.env._PLATFORM || process.env.PLATFORM || 'Linux').replace(/_/g,' ');
      
      var options = {
          desiredCapabilities: {
      
      
           browserName: BROWSERNAME,
              version: BROWSERVERSION,
              platform: BROWSERPLATFORM
          },
          // ...
      };
      
      client = webdriverjs.remote(options);
      

      Travis 将自动启动三个不同的构建,并使用不同的浏览器并行运行您的测试。查看此示例项目了解更多实施细节。

      更多详情multiple browsers test

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-12-15
        • 1970-01-01
        • 2021-10-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-25
        相关资源
        最近更新 更多