Xamarin 表单更改 UI 测试的时间选择器值
Xamarin forms changing time picker value for UI test
在下面时间选择器的 Xamarin 表单中
如何更改 xamarin UI 测试的时间选择器值。
我可以打开时间选择器但不确定如何更改时间。
这是时间选择器的 app.Repl() 树的屏幕截图。
这是我尝试更改时间的尝试。
app.WaitForElement(c => c.Marked("hours"));
app.Tap(c => c.Marked("hours"));
app.EnterText(c => c.Marked("hours"), newHours) // errors can't pull up keyboard
我发现处理日期和时间控件的最简单方法是使用 Invoke 方法访问 time/date 选择器控件中公开的后门。
// invokes a method to input the hour into the picker, time format is 24 hour
app.Query(c => c.Class("RadialTimePickerView").Invoke("setCurrentHour", (int)hour));
// invokes a method to input the minute into the picker
app.Query(c => c.Class("RadialTimePickerView").Invoke("setCurrentMinute", (int)minute));
日期选择器非常相似,但它不需要两个单独的方法,而是只使用一个。
// invokes a method to input the date into the picker, where month starts from 0
app.Query(c => c.Raw("DatePicker").Invoke("updateDate", (int)year, (int)month - 1, (int)day));
我建议使用这个特殊的后门,因为它适用于各种 android 版本,因为 android 的每个版本都有稍微不同的 date/time 选择器样式。
在下面时间选择器的 Xamarin 表单中
如何更改 xamarin UI 测试的时间选择器值。 我可以打开时间选择器但不确定如何更改时间。 这是时间选择器的 app.Repl() 树的屏幕截图。
这是我尝试更改时间的尝试。
app.WaitForElement(c => c.Marked("hours"));
app.Tap(c => c.Marked("hours"));
app.EnterText(c => c.Marked("hours"), newHours) // errors can't pull up keyboard
我发现处理日期和时间控件的最简单方法是使用 Invoke 方法访问 time/date 选择器控件中公开的后门。
// invokes a method to input the hour into the picker, time format is 24 hour
app.Query(c => c.Class("RadialTimePickerView").Invoke("setCurrentHour", (int)hour));
// invokes a method to input the minute into the picker
app.Query(c => c.Class("RadialTimePickerView").Invoke("setCurrentMinute", (int)minute));
日期选择器非常相似,但它不需要两个单独的方法,而是只使用一个。
// invokes a method to input the date into the picker, where month starts from 0
app.Query(c => c.Raw("DatePicker").Invoke("updateDate", (int)year, (int)month - 1, (int)day));
我建议使用这个特殊的后门,因为它适用于各种 android 版本,因为 android 的每个版本都有稍微不同的 date/time 选择器样式。