selenium webdriver - How to use parameters in one function in another using Javascript -
i performing automation using protractor , cucumber. have scenario need use output of function in function b. in normal way without using cucumber able extend function using then
. using cucumber unable this.
can please suggest how using cucumber.
function a
then('abc', function (done) { search.citycountydropdown.click(); search.citycounty.count().then(function(count) { search.citycountycount = count; search.randomcitycountyindex = ( 1 + math.floor(math.random() * (search.citycountycount - 1)) ); }) .then(function() { search .citycounty .get(search.randomcitycountyindex) .gettext() .then(function(citycountylabel) { search.selectcitycountylabel(citycountylabel); console.log(citycountylabel); done(); }); }); });
function b
then('defij', function (done) { console.log(citycountylabel); done(); });
i wanted use citycountylabel
in function b
here pageobject.js file.
var searchpage = function () { this.category = element(by.css('[href="/abc/"]')); this.header = element(by.id('abc')); this.citycountydropdown = element(by.id('abc')); this.citycounty = element.all(by.xpath("//*[@id='abc']/dd/ul/li")); this.citycountycount; this.randomcitycountyindex; this.selectcitycountylabel = function (citycountylabel) { element(by.xpath(".//*[@id='abc']/dd/ul/li[text()='" + citycountylabel + "']")).click(); }; this.submitbutton = element(by.css('input.btn-search')); this.searchresults = element.all(by.xpath("//*[@id='abc']/tbody/tr/td[1]/div[@class='abc']")); this.searchresultscount; this.randomsearchresultsindex; this.randomsearchresult = function (randomsearchresultsindex, searchresult) { return element(by.xpath(".//*[@id='abc']/tbody/tr/td[1]/div[@class='abc'][" + randomsearchresultsindex + "]/div[1]/h2/a")); } this.addressregex; } module.exports = new searchpage();
in cucumber pass data between steps using world, available this
in steps. example code:
then('abc', function (done) { this["citycountylabel"] = "data"; done(); }); then('defij', function (done) { // print out: "data" console.log(this["citycountylabel"]); done(); });
Comments
Post a Comment