【发布时间】:2015-09-24 13:41:53
【问题描述】:
我正在编写一个测试,它读取一个字符串,然后获取该字符串并将其应用于 switch 语句。然后我将字符串与大小写匹配并设置一个整数值,我将其传递回规范页面,然后将 int 值传递给我用于 if 语句的另一个测试。我无法让 int 通过,因此 if 语句将无法正常工作。
开关对象:
var appsNotPurchased = 0;
this.checksHomeSublevel = function(mmCode) {
browser.get('https://iplan-qa.meetingmatrix.com/Home/Index/' + mmCode);
marketingObjects.level.getText().then(function(text) {
var homeText = text;
browser.get('https://iplan-qa.meetingmatrix.com/Home/Apps/' + mmCode);
expect($('div.apps-subscription > span').getText()).toEqual('iPlan Level: ' + homeText);
switch (homeText) {
case 'Select':
console.log(homeText);
appsNotPurchased = 6;
return appsNotPurchased;
break;
case 'Content':
console.log(homeText);
appsNotPurchased = 0 || 1 || 2 || 3 || 4 || 5 || 6;
return appsNotPurchased;
break;
}
});
testSpec 描述函数:
describe('should upload media: ', function() {
it('should select add media', function() {
var mmCode = "ACC0572";
var appsNotPurchased = appsObjects.checksHomeSublevel(mmCode);
appsObjects.checksSubLevelSelect(mmCode, appsNotPurchased);
});
});
我将值传递给的对象:
this.checksSubLevelSelect = function(mmCode, appsNotPurchased) {
//counts the apps
apps.count().then(function(count) {
expect(count).toEqual(7);
for (var i = 0; i < count; i++) {
if (appsPlace == appsNotPurchased) {
//does something here
} else {
//does something here
}
appsPlace++;
}
});
};
【问题讨论】:
-
我建议在你的代码中使用更多的空白,这样会更容易阅读(至少对我来说:-)
-
你应该在你的
return语句之后添加一个default: return 'None of the above';case并删除break;语句(return无论如何都会break它)。如果它返回上面的那句话,您就知道您的案例不匹配。提示:总是将default提供给switch语句。 -
homeText 总是“选择”还是“内容”?由于您没有默认返回值。
appsNotPurchased = 0 || 1 || 2 || 3 || 4 || 5 || 6;正确吗?因为它总是 1,所以它是第一个真值。 -
@NicolePhillips:Shilly 所说的第二部分是
0 || 1 || 2 || 3 || 4 || 5 || 6只是写1的一种非常长且不清楚的方式。该值将始终为1。里面没有任何条件。 -
@NicolePhillips 这不是它的工作原理。
||或运算符将返回第一个不是falsy的值,因此是数字1
标签: javascript angularjs selenium-webdriver switch-statement protractor