gpt4 book ai didi

node.js - 如何根据 Excel 值多次运行 Protractor Spec

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

我是 Protractor 新手。我将测试数据存储在 Excel 中的多行中。我想为 Excel 中的每一行多次运行相同的规范。可能吗?

exports.config = {


seleniumAddress: 'http://localhost:4444/wd/hub',

baseUrl: 'https:somewebsite.com',

capabilities: {

'browserName': (process.env.TEST_BROWSER_NAME || workbook.Sheets[sheetNamelist[sheetNumber]]['N2'].v)
, 'version': (process.env.TEST_BROWSER_VERSION || 'ANY')
, 'shardTestFiles': false
, },
onPrepare: function () {
browser.ignoreSynchronization = true;
},

framework: 'custom'
, frameworkPath: require.resolve('protractor-cucumber-framework'),

specs: [
'../Features/Availity_Login.feature'
]
, exclude: '../Features/database.feature'
, cucumberOpts: {

monochrome: true
, strict: true
, plugin: ["pretty"]
, require: ['../StepDefinitions/*.js', '../Support/*.js']
, tags: '@AllureScenario,@Regression,@ProtractorScenario,~@DatabaseTest' // @DatabaseTest scenario can be included when the username & password of DB have been configured in Support/database.js

}


};

在上面的脚本中,我想多次运行规范,因为我的 Excel 中有多个测试数据。我可以使用模块“xlsjs”读取 Excel 值。循环遍历规范将仅在第一次运行规范。

最佳答案

使用多组数据测试相同的功能只不过是数据驱动方法。为此,我们有 jasmine-data-provider 包,它将帮助您使用 Protractor 进行数据驱动测试。

Code Snippet:

var using = require(‘jasmine-data-provider);
var loginData = require('../example/Test Data/Test.json');


describe('Data driven test spec', function () {
/*define sets of input data as array in method called arrayOfData*/
//OR retrieve all test data and stored into array and the follow below
//approach

function arrayOfData() {
return [
{
"username": "admin",
"passwordField": "admin"
},

{
"username": "admin1",
"passwordField": "admin2"
}
]
} /*below one will loop the test case based on data size and pass single
data set every time till complete the end of array*/

using(arrayofData, function (inputData) {
it('test case logic to be executed for each set of data', function ()
{
browser.get("http://127.0.0.1:8080/#/login");
element(by.model("username")).sendKeys(inputData.username);
element(by.model("password")).sendKeys(inputData.passwordField);
element(by.buttonText("Authenticate")).click();
});
});
});

注意:如果您的计算机上尚未安装 jasmine-data-provider 软件包,请在运行测试脚本之前通过运行以下命令来安装它。

npm install jasmine-data-provider

关于node.js - 如何根据 Excel 值多次运行 Protractor Spec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38747466/

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