运行 在多个浏览器上测试(按顺序)

Run tests on multiple browsers (Sequentially)

我目前仅使用 Chrome(驱动程序)进行测试。我也想用 Firefox 和 Safari 测试它。一个接着一个,不能并列。

这是我的 gulp 开始测试的任务:

gulp.task('test', function() {
  return gulp.src('*test/features/*').pipe(cucumber({
    'steps': '*test/features/steps/*.js'
  }));
});

一个简单的特征文件:

Feature: UI
    Testing UI

    Scenario: Check the title of the page
        When I open the homepage
        Then I should see "Test - IntApp" in the title

步骤文件:

const chrome = require('selenium-webdriver/chrome');
const webdriver = require('selenium-webdriver');
const assert = require('assert');


module.exports = function () {
    let options = new chrome.Options();
    options.addArguments('start-maximized');

    var driver = new webdriver.Builder()
    .forBrowser('chrome')
    .setChromeOptions(options)
    .build();

    this.When('I open the homepage', function (done) {
        driver.get('http://intapp.dev/').then(done);
    });

    this.Then('I should see "Test - IntApp" in the title', function (done) {
        driver.getTitle().then(function(title) {
          assert.equal(title, "Test - IntApp");
        }).then(done);
    });


    this.registerHandler('AfterFeatures', function (features) {
        return driver.quit();
    });
};

我在想也许我可以通过 gulp 任务以某种方式将浏览器的名称作为参数传递,但这似乎不可能。

I was thinking that maybe I could pass the browser's name as parameter somehow from the gulp task, but it doesn't seem to be possible.

请记住,每个浏览器都有自己的驱动程序,每个驱动程序都需要以自己的方式 created/initialized。

如果你朝着你计划的方向前进, 您可以将所有浏览器句柄(在您创建它们之后)保存在一个数组中,然后只需按名称拉出您想要的那个。

编写 bash 或批处理脚本并创建安装文件。

在安装文件中,您可以设置一个可以用脚本更改的变量(通过编辑该行),并将其交给声明您将使用哪个驱动程序的地方。

此脚本将一个接一个地 运行 它们,但它们将是不同的套件(如果您使用 JSON 或 HTML 输出,则创建不同的报告)。

这就是我一段时间以来一直在做跨浏览器自动化的方式。

优先使用 bash 而不是批处理,因为 bash 在 Mac、UNIX 和 Windows 10 上可以是 运行,但批处理是主要是 Windows(从记忆中我认为它只是 Windows)。

如果您需要关于从哪里开始的指导,我会根据要求给您一个大纲,但我应该给您足够的信息来研究如何去做。

因为我想按顺序进行测试,这就是我想出的:

gulp.task('test', function(cb) {
  runSequence(
    'test-chrome',
    'test-firefox',
  cb);
});

gulp.task('test-chrome', function(cb) {
  return gulp.src('*test/features/*').pipe(cucumber({
      'steps': '*test/features/steps/*.js',
      'support': '*test/support/chrome.js'
    }));
});

gulp.task('test-firefox', function(cb) {
  return gulp.src('*test/features/*').pipe(cucumber({
      'steps': '*test/features/steps/*.js',
      'support': '*test/support/firefox.js'
    }));
});