Xamarin.UITest:如何判断Xamarin.Forms.ListView是否刷新?
Xamarin.UITest: How to Determine If Xamarin.Forms.ListView Is Refreshing?
在 Xamarin.UITest 中,如何确定 Xamarin.Forms.ListView
是否正在刷新?
当我执行 app.Query(x => x.Class("ListViewRenderer"))
时,我只得到这些结果:
Query for Class("ListViewRenderer") gave 1 results.
[
[0] {
Id => null,
Description => "md51558244f76c53b6aeda52c8a337f2c37.ListViewRenderer{b749570 V.E...... ........ 0,0-1080,1536}",
Rect => {
Width => 1080,
Height => 1536,
X => 0,
Y => 240,
CenterX => 540,
CenterY => 1008
},
Label => null,
Text => null,
Class => "md51558244f76c53b6aeda52c8a337f2c37.ListViewRenderer",
Enabled => true
}
]
更多信息,我整理了这篇博客post:https://codetraveler.io/2019/10/03/xamarin-uitest-determine-if-xamarin-forms-listview-is-refreshing/
Android
要与来自 Xamarin.UITest 的 Android 上的 ListView 交互,您必须使用 Invoke method to access the methods in the native Java Android API。
在 Android 上,我们可以像这样检查从 SwipeRefreshLayout.isRefreshing()
返回的值:
(bool)(app.Query(x => x.Class("ListViewRenderer_SwipeRefreshLayoutWithFixedNestedScrolling").Invoke("isRefreshing")).FirstOrDefault();
iOS
对于iOS,我们可以检查UIRefreshControl
是否可见:
app.Query(x => x.Class("UIRefreshControl")).Any()
代码示例
public bool GetIsRefreshIndicatorDisplayed(Xamarin.UITest.IApp app)
{
if (app is AndroidApp)
return (bool)(app.Query(x => x.Class("ListViewRenderer_SwipeRefreshLayoutWithFixedNestedScrolling")?.Invoke("isRefreshing"))?.FirstOrDefault() ?? false);
if (app is iOSApp)
return app.Query(x => x.Class("UIRefreshControl"))?.Any() ?? false;
throw new NotSupportedException("Xamarin.UITest only supports Android and iOS");
}
示例应用程序
这是我成功实施此方法的示例应用程序:https://github.com/brminnick/UITestSampleApp/blob/master/Src/UITestSampleApp.UITests/Pages/ListPage.cs
在 Xamarin.UITest 中,如何确定 Xamarin.Forms.ListView
是否正在刷新?
当我执行 app.Query(x => x.Class("ListViewRenderer"))
时,我只得到这些结果:
Query for Class("ListViewRenderer") gave 1 results.
[
[0] {
Id => null,
Description => "md51558244f76c53b6aeda52c8a337f2c37.ListViewRenderer{b749570 V.E...... ........ 0,0-1080,1536}",
Rect => {
Width => 1080,
Height => 1536,
X => 0,
Y => 240,
CenterX => 540,
CenterY => 1008
},
Label => null,
Text => null,
Class => "md51558244f76c53b6aeda52c8a337f2c37.ListViewRenderer",
Enabled => true
}
]
更多信息,我整理了这篇博客post:https://codetraveler.io/2019/10/03/xamarin-uitest-determine-if-xamarin-forms-listview-is-refreshing/
Android
要与来自 Xamarin.UITest 的 Android 上的 ListView 交互,您必须使用 Invoke method to access the methods in the native Java Android API。
在 Android 上,我们可以像这样检查从 SwipeRefreshLayout.isRefreshing()
返回的值:
(bool)(app.Query(x => x.Class("ListViewRenderer_SwipeRefreshLayoutWithFixedNestedScrolling").Invoke("isRefreshing")).FirstOrDefault();
iOS
对于iOS,我们可以检查UIRefreshControl
是否可见:
app.Query(x => x.Class("UIRefreshControl")).Any()
代码示例
public bool GetIsRefreshIndicatorDisplayed(Xamarin.UITest.IApp app)
{
if (app is AndroidApp)
return (bool)(app.Query(x => x.Class("ListViewRenderer_SwipeRefreshLayoutWithFixedNestedScrolling")?.Invoke("isRefreshing"))?.FirstOrDefault() ?? false);
if (app is iOSApp)
return app.Query(x => x.Class("UIRefreshControl"))?.Any() ?? false;
throw new NotSupportedException("Xamarin.UITest only supports Android and iOS");
}
示例应用程序
这是我成功实施此方法的示例应用程序:https://github.com/brminnick/UITestSampleApp/blob/master/Src/UITestSampleApp.UITests/Pages/ListPage.cs