我可能有不寻常的情况,我必须从帮助器文件中的元素中获取文本,然后在spec文件中比较此文本。例如:量角器:从spec文件中的帮助器文件中使用变量
两个页面文件:
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存储为可能被传递到spec文件中的变量?
规格文件:
// 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'块? – Gunderson
因为目前我在一个规范中称这些为助手,但会将它们更改为spec文件。 – jurijk