使用browserstack-local

时间:2016-07-27 11:28:30

标签: protractor browserstack gulp-protractor

我正在开展一个角度项目,我们使用量角器进行端到端测试。我们使用gulp-protractor来运行这些测试。当地的每件事都很好。现在我们想要增加测试中的浏览器和设备的数量,所以我开始更改protractor.conf.js以使用browserstack。

正在测试的Web应用程序在本地运行,因此我也使用browserstack-local

我的配置适用于一个浏览器,它测试在本地运行的网站(灵感来自https://github.com/browserstack/protractor-browserstack/blob/master/conf/local.conf.js)。

现在,我试图让它适应在多浏览器上运行(https://github.com/browserstack/protractor-browserstack/blob/master/conf/parallel.conf.js之后)。我最终得到了这个配置:

exports.config = {
  framework: 'jasmine2',
  onPrepare: common.onPrepare,

  // The address of a running selenium server.
  seleniumAddress: 'http://hub-cloud.browserstack.com/wd/hub',

  commonCapabilities: {
    'browserstack.user': 'OUR_USER',
    'browserstack.key': 'OUR_KEY',
    name: 'Taylor Wimpey e2e tests',
    'browserstack.debug': 'true',
    'browserName': 'chrome',
    'browserstack.local': true
  },

  multiCapabilities: [{
    browserName: 'Chrome'
  },{
    browserName: 'Safari'
  },{
    browserName: 'Firefox'
  },{
    browserName: 'IE'
  }],

  baseUrl: 'http://localhost:3000',

  // Spec patterns are relative to the current working directory when
  // protractor is called.
  specs: [paths.e2e + '/**/*.js'],

  // Options to be passed to Jasmine-node.
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000
  },

  // Code to start browserstack local before start of test
  beforeLaunch: function(){
    console.log("Connecting local");
    return new Promise(function(resolve, reject){
      exports.bs_local_args = {
        key: exports.config.commonCapabilities['browserstack.key'],
        force: true
      };
      exports.bs_local = new browserstack.Local();
      exports.bs_local.start(exports.bs_local_args, function(error) {
        if (error) return reject(error);
        console.log('Connected. Now testing...');

        resolve();
      });
    });
  },

  // Code to stop browserstack local after end of test
  onComplete: function(){
    console.log('Stop browserstack local');
    return new Promise(function(resolve){
      exports.bs_local.stop(resolve);
    });
  }
};

// Code to support common capabilities
exports.config.multiCapabilities.forEach(function(caps){
  for(var i in exports.config.commonCapabilities) {
    caps[i] = caps[i] || exports.config.commonCapabilities[i];
  }
});

测试已启动并正常运行(我的报告是针对每个浏览器生成的),但它永远不会停止。这里是控制台日志的结束:

...
[BS] Serving files from: .tmp/serve
[BS] Serving files from: src
Connecting local
Connected. Now testing...
[09:05:39] I/launcher - Running 4 instances of WebDriver
......F......FFF^C

所以我必须手动杀死它们,这不是一个选项,因为最后,测试将在持续集成服务器中运行。

有没有人知道如何使用browserstack在多个浏览器上运行e2e测试,并在本地运行测试的Web应用程序?

更新:browserstack支持为其github仓库上的本地运行的多功能添加了一个示例:https://github.com/browserstack/protractor-browserstack/blob/master/conf/parallel_local.conf.js

唯一的区别是使用afterLaunch代替onComplete

由于

0 个答案:

没有答案