【发布时间】:2014-09-01 00:41:27
【问题描述】:
我正在使用 UIAutomation 来测试我们的应用。我想要做的是:在今天之前的任何一天(同年)在 datePicker 上选择一个随机日期。我已经得到了随机的月份和日期值。这是我的代码:
var currDate = new Date();
var year = currDate.getFullYear();
var month = new Array;
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
var setMonthInt = currDate.getMonth();
var day = currDate.getDate();
var randomMonth = Math.floor((Math.random() * (setMonthInt + 1 - 0)) + 0);
var valueAtIndex = "\"" + month[randomMonth] + "\"";
if (randomMonth == setMonthInt){
var randomDay = "\"" + Math.floor((Math.random() * (day)) + 1) + "\"";
} else {
var randomDay = "\"" + Math.floor((Math.random() * (32)) + 1) + "\"";
}
this.window().popover().pickers()[0].wheels()[1].selectValue(valueAtIndex);
this.window().popover().pickers()[0].wheels()[0].selectValue(randomDay);
我检查了valueAtIndex 变量确实返回一个月,例如“三月”,randomDay 变量确实返回一天,例如“9”。
只要我使用selectValue() 方法,仪器就会抛出错误:- selectValue requires a valid value.
setValue() 方法也不起作用。
我将如何告诉选择器生成随机的月份和日期?
【问题讨论】:
-
我认为这条线
Math.floor((Math.random() * (32)) + 1)可以返回32作为可能的一天。 32 * .99 向下舍入是 31 + 1 是 32。也许这就是导致错误的原因? -
@Braains 这不是问题,32 不包含在返回值中
标签: javascript ios ipad ui-automation ios-ui-automation