Skip to content

Commit a40ef4e

Browse files
author
Pavel Anihimovsky
committed
Update README
1 parent 55eaf7c commit a40ef4e

File tree

1 file changed

+44
-26
lines changed

1 file changed

+44
-26
lines changed

README.md

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -80,67 +80,85 @@ namespace Aquality.Appium.Mobile.Tests.Samples.Android.ApiDemosScreens
8080

8181
### ScreenFactory
8282

83-
When you automate tests for both iOS and Android platforms it is good to have only one set of tests and different implementations of screens. `ScreenFactory` allows to do this. You can define interfaces for your screens and have different implementations for iOS and Android platforms. And then use `ScreenFactory` to resolve necessary screen depending on the chosen platform.
83+
When you automate tests for both iOS and Android platforms it is good to have only one set of tests and different implementations of screens. `ScreenFactory` allows to do this. You can define abstract classes for your screens and have different implementations for iOS and Android platforms. After that you can use `ScreenFactory` to resolve necessary screen depending on the chosen platform.
8484

8585
1. Set `screensLocation` property in `settings.json`. It is a name of Assembly where you define screens.
8686

87-
2. Define interfaces for the screens:
87+
2. Define abstract classes for the screens:
8888

8989
```csharp
90-
90+
using Aquality.Appium.Mobile.Elements.Interfaces;
9191
using Aquality.Appium.Mobile.Screens;
92+
using OpenQA.Selenium;
9293

93-
namespace Aquality.Appium.Mobile.Template.Screens.Interfaces
94+
namespace Aquality.Appium.Mobile.Template.Screens.Login
9495
{
95-
public interface ILoginScreen : IScreen
96+
public abstract class LoginScreen : Screen
9697
{
97-
ILoginScreen SetUsername(string username);
98+
private readonly ITextBox usernameTxb;
99+
private readonly ITextBox passwordTxb;
100+
private readonly IButton loginBtn;
101+
102+
protected LoginScreen(By locator) : base(locator, "Login")
103+
{
104+
usernameTxb = ElementFactory.GetTextBox(UsernameTxbLoc, "Username");
105+
passwordTxb = ElementFactory.GetTextBox(PasswordTxbLoc, "Password");
106+
loginBtn = ElementFactory.GetButton(LoginBtnLoc, "Login");
107+
}
108+
109+
protected abstract By UsernameTxbLoc { get; }
110+
111+
protected abstract By PasswordTxbLoc { get; }
112+
113+
protected abstract By LoginBtnLoc { get; }
114+
115+
public LoginScreen SetUsername(string username)
116+
{
117+
usernameTxb.SendKeys(username);
118+
return this;
119+
}
98120

99-
ILoginScreen SetPassword(string password);
121+
public LoginScreen SetPassword(string password)
122+
{
123+
passwordTxb.TypeSecret(password);
124+
return this;
125+
}
100126

101-
void TapLogin();
127+
public void TapLogin() => loginBtn.Click();
102128
}
103129
}
104-
105130
```
106131

107132
3. Implement interface (Android example):
108133

109134
```csharp
110-
using Aquality.Appium.Mobile.Screens;
111-
using Aquality.Appium.Mobile.Template.Screens.Interfaces;
135+
using Aquality.Appium.Mobile.Applications;
136+
using Aquality.Appium.Mobile.Screens.ScreenFactory;
112137
using OpenQA.Selenium;
113138
using OpenQA.Selenium.Appium;
114139

115-
namespace Aquality.Appium.Mobile.Template.Screens.Android
140+
namespace Aquality.Appium.Mobile.Template.Screens.Login
116141
{
117-
public class LoginScreen : AndroidScreen, ILoginScreen
142+
[ScreenType(PlatformName.Android)]
143+
public sealed class AndroidLoginScreen : LoginScreen
118144
{
119-
public LoginScreen() : base(By.XPath("//android.widget.TextView[@text='Login']"), "Login")
145+
public AndroidLoginScreen() : base(By.XPath("//android.widget.TextView[@text='Login']"))
120146
{
121147
}
122148

123-
public ILoginScreen SetUsername(string username)
124-
{
125-
ElementFactory.GetTextBox(MobileBy.AccessibilityId("username"), "Username").SendKeys(username);
126-
return this;
127-
}
149+
protected override By UsernameTxbLoc => MobileBy.AccessibilityId("username");
128150

129-
public ILoginScreen SetPassword(string password)
130-
{
131-
ElementFactory.GetTextBox(MobileBy.AccessibilityId("password"), "Password").TypeSecret(password);
132-
return this;
133-
}
151+
protected override By PasswordTxbLoc => MobileBy.AccessibilityId("password");
134152

135-
public void TapLogin() => ElementFactory.GetButton(MobileBy.AccessibilityId("loginBtn"), "Login").Click();
153+
protected override By LoginBtnLoc => MobileBy.AccessibilityId("loginBtn");
136154
}
137155
}
138156
```
139157

140158
4. Resolve screen in test:
141159

142160
```csharp
143-
var loginScreen = AqualityServices.ScreenFactory.GetScreen<ILoginScreen>();
161+
var loginScreen = AqualityServices.ScreenFactory.GetScreen<LoginScreen>();
144162
```
145163

146164
You can find an example in [aquality-appium-mobile-dotnet-template](https://github.com/aquality-automation/aquality-appium-mobile-dotnet-template) repository.

0 commit comments

Comments
 (0)