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

标签 node.js cucumber protractor

我是 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/

相关文章:

node.js - 在 Node.js Step 模块中使用参数调用下一步

ruby-on-rails - 设计表单 cucumber 方案的最佳BDD做法

maven - cucumber 和junit在jenkins中的测试量错误(万无一失)

angular - Protractor angular2 等待异步 Angular 任务完成时超时

javascript - isPresent 和 isDisplayed 方法有什么区别

android - 使用 Cordova 6.0.0 构建 Android 应用程序时出错

node.js - 我可以使用 require 获取 createSagaMiddleware 吗?

node.js - 使用 Mongoose 和 GraphQL 保存实体后数据为空

ruby - 如何使用 Aruba 测试在主文件夹中创建文件

angularjs - Angular Protractor - 在 E2E 测试后保持浏览器打开