Skip to content

Commit bc40b1e

Browse files
author
Pavel Anihimovsky
committed
Update README.md
1 parent 00af0f3 commit bc40b1e

File tree

1 file changed

+52
-22
lines changed

1 file changed

+52
-22
lines changed

README.md

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,65 +84,95 @@ public class InvokeSearchScreen extends AndroidScreen {
8484

8585
### ScreenFactory
8686

87-
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.
87+
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 a necessary screen depending on the chosen platform.
8888

8989
1. Set `screensLocation` property in `settings.json`. It is a name of package where you define screens.
9090

91-
2. Define interfaces for the screens:
91+
2. Define abstract classes for the screens:
9292

9393
```java
94-
package aquality.appium.mobile.template.screens.interfaces;
94+
package aquality.appium.mobile.template.screens.login;
9595

96-
public interface ILoginScreen extends IScreen {
96+
import aquality.appium.mobile.elements.interfaces.IButton;
97+
import aquality.appium.mobile.elements.interfaces.ITextBox;
98+
import aquality.appium.mobile.screens.Screen;
99+
import org.openqa.selenium.By;
97100

98-
ILoginScreen setUsername(final String username);
101+
public abstract class LoginScreen extends Screen {
102+
103+
private final ITextBox usernameTxb;
104+
private final ITextBox passwordTxb;
105+
private final IButton loginBtn;
106+
107+
protected LoginScreen(By locator) {
108+
super(locator, "Login");
109+
usernameTxb = getElementFactory().getTextBox(getUsernameTxbLoc(), "Username");
110+
passwordTxb = getElementFactory().getTextBox(getPasswordTxbLoc(), "Password");
111+
loginBtn = getElementFactory().getButton(getLoginBtnLoc(), "Login");
112+
}
99113

100-
ILoginScreen setPassword(final String password);
114+
protected abstract By getUsernameTxbLoc();
115+
116+
protected abstract By getPasswordTxbLoc();
117+
118+
protected abstract By getLoginBtnLoc();
119+
120+
public LoginScreen setUsername(final String username) {
121+
usernameTxb.sendKeys(username);
122+
return this;
123+
}
101124

102-
void tapLogin();
125+
public LoginScreen setPassword(final String password) {
126+
passwordTxb.typeSecret(password);
127+
return this;
128+
}
129+
130+
public void tapLogin() {
131+
loginBtn.click();
132+
}
103133
}
104134
```
105135

106136
3. Implement interface (Android example):
107137

108138
```java
109-
package aquality.appium.mobile.template.screens.android;
139+
package aquality.appium.mobile.template.screens.login;
110140

111-
import aquality.appium.mobile.screens.AndroidScreen;
112-
import aquality.appium.mobile.template.screens.interfaces.ILoginScreen;
141+
import aquality.appium.mobile.application.PlatformName;
142+
import aquality.appium.mobile.screens.screenfactory.ScreenType;
143+
import org.openqa.selenium.By;
113144

114145
import static io.appium.java_client.MobileBy.AccessibilityId;
115146
import static org.openqa.selenium.By.xpath;
116147

117-
public class LoginScreen extends AndroidScreen implements ILoginScreen {
148+
@ScreenType(platform = PlatformName.ANDROID)
149+
public class AndroidLoginScreen extends LoginScreen {
118150

119-
public LoginScreen() {
120-
super(xpath("//android.widget.TextView[@text='Login']"), "Login");
151+
public AndroidLoginScreen() {
152+
super(xpath("//android.widget.TextView[@text='Login']"));
121153
}
122154

123155
@Override
124-
public ILoginScreen setUsername(final String username) {
125-
getElementFactory().getTextBox(AccessibilityId("username"), "Username").sendKeys(username);
126-
return this;
156+
protected By getUsernameTxbLoc() {
157+
return AccessibilityId("username");
127158
}
128159

129160
@Override
130-
public ILoginScreen setPassword(final String password) {
131-
getElementFactory().getTextBox(AccessibilityId("password"), "Password").typeSecret(password);
132-
return this;
161+
protected By getPasswordTxbLoc() {
162+
return AccessibilityId("password");
133163
}
134164

135165
@Override
136-
public void tapLogin() {
137-
getElementFactory().getButton(AccessibilityId("loginBtn"), "Login").click();
166+
protected By getLoginBtnLoc() {
167+
return AccessibilityId("loginBtn");
138168
}
139169
}
140170
```
141171

142172
4. Resolve screen in test:
143173

144174
```java
145-
ILoginScreen loginScreen = AqualityServices.getScreenFactory().getScreen(ILoginScreen.class);
175+
LoginScreen loginScreen = AqualityServices.getScreenFactory().getScreen(LoginScreen.class);
146176
```
147177

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

0 commit comments

Comments
 (0)