【发布时间】:2017-08-18 13:45:08
【问题描述】:
我正在使用 Protractor 和 Cucumber 执行自动化。我有一个场景,我需要在函数 B 中使用函数 A 的输出。在不使用 cucumber 的情况下,我可以使用 then 扩展函数。但是使用黄瓜我无法做到这一点。
有人可以建议如何使用黄瓜来做到这一点。
功能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();
});
});
});
功能 B
Then('defij', function (done) {
console.log(cityCountyLabel);
done();
});
我想在函数 B 中使用cityCountyLabel
这是我的 pageObject.js 文件。
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();
【问题讨论】:
标签: javascript selenium-webdriver gruntjs protractor cucumber