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

我目前只使用Chrome(驱动程序)进行testing。 我想用Firefox和Safari来testing它。 一个接一个,不能并行。

这是我开始testing的重要任务:

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

一个简单的function文件:

 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(); }); }; 

我在想,也许我可以通过吞咽任务以某种方式传递浏览器的名字,但似乎并不可能。

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

在设置文件中,您可以设置一个可以通过脚本进行更改的variables(通过编辑该行),然后将其传递到您声明将使用哪个驱动程序的位置。

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

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

首选是使用bash而不是批处理,因为bash可以在Mac,UNIX和Windows 10上运行,但批处理主要是Windows(从内存我认为它只是Windows)。

如果你需要从哪里开始的指导,应要求我会给你一个大纲,但我应该给你足够的信息,以研究如何做到这一点。

由于我想按顺序进行testing,所以我想到了:

 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' })); }); 

我在想,也许我可以通过吞咽任务以某种方式传递浏览器的名字,但似乎并不可能。

请记住,每个浏览器都有自己的驱动程序,每个驱动程序需要以自己的方式创build/初始化。

如果按照您计划的方向前进,则可以将所有浏览器句柄(在创build它们之后)保存在一个数组中,然后按名称将其拖动到所需的位置。