【发布时间】:2019-10-21 05:36:54
【问题描述】:
我是 Protractor 的新手。如果您想知道为什么我将功能文件分成文件夹是因为我想知道哪个浏览器无法进行黄瓜报告。如果我只在 1 个文件夹 specs: 'features/*.feature' 中运行所有 4 个浏览器,我无法确定最终哪个浏览器测试失败以获取黄瓜报告。
黄瓜报告: https://github.com/damianszczepanik/cucumber-reporting
在学习这个新框架时,我一直在尝试在 selenium 网格上使用相同规范(例如登录/注销 IE、safari、firefox、chrome)运行多个浏览器测试。我注意到在 4 台不同的机器上并行运行 4 种不同的浏览器有时会失败,但是当我在 1 台机器上运行 1 个浏览器测试时它通过了。它失败,要么是其中一个浏览器在页面上找不到元素,要么是浏览器卡住了。
运行多个浏览器测试的最佳做法是什么?您是想在同一个规范文件上运行并行测试,还是并行测试来帮助在不同的规范文件上运行?这里的特征文件路径是这样的
features/chrome/login.feature
features/safari/login.feature
features/firefox/login.feature
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
framework: 'custom',
// path relative to the current config file
frameworkPath: require.resolve('protractor-cucumber-framework'),
multiCapabilities:
[{
'browserName': 'chrome',
specs: 'features/chrome/*.feature'
},
{
'browserName': 'firefox',
specs: 'features/firefox/*.feature'
},
{
'browserName': 'internet explorer',
specs: 'features/ie/*.feature'
},
{
'browserName': 'safari',
specs: 'features/safari/*.feature'
}],
maxSessions: 2,
baseUrl: 'https://localhost:8080',
cucumberOpts: {
strict: true,
require: [
'hooks/hooks.js',
'specs/*Spec.js'
],
tags: [
"@runThis",
"~@ignoreThis"
],
profile: false,
format: 'json:e2e/reports/cucumber-report.json',
resultJsonOutputFile: 'e2e/reports/cucumber-report.json'
},
onPrepare: function() {
const fs = require('fs');
const path = require('path');
const directory = 'e2e/reports';
//cleans up the json results from the previous build when using node flake
// fs.readdir(directory, (err, files) => {
// if (err) throw err;
// for (const file of files) {
// fs.unlink(path.join(directory, file), err => {
// if (err) throw err;
// });
// }
// });
var chai = require('chai');
chai.use(require('chai-as-promised'));
global.expect = chai.expect;
browser.ignoreSynchronization = true;
browser.manage().window().maximize();
browser.waitForAngular(false);
}
}
Feature: Login to see the dashboard pages and logout
@runThis
Scenario: Open the browser and login
Given I am on the login page
When I should be able to login with my credentials
When I logout
Then I should be able to see login page
LoginSpec.js
let loginPage = require('../pages/loginPage.js');
const username = 'xxx';
const password = 'xxx';
module.exports = function() {
this.Given('I am on the login page', function() {
browser.get("https://localhost:8080");
});
this.When('I should be able to login with my credentials', function() {
loginPage.setUsername(username);
loginPage.setPassword(password);
loginPage.clickLogin();
loginPage.loaded(loginPage.HAMBERBURGER_MENU_ICON_CLASS);
});
this.When('I logout', function() {
loginPage.openSideMenu();
loginPage.clickLogout();
loginPage.clickLogoutPopup();
});
this.Then('I should be able to see login page', {timeout: 120 * 1000}, async function () {
expect(await element(by.id(loginPage.LOGIN_BUTTON_ID)).isPresent()).to.equal(true);
});
};
【问题讨论】:
标签: automation protractor qa