我正在测试一个时间选择器,我想测试一次AM,PM格式和一次24小时格式,有没有办法通过xamarin.uitest项目设置安卓日期格式?

发布于 2021-01-13 16:57:36
你可以试试下面的代码。
[Test]
public void timePickerTest()
{
app.Tap("TimePickerElement");
SetTimePicker(1, 16, false);
app.Screenshot("new time set");
app.Back();
}
public void SetTimePicker(int hour, int minute, bool am)
{
string hourString = hour.ToString();
string minuteString = minute.ToString();
DateTime date = DateTime.Now;
DateTime time = new DateTime(date.Year, date.Month, date.Day, hour, minute, 0);
int ampm;
if (am)
{
ampm = 0;
}
else ampm = 1;
if (platform == Platform.iOS)
{
app.Query(x => x.Class("UIPickerView").Invoke("selectRow", time.Hour, "inComponent", 0, "animated", true)); //if time.Hour == 0, than hour is '1'. if time.Hour == 11, than hour is '12'
app.Query(x => x.Class("UIPickerView").Invoke("selectRow", time.Minute, "inComponent", 1, "animated", true)); //if time.Minute == 0, than minutes is '1'. if time.Minute == 59, than minutes is '59'
app.Query(x => x.Class("UIPickerView").Invoke("selectRow", ampm, "inComponent", 2, "animated", true)); //0 == AM and 1 == PM
}
else // Android
{
// switch to Text entry for time
app.Tap("toggle_mode");
// hour
app.ClearText();
app.EnterText(hourString);
// minute
app.ClearText("input_minute");
app.EnterText(minuteString);
// AM/PM
if (!am)
{
app.Tap("AM"); // opens spinner
app.Tap("PM"); // changes to PM
}
app.Tap("OK"); // finalize time
}
}https://stackoverflow.com/questions/65680626
复制相似问题