gpt4 book ai didi

unit-testing - nunit UITest xamarin.forms : how to scroll a picker?

转载 作者:行者123 更新时间:2023-12-04 02:11:37 25 4
gpt4 key购买 nike

我正在尝试为 Xamarin.Forms 项目创建 UITest。在 Android 上进行测试。我尝试使用 Xamarin forum 上可用的一些信息但没有运气。

选择器的国家/地区列表:

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”的值 - 相同,没有结果。

我错过了什么吗?

最佳答案

打开 Xamarin.Form 选择器、选择和测试结果(仅限 Android):

// Open up the picker
app.Tap(x => x.Marked("countryPicker"));

// Try to scroll and find the text item only 5 times
for (int i = 0; i< 5; i++)
{
if (app.Query(m => m.Text("United States")).Length == 0)
app.ScrollDown(x => x.Id("select_dialog_listview"));
else
{
app.Tap(x => x.Text("United States"));
break;
}
}
Assert.IsTrue(app.Query("countryPicker")[0].Text == "United States");

打开 Xamarin.Form 选择器、选择和测试结果(仅限 iOS):

/// Open up the picker
app.Tap(x => x.Marked("countryPicker"));

// Assuming a single column picker
var picker = app.Query(x => x.Class(pickerClass).Index(0));
// Try to scroll and find the text item only 5 times
for (int i = 0; i < 5; i++)
{
if (app.Query(m => m.Text("United States")).Length == 0)
app.ScrollDown(x => x.Class("UIPickerTableView").Index(0));
else
{
app.Tap(x => x.Text("United States"));
break;
}
}
app.Tap(x => x.Class("UIToolbarTextButton"));
Assert.IsTrue(app.Query("countryPicker")[0].Text == "United States");

关于unit-testing - nunit UITest xamarin.forms : how to scroll a picker?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37611170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com