gpt4 book ai didi

node.js - 在多个浏览器上运行测试(顺序)

转载 作者:太空宇宙 更新时间:2023-11-03 23:25:25 26 4
gpt4 key购买 nike

我目前仅使用 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 任务以某种方式将浏览器的名称作为参数传递,但这似乎不可能。

最佳答案

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

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

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

这就是我现在进行跨浏览器自动化的方式。

优先使用 bash 而不是批处理,因为 bash 可以在 Mac、UNIX 和 Windows 10 上运行,但批处理主要是 Windows(据我内存,我认为它仅适用于 Windows)。

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

关于node.js - 在多个浏览器上运行测试(顺序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44943339/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com