-
Notifications
You must be signed in to change notification settings - Fork 23
/
BasePage.cs
52 lines (44 loc) · 2.11 KB
/
BasePage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using NUnit.Framework;
using Xamarin.UITest;
namespace Xamarin.UITest.POPSample
{
public abstract class BasePage
{
protected IApp app => AppManager.App;
protected bool OnAndroid => AppManager.Platform == Platform.Android;
protected bool OniOS => AppManager.Platform == Platform.iOS;
protected abstract PlatformQuery Trait { get; }
protected BasePage()
{
AssertOnPage(TimeSpan.FromSeconds(30));
app.Screenshot("On " + this.GetType().Name);
}
/// <summary>
/// Verifies that the trait is still present. Defaults to no wait.
/// </summary>
/// <param name="timeout">Time to wait before the assertion fails</param>
protected void AssertOnPage(TimeSpan? timeout = default(TimeSpan?))
{
var message = "Unable to verify on page: " + this.GetType().Name;
if (timeout == null)
Assert.IsNotEmpty(app.Query(Trait.Current), message);
else
Assert.DoesNotThrow(() => app.WaitForElement(Trait.Current, timeout: timeout), message);
}
/// <summary>
/// Verifies that the trait is no longer present. Defaults to a 5 second wait.
/// </summary>
/// <param name="timeout">Time to wait before the assertion fails</param>
protected void WaitForPageToLeave(TimeSpan? timeout = default(TimeSpan?))
{
timeout = timeout ?? TimeSpan.FromSeconds(5);
var message = "Unable to verify *not* on page: " + this.GetType().Name;
Assert.DoesNotThrow(() => app.WaitForNoElement(Trait.Current, timeout: timeout), message);
}
// You can edit this file to define functionality that is common across many or all pages in your app.
// For example, you could add a method here to open a side menu that is accesible from all pages.
// To keep things more organized, consider subclassing BasePage and including common page actions there.
// For some examples check out https://github.com/xamarin-automation-service/uitest-pop-example/wiki
}
}