我正在为角度应用程序在量角器中编写e2e测试。
我有一个流程,用户在每一步输入一些数据,我使用服务来保存这些数据,并通过getter和setter方法将重要部分传递给流程的下一步。
在调用browser.get之前,我似乎无法让量角器调用这些setter方法,因此页面无法正确加载。
下面是一些剥离后的代码。
希望这是有道理的。提前感谢您提供的任何帮助。
流程步骤1 - 通过quotesService setter methods
设置数据function _check_property_type(question, answer) {
if (question === 'property_type') {
$scope.borrowing_soon.is_required = true;
quotesService.setPropertyType(answer);
return true;
}
return false;
}
function _check_reason(question, answer) {
if (question === 'reason') {
$scope.property_type.is_required = true;
quotesService.setReason(answer);
return true;
}
return false;
}
流程步骤2 - 通过getter方法从quotesService获取数据
data.reason = quotesService.getReason()
data.property_type = quotesService.getPropertyType()
quotesService
var propertyType;
var reason;
function setPropertyType(answer){
propertyType = answer;
}
function getPropertyType(){
return propertyType;
}
function setReason(answer){
reason = answer;
}
function getReason(){
return reason;
}
量角器测试
function get(reason, property_type) {
browser.get(
'quotes.html#/step_2'
);
**** Need to set the variables here. ****
--------
// this is how its done for cookies.
// browser.manage().addCookie('reason', reason);
// browser.manage().addCookie('property_type', property_type);
--------
browser.refresh();
}