Skip to content

Commit f037254

Browse files
committed
Refactor screen class
1 parent 4268856 commit f037254

File tree

5 files changed

+46
-32
lines changed

5 files changed

+46
-32
lines changed

src/main/java/aquality/appium/mobile/elements/Link.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ protected String getElementType() {
1919

2020
@Override
2121
public String getHref() {
22-
return getAttribute("href");
22+
return getAttribute(Attributes.HREF.toString());
2323
}
2424
}

src/main/java/aquality/appium/mobile/screens/Screen.java

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import aquality.appium.mobile.application.PlatformName;
55
import aquality.appium.mobile.elements.interfaces.IElementFactory;
66
import aquality.appium.mobile.elements.interfaces.ILabel;
7+
import aquality.selenium.core.elements.interfaces.IElementStateProvider;
78
import io.appium.java_client.AppiumDriver;
89
import org.openqa.selenium.By;
910
import org.openqa.selenium.Dimension;
@@ -13,21 +14,17 @@
1314

1415
public abstract class Screen {
1516

16-
/**
17-
* Locator for specified screen
18-
*/
19-
protected final By locator;
20-
/**
21-
* Name of specified screen
22-
*/
23-
protected final String name;
17+
private final By locator;
18+
private final String name;
19+
private final ILabel screenLabel;
2420

2521
/**
2622
* Constructor with parameters
2723
*/
2824
protected Screen(By locator, String name) {
2925
this.locator = locator;
3026
this.name = name;
27+
screenLabel = getElementFactory().getLabel(locator, name);
3128
}
3229

3330
protected abstract AppiumDriver getDriver();
@@ -39,7 +36,7 @@ protected Screen(By locator, String name) {
3936
* False - screen is not opened
4037
*/
4138
public boolean isDisplayed() {
42-
return getFormLabel().state().waitForDisplayed();
39+
return screenLabel.state().waitForDisplayed();
4340
}
4441

4542
/**
@@ -50,21 +47,17 @@ public boolean isDisplayed() {
5047
* False - screen is not opened
5148
*/
5249
public boolean isDisplayed(Duration timeout) {
53-
return getFormLabel().state().waitForDisplayed(timeout);
50+
return screenLabel.state().waitForDisplayed(timeout);
5451
}
5552

56-
public Dimension getScreenSize() {
57-
return getFormLabel().getElement().getSize();
53+
public Dimension getSize() {
54+
return screenLabel.getElement().getSize();
5855
}
5956

6057
protected IElementFactory getElementFactory(){
6158
return AqualityServices.getElementFactory();
6259
}
6360

64-
private ILabel getFormLabel(){
65-
return getElementFactory().getLabel(locator, name);
66-
}
67-
6861
void ensureApplicationPlatformCorrect(PlatformName targetPlatform) {
6962
PlatformName currentPlatform = AqualityServices.getApplication().getPlatformName();
7063
if(targetPlatform != currentPlatform) {
@@ -74,4 +67,27 @@ void ensureApplicationPlatformCorrect(PlatformName targetPlatform) {
7467
targetPlatform));
7568
}
7669
}
70+
71+
/**
72+
* Locator for specified screen
73+
*/
74+
public By getLocator() {
75+
return locator;
76+
}
77+
78+
/**
79+
* Name of specified screen
80+
*/
81+
public String getName() {
82+
return name;
83+
}
84+
85+
/**
86+
* Provides ability to define of element's state (whether it is displayed, exists or not) and respective waiting functions
87+
*
88+
* @return provider to define element's state
89+
*/
90+
public IElementStateProvider state() {
91+
return screenLabel.state();
92+
}
7793
}

src/test/java/samples/android/AndroidBasicInteractionsTest.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import aquality.appium.mobile.application.AqualityServices;
44
import aquality.appium.mobile.application.MobileModule;
5-
import aquality.selenium.core.logging.Logger;
6-
import io.appium.java_client.android.AndroidDriver;
75
import org.testng.Assert;
86
import org.testng.annotations.AfterClass;
97
import org.testng.annotations.BeforeClass;
@@ -14,16 +12,11 @@
1412
import samples.android.apidemos.screens.TwoButtonsAlert;
1513

1614
public class AndroidBasicInteractionsTest {
17-
private AndroidDriver<?> driver;
18-
private final String SEARCH_ACTIVITY = ".app.SearchInvoke";
19-
private final String ALERT_DIALOG_ACTIVITY = ".app.AlertDialogSamples";
20-
private final String PACKAGE = "io.appium.android.apis";
2115

2216
@BeforeClass
2317
public void setUp() {
2418
System.clearProperty("profile");
2519
AqualityServices.initInjector(new MobileModule(AqualityServices::getApplication));
26-
driver = (AndroidDriver<?>) AqualityServices.getApplication().getDriver();
2720
}
2821

2922
@AfterClass
@@ -32,10 +25,11 @@ public void tearDown() {
3225
}
3326

3427

35-
@Test()
28+
@Test
3629
public void testSendKeys() {
3730
new MainMenuScreen().startSearch();
3831
InvokeSearchScreen searchScreen = new InvokeSearchScreen();
32+
Assert.assertTrue(searchScreen.isDisplayed(), searchScreen.getName() + " should be opened from the menu");
3933
String query = "Hello world!";
4034
searchScreen.submitSearch(query);
4135
Assert.assertEquals(searchScreen.getSearchResult(), query, "Search result don't match to entered query");
@@ -44,19 +38,23 @@ public void testSendKeys() {
4438
@Test
4539
public void testOpensAlert() {
4640

47-
Logger.getInstance().info("Open the 'Alert Dialog' activity of the android app");
41+
logStep("Open the 'Alert Dialog' activity of the android app");
4842
new MainMenuScreen().openAlerts();
4943

50-
Logger.getInstance().info("Click button that opens a dialog");
44+
logStep("Click button that opens a dialog");
5145
new AlertsMenuScreen().openTwoButtonsDialog();
5246

53-
Logger.getInstance().info("Check that the dialog is there");
47+
logStep("Check that the dialog is there");
5448
TwoButtonsAlert alertDialog = new TwoButtonsAlert();
5549
Assert.assertEquals(alertDialog.getAlertText(),
5650
"Lorem ipsum dolor sit aie consectetur adipiscing\nPlloaso mako nuto siwuf cakso dodtos anr koop.",
5751
"Alert text should match to expected");
5852

59-
Logger.getInstance().info("Close the dialog");
60-
alertDialog.closeDialog();
53+
logStep("Close the dialog");
54+
alertDialog.close();
55+
}
56+
57+
private void logStep(String step) {
58+
AqualityServices.getLogger().info(step);
6159
}
6260
}

src/test/java/samples/android/apidemos/screens/InvokeSearchScreen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class InvokeSearchScreen extends AndroidScreen {
1313
private final ILabel lblSearchResult = getElementFactory().getLabel(By.id("android:id/search_src_text"), "Search results");
1414

1515
public InvokeSearchScreen() {
16-
super(By.xpath("//*[contains(.,'App/Search/Invoke Search')]"), "Invoke Search");
16+
super(By.xpath("//android.widget.TextView[@text='App/Search/Invoke Search']"), "Invoke Search");
1717
}
1818

1919
public void submitSearch(String query) {

src/test/java/samples/android/apidemos/screens/TwoButtonsAlert.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public String getAlertText() {
2020
return lblAlertTitle.getText();
2121
}
2222

23-
public void closeDialog(){
23+
public void close(){
2424
btnClose.click();
2525
}
2626
}

0 commit comments

Comments
 (0)