【发布时间】:2017-03-09 22:15:21
【问题描述】:
我可能遇到不寻常的情况,我必须从帮助文件中的元素中获取文本,然后在规范文件中比较该文本。例如:
两个页面文件:
this.matchText = function(elem) {
return elem.getText();
};
帮助文件:
// page objects
var calculationPage = require('../calculation_page/calculation_page.js');
// variables
var globalPrice = "";
module.exports = exports = function() {
describe('...
it('...
// initialize page object
var calculation = new calculationPage();
// store price into global variable
calculation.matchText(calculation.price).then(function(text) {
globalPrice = text;
});
// verify price equals expected
expect(calculation.matchText(calculation.priceSum)).toContain(globalPrice);
???
});
});
}
如何将 globalPrice 存储为可以传递给规范文件的变量?
规格文件:
// page objects
var homePage = require('../home_page/home_page.js');
// helpers
var getPrice = require('../helpers/get_price.js');
describe('...
it('...
// helper - get price
getPrice();
// initialize page object
var home = new homePage();
// verify if price equals expected
expect(home.matchText(home.price)).toContain(???);
});
});
如何从规范文件中的帮助文件中读取全局变量?
【问题讨论】:
-
为什么您的帮助文件中有
describe、it和expect块? -
因为目前我在一个规范中将它们称为助手,但会将它们更改为规范文件。
标签: protractor global-variables helper