json - Data-Driven Testing in Protractor -
i new protractor. can please guide me data driven testing using protractor. below code, config file , testdata.json file.
'use strict'; var testdata = require('../example/test data/test.json'); describe('loginpage', function() { var logindata = require('../example/test data/test.json'); testdata.foreach(function (data) { it("data.description", function (data) { browser.get("http://127.0.0.1:8080/#/login"); element(by.model("username")).sendkeys(data.username); element(by.model("password")).sendkeys(data.passwordfield); element(by.buttontext("authenticate")).click(); }); }); });
config file:
// example configuration file. exports.config = { directconnect: true, //seleniumaddress: 'http://localhost:4444/wd/hub', // capabilities passed webdriver instance. capabilities: { 'browsername': 'chrome' }, // framework use. jasmine recommended. framework: 'jasmine', // spec patterns relative current working directory when // protractor called. specs: ['testpage.js'], // options passed jasmine. jasminenodeopts: { defaulttimeoutinterval: 30000 } };
json file:
[ { "username": "admin", "passwordfield": "admin" }, { "username": "admin1", "passwordfield": "admin2" } ]
issue instead of taking data , writing undefined in input boxes. please help
i assuming array of objects, can iterate each array element , directly access contents , don't need testdata.foreach()
, try -
'use strict'; var testdata = require('../example/test data/test.json'); describe('loginpage', function() { var logindata = require('../example/test data/test.json'); 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 above code , should use page objects rather directly using them in tests!
Comments
Post a Comment