Skip to content

Commit 9c43dbc

Browse files
committed
Added base changes to include main App driver property to differentiate between the web driver and a base access driver (strictly naming convention change)
1 parent 994e5e8 commit 9c43dbc

File tree

4 files changed

+46
-28
lines changed

4 files changed

+46
-28
lines changed
140 KB
Binary file not shown.
140 KB
Binary file not shown.

src/Legerity.Core/AppManager.cs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,30 @@ public static class AppManager
2626
/// <summary>
2727
/// Gets the instance of the started Windows application.
2828
/// </summary>
29-
public static WindowsDriver<WindowsElement> WindowsApp => WebApp as WindowsDriver<WindowsElement>;
29+
public static WindowsDriver<WindowsElement> WindowsApp => App as WindowsDriver<WindowsElement>;
3030

3131
/// <summary>
3232
/// Gets the instance of the started Android application.
3333
/// </summary>
34-
public static AndroidDriver<AndroidElement> AndroidApp => WebApp as AndroidDriver<AndroidElement>;
34+
public static AndroidDriver<AndroidElement> AndroidApp => App as AndroidDriver<AndroidElement>;
3535

3636
/// <summary>
3737
/// Gets the instance of the started iOS application.
3838
/// </summary>
39-
public static IOSDriver<IOSElement> IOSApp => WebApp as IOSDriver<IOSElement>;
39+
public static IOSDriver<IOSElement> IOSApp => App as IOSDriver<IOSElement>;
4040

4141
/// <summary>
4242
/// Get the instance of the started web application.
4343
/// </summary>
44-
public static RemoteWebDriver WebApp { get; set; }
44+
public static RemoteWebDriver WebApp => App;
45+
46+
/// <summary>
47+
/// Gets the instance of the started application.
48+
/// <para>
49+
/// This could be a <see cref="WindowsDriver{W}"/>, <see cref="AndroidDriver{W}"/>, <see cref="IOSDriver{W}"/>, or web driver.
50+
/// </para>
51+
/// </summary>
52+
public static RemoteWebDriver App { get; set; }
4553

4654
/// <summary>
4755
/// Starts the application ready for testing.
@@ -62,29 +70,29 @@ public static void StartApp(AppManagerOptions opts)
6270
{
6371
case WebAppManagerOptions webOpts:
6472
{
65-
WebApp = webOpts.DriverType switch
73+
App = webOpts.DriverType switch
6674
{
6775
WebAppDriverType.Chrome => new ChromeDriver(webOpts.DriverUri),
6876
WebAppDriverType.Firefox => new FirefoxDriver(webOpts.DriverUri),
6977
WebAppDriverType.Opera => new OperaDriver(webOpts.DriverUri),
7078
WebAppDriverType.Safari => new SafariDriver(webOpts.DriverUri),
7179
WebAppDriverType.Edge => new EdgeDriver(webOpts.DriverUri),
7280
WebAppDriverType.InternetExplorer => new InternetExplorerDriver(webOpts.DriverUri),
73-
_ => WebApp
81+
_ => App
7482
};
7583

76-
VerifyAppDriver(WebApp, webOpts);
84+
VerifyAppDriver(App, webOpts);
7785

7886
if (webOpts.Maximize)
7987
{
80-
WebApp.Manage().Window.Maximize();
88+
App.Manage().Window.Maximize();
8189
}
8290
else
8391
{
84-
WebApp.Manage().Window.Size = webOpts.DesiredSize;
92+
App.Manage().Window.Size = webOpts.DesiredSize;
8593
}
8694

87-
WebApp.Url = webOpts.Url;
95+
App.Url = webOpts.Url;
8896
break;
8997
}
9098
case WindowsAppManagerOptions winOpts:
@@ -94,22 +102,23 @@ public static void StartApp(AppManagerOptions opts)
94102
WinAppDriverHelper.Run();
95103
}
96104

97-
WebApp = new WindowsDriver<WindowsElement>(
105+
App = new WindowsDriver<WindowsElement>(
98106
new Uri(winOpts.DriverUri),
99107
winOpts.AppiumOptions);
100108

101109
VerifyAppDriver(WindowsApp, winOpts);
102110

103111
if (winOpts.Maximize)
104112
{
105-
WebApp.Manage().Window.Maximize();
113+
App.Manage().Window.Maximize();
106114
}
115+
107116
break;
108117
}
109118

110119
case AndroidAppManagerOptions androidOpts:
111120
{
112-
WebApp = new AndroidDriver<AndroidElement>(
121+
App = new AndroidDriver<AndroidElement>(
113122
new Uri(androidOpts.DriverUri),
114123
androidOpts.AppiumOptions);
115124

@@ -119,7 +128,7 @@ public static void StartApp(AppManagerOptions opts)
119128

120129
case IOSAppManagerOptions iosOpts:
121130
{
122-
WebApp = new IOSDriver<IOSElement>(new Uri(iosOpts.DriverUri), iosOpts.AppiumOptions);
131+
App = new IOSDriver<IOSElement>(new Uri(iosOpts.DriverUri), iosOpts.AppiumOptions);
123132

124133
VerifyAppDriver(IOSApp, iosOpts);
125134
break;
@@ -132,10 +141,10 @@ public static void StartApp(AppManagerOptions opts)
132141
/// </summary>
133142
public static void StopApp()
134143
{
135-
if (WebApp != null)
144+
if (App != null)
136145
{
137-
WebApp.Quit();
138-
WebApp = null;
146+
App.Quit();
147+
App = null;
139148
}
140149

141150
WinAppDriverHelper.Stop();

src/Legerity.Core/Pages/BasePage.cs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace Legerity.Pages
22
{
33
using System;
4+
45
using Legerity.Exceptions;
56

67
using OpenQA.Selenium;
@@ -42,11 +43,19 @@ protected BasePage()
4243

4344
/// <summary>
4445
/// Gets the instance of the started web application.
46+
/// </summary>
47+
protected RemoteWebDriver WebApp => AppManager.WebApp;
48+
49+
/// <summary>
50+
/// Gets the instance of the started application.
51+
/// <para>
52+
/// The <see cref="App"/> instance serves as base for the drivers and can be referenced for basic Selenium functions.
53+
/// </para>
4554
/// <para>
46-
/// The <see cref="WebApp"/> instance also serves as base for the Appium drivers and can be referenced for basic Selenium functions.
55+
/// This could be a <see cref="WindowsDriver{W}"/>, <see cref="AndroidDriver{W}"/>, <see cref="IOSDriver{W}"/>, or web driver.
4756
/// </para>
4857
/// </summary>
49-
protected RemoteWebDriver WebApp => AppManager.WebApp;
58+
protected RemoteWebDriver App => AppManager.App;
5059

5160
/// <summary>
5261
/// Gets a given trait of the page to verify that the page is in view.
@@ -73,24 +82,24 @@ public void VerifyPageShown()
7382
/// <exception cref="T:Legerity.Exceptions.PageNotShownException">Thrown if the page is not shown.</exception>
7483
public void VerifyPageShown(TimeSpan? timeout)
7584
{
76-
if (this.WebApp == null)
85+
if (this.App == null)
7786
{
7887
throw new DriverNotInitializedException(
7988
$"An app driver has not been initialized. Call 'AppManager.StartApp()' with an instance of an {nameof(AppManagerOptions)} to setup for testing.");
8089
}
8190

8291
if (timeout == null)
8392
{
84-
if (this.WebApp != null && this.WebApp.FindElement(this.Trait) == null)
93+
if (this.App != null && this.App.FindElement(this.Trait) == null)
8594
{
8695
throw new PageNotShownException(this.GetType().Name);
8796
}
8897
}
8998
else
9099
{
91-
if (this.WebApp != null)
100+
if (this.App != null)
92101
{
93-
AttemptWaitForDriverElement(this.Trait, timeout.Value, this.WebApp);
102+
AttemptWaitForDriverElement(this.Trait, timeout.Value, this.App);
94103
}
95104
}
96105
}
@@ -121,24 +130,24 @@ public void VerifyElementShown(By by)
121130
/// <exception cref="T:Legerity.Exceptions.ElementNotShownException">Thrown if the element is not shown.</exception>
122131
public void VerifyElementShown(By by, TimeSpan? timeout)
123132
{
124-
if (this.WebApp == null)
133+
if (this.App == null)
125134
{
126135
throw new DriverNotInitializedException(
127136
$"An app driver has not been initialized. Call 'AppManager.StartApp()' with an instance of an {nameof(AppManagerOptions)} to setup for testing.");
128137
}
129138

130139
if (timeout == null)
131140
{
132-
if (this.WebApp != null && this.WebApp.FindElement(by) == null)
141+
if (this.App != null && this.App.FindElement(by) == null)
133142
{
134143
throw new ElementNotShownException(by.ToString());
135144
}
136145
}
137146
else
138147
{
139-
if (this.WebApp != null)
148+
if (this.App != null)
140149
{
141-
AttemptWaitForDriverElement(by, timeout.Value, this.WebApp);
150+
AttemptWaitForDriverElement(by, timeout.Value, this.App);
142151
}
143152
}
144153
}
@@ -152,7 +161,7 @@ public void VerifyElementShown(By by, TimeSpan? timeout)
152161
/// <exception cref="T:Legerity.Exceptions.DriverNotInitializedException">Thrown if AppManager.StartApp() has not been called.</exception>
153162
public void VerifyElementNotShown(By by)
154163
{
155-
if (this.WebApp == null)
164+
if (this.App == null)
156165
{
157166
throw new DriverNotInitializedException(
158167
$"An app driver has not been initialized. Call 'AppManager.StartApp()' with an instance of an {nameof(AppManagerOptions)} to setup for testing.");

0 commit comments

Comments
 (0)