I am using UIAutomation to test our apps. What I want to do is: select a random date on a datePicker any day before today (in the same year). I already got the a random month and day value. Here is my code:
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);
I have checked the valueAtIndex
variable does return a month for example "March" and the randomDay
variable does return a day for example "9".
As soon as I use the selectValue()
method instruments throw an error: - selectValue requires a valid value.
The setValue()
method does not work either.
How will I go about to tell the picker to get the random month and day generated?