适用于多个浏览器的WebdriverIO配置文件

时间:2017-11-29 08:34:21

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

我需要在多个浏览器上运行测试用例,同时使用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插件/依赖项。

任何人都可以指出,我错过了什么或错误配置了什么? 目前两个谷歌Chrome浏览器实例启动并运行测试用例,而我希望测试用例分别在chrome和firefox中运行。

3 个答案:

答案 0 :(得分:0)

此外,请检查您的" 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'
}
],
...

答案 1 :(得分:0)

如果要进行多个浏览器测试,则要运行一个具有不同环境变量的测试套件。您应该定义矩阵;

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

答案 2 :(得分:0)

这是铬和铬。

  exports.config = {
    runner: 'local',
    //
    specs: [
        'test.js'
    ],
    //
    exclude: [
        // 'path/to/excluded/files'
    ],
    //
    //
    capabilities: {
        myChromeBrowser: {
            capabilities: {
                browserName: 'chrome',
            }
        },
        myAppiumAppr: {
            port: 4723,
            capabilities: {
                platformName: 'iOS',
                'appium:deviceName': 'iPhone 8',
                'appium:platformVersion': '12.4',
                'appium:orientation': 'PORTRAIT',
                'appium:noReset': true,
                'appium:newCommandTimeout': 240,
                "appium:platformName": "iOS",
                "appium:deviceName": "iPhone 8",
                "appium:bundleId": "com.abc.debug",
            }
        }
    },
    services: ['appium'],
    appium: {
        args: {
            address: '127.0.0.1',
            commandTimeout: '7200',
            sessionOverride: true,
            debugLogSpacing: true,
            platformVersion: '4.4',
            platformName: 'iOS',
            deviceName: 'emulator-5554',
            nativeInstrumentsLib: true,
            isolateSimDevice: true,
            app: "com.abc.debug"
        }
    },
    //
    logLevel: 'trace',
    //
    deprecationWarnings: true,
    //
    bail: 0,
    //
    baseUrl: 'google.com/',
    //
    waitforTimeout: 10000,
    //
    connectionRetryTimeout: 90000,
    //
    connectionRetryCount: 3,
    //
    services: ['selenium-standalone'],
    //
    framework: 'jasmine',
    //
    //
}

这是编写测试用例的方式;

describe('create article', function() {
    it('should do something with two browser', function () {
        //console.log(browser.getTitle()); // returns {myChromeBrowser: 'Google', myFirefoxBrowser: 'Google'}

        myAppiumApp.$('~Login').click();
        myChromeBrowser.url('http://localhost:9174/')
        myChromeBrowser.setWindowSize(2160, 3840)
        myChromeBrowser.pause(50000000000000000)
        console.log(myChromeBrowser.getTitle());
        myChromeBrowser.pause(50000000000000000)

    });
});
相关问题