Data-Driven Testing in Protractor

前端 未结 5 1131
南笙
南笙 2020-12-11 07:28

I am new to protractor. Can anyone please guide me for data driven testing using protractor. Below is the code, config file and testdata.json file.

\'use st         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-11 08:13

    I am assuming its an Array of objects, you can iterate each array element and directly access its contents and you don't need testdata.forEach(), you could try something like this -

     'use strict';
    
    var testData = require('../example/Test Data/Test.json');
    
    describe('LoginPage', function() {
    
    it("data.description", function () {
        browser.get("http://127.0.0.1:8080/#/login");
        element(by.model("username")).sendKeys(testData[0].username);
        element(by.model("password")).sendKeys(testData[0].passwordField); 
        element(by.buttonText("Authenticate")).click();
    
       });
      });
     });  
    

    I haven't tested the above code and you should use Page Objects rather than directly using them in your tests!

提交回复
热议问题