【发布时间】:2016-06-03 09:51:34
【问题描述】:
我正在尝试为 Xamarin.Forms 项目创建 UITest。在 Android 上进行测试。 我尝试使用Xamarin forum 上的一些 inf,但没有成功。
选择器的国家/地区列表:
List<country> countryList = new List<country>({id="GB", name="United Kingdom"}, {id="US", name="United States"}.... etc);
选择器代码:
var countryPicker = new Picker();
countryPicker.SetBinding(Picker.SelectedIndexProperty, "myIndex");
countryPicker.BindingContext = getCountry;
countryPicker.BackgroundColor = Color.White;
countryPicker.AutomationId = "countryPicker";
countryPicker.SelectedIndexChanged += ((s, e) =>
{
foreach (var element in countryList)
{
if (element.name.Equals(countryPicker.Items[countryPicker.SelectedIndex]))
{
getCountry.myCountry = element.id;
}
}
});
//adding all the countries to the list
foreach (var item in countryList)
{
countryPicker.Items.Add(item.name);
}
单元代码:
app.Query(c=>c.Marked("countryPicker").Invoke("selectValue", "United States"));
答案:查询 Marked("countryPicker").Invoke("selectValue", "United States") 得到 1 个结果。 但是什么都没有发生——选择还没有完成! 我尝试将值选择为“US” - 相同,没有结果。
我错过了什么吗?
【问题讨论】:
-
我很确定
AppQuery.Invoke会尝试在本机视图上调用方法(所以UIPickView或Spinner)。我猜您需要根据平台更改Invoke调用,并使用平台选择器支持的任何方法来设置选择。
标签: unit-testing xamarin nunit xamarin.forms ui-testing