ヘルパーファイルの要素からテキストを取り出して、このテキストをスペックファイルで比較する必要がある場合があります。たとえば、次のように分度器:スペックファイルのヘルパーファイルから変数を使用する
どちらのページファイル:
this.matchText = function(elem) {
return elem.getText();
};
ヘルパーファイル:ファイルを仕様に渡すことができます変数としてglobalPriceを保存する方法
// 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);
???
});
});
}
?
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(???);
});
});
どのようにスペックファイル内のヘルパーファイルからグローバル変数を読み込むには?
@私の答えを参照してください? – Gunderson
現在、私はこれをヘルパーと呼んでいますが、スペックファイルに変更します。 – jurijk