-
Notifications
You must be signed in to change notification settings - Fork 4
UI extensions
MilleBo edited this page Mar 6, 2017
·
5 revisions
Ui extensions is a way to hijack the UIService so before we look for element x we do y. An example of this could be looking for dialogs, error message or loading bars.
public class UiLoadingExtension : IUiExtension
{
// A flag to temporary disable this extension
private bool _isWaiting;
private readonly With _loadingWith;
private UiLoadingExtension()
{
_loadingWith = With.ResourceId("loadingId");
}
public bool CheckNodes(IList<Node> nodes, IAndroidDevice device)
{
if (nodes.Any(_loadingWith.NodeSearche) && !_isWaiting)
{
WaitForLoading(nodes, device);
// Reset the wait timer for the actual object we're looking for.
return true;
}
return false;
}
private void WaitForLoading(IList<Node> nodes, IAndroidDevice device)
{
_isWaiting= true;
var loading = device.Ui.CreateUiObject(_loadingWith);
loading.IsHidden(180);
_isWaiting= false;
}
}And then you add this to your device ui service
var device = new AndroidDevice(new DeviceConfiguration());
device.Ui.Extensions.Add(new UiLoadingExtension());