我正在使用 Xamarin UI 测试 (1.0.0)。我正在尝试编写一个扩展方法来更新所选日期。这是我到目前为止所写的。它适用于 iOS 和 Android 4.x。它不适用于 Android 5.x。
public static void EnterDate(this IApp app, string datePickerStyleId, DateTime date)
{
var array = app.Query(datePickerStyleId);
if (array.Length == 0)
return;
foreach (var picker in array)
{
var newMonth = date.ToString("MMM");
var newDay = date.Day.ToString();
var newYear = date.Year.ToString();
if (app.IsAndroid())
{
app.Tap(picker.Label);
//if device OS > 5 try scrolll up
app.Repl();
app.Screenshot("Date Picker");
app.Tap("month");
app.EnterText(newMonth);
app.PressEnter();
app.Tap("day");
app.EnterText(newDay);
app.PressEnter();
app.Tap("year");
app.EnterText(newYear);
app.PressEnter();
app.ClickDone();
app.Screenshot("Page After Changing Date");
app.ClickButton("Ok");
}
else if (app.IsIOS())
{
app.Tap(picker.Id);
app.Screenshot("Date Picker");
var currentDate = picker.Text;
var split = currentDate.Split(' ');
var currentMonth = split[0];
var currentDay = split[1].Remove(split[1].Length - 1);
var currentYear = split[2];
if (!newMonth.Equals(currentMonth))
{
app.Tap(newMonth);
}
if (!newDay.Equals(currentDay))
{
app.Tap(newDay);
}
if (!newYear.Equals(currentYear))
{
app.Tap(newYear);
}
app.ClickButton("Done");
}
}
}
我遇到的问题是我不知道如何选择某个日期。App.ScrollUp()/.ScrollDown() 确实可以导航到不同的月份。虽然,我还没有找到确定当前月份然后选择一天。这是 Repl() 工具的 tree 命令的输出。
tree [[object CalabashRootView] > ... > FrameLayout] [FrameLayout] id: "content" [LinearLayout] id: "parentPanel" [FrameLayout] id: "customPanel" [FrameLayout] id: "custom" [DatePicker > LinearLayout] id: "datePicker" [LinearLayout] id: "day_picker_selector_layout"
[TextView] id:“date_picker_header”文本:“Thursday”[LinearLayout] id:“date_picker_month_day_year_layout”[LinearLayout] id:“date_picker_month_and_day_layout”,标签:“8 月 6 日”[TextView] id:“date_picker_month”文本:“AUG”[ TextView] id: "date_picker_day" text: "6" [TextView] id: "date_picker_year" text: "2015" [AccessibleDateAnimator > ... > SimpleMonthView] id: "animator", label: "月份日期:8 月 6 日" [LinearLayout] id: "buttonPanel" [Button] id: "button2" text: "Cancel"[按钮] id:“button1”文本:“确定”
有人知道或有方法选择适用于 iOS 和 Android(4.x 和 5.x)的 Xamarin UI 测试日期吗?