Skip to content

Commit 94660c7

Browse files
The refactoring of widget tests: work on remarks by @mykola-mokhnach
1 parent 73589c8 commit 94660c7

File tree

13 files changed

+162
-30
lines changed

13 files changed

+162
-30
lines changed

src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/AbstractStubWebDriver.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ public String getAutomationName() {
264264
return APPIUM;
265265
}
266266

267+
@Override
267268
public boolean isBrowser() {
268269
return true;
269270
}

src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ExtendedWidgetTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ protected ExtendedWidgetTest(ExtendedApp app, WebDriver driver) {
2626
@Test
2727
public abstract void checkCaseWhenBothWidgetFieldAndClassHaveDelaredAnnotations();
2828

29-
protected static void testLogigByDefault(DefaultStubWidget single, List<DefaultStubWidget> multiple, By rootLocator,
30-
By subLocator) {
29+
protected static void checkThatLocatorsAreCreatedCorrectly(DefaultStubWidget single,
30+
List<DefaultStubWidget> multiple, By rootLocator,
31+
By subLocator) {
3132

3233
assertThat(single.toString(), containsString(rootLocator.toString()));
3334
assertThat(multiple.stream().map(DefaultStubWidget::toString).collect(toList()),

src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/WidgetTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ protected WidgetTest(AbstractApp app, WebDriver driver) {
2121
}
2222

2323
@Test
24-
public abstract void commonTestCase();
24+
public abstract void checkThatWidgetsAreCreatedCorrectly();
2525
}

src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AndroidApp.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,52 @@ public class AndroidApp implements ExtendedApp {
2222
@SelendroidFindBy(linkText = "SOME_SELENDROID_DEFAULT_LOCATOR")
2323
private List<DefaultAndroidWidget> multipleAndroidWidgets;
2424

25+
/**
26+
* This class is annotated by {@link AndroidFindBy} and @{@link SelendroidFindBy}.
27+
* This field was added to check that locator is created correctly according to current platform
28+
* and current automation.
29+
*/
2530
private AnnotatedAndroidWidget singleAnnotatedAndroidWidget;
2631

32+
/**
33+
* This class is annotated by {@link AndroidFindBy} and @{@link SelendroidFindBy}.
34+
* This field was added to check that locator is created correctly according to current platform
35+
* and current automation.
36+
*/
2737
private List<AnnotatedAndroidWidget> multipleAnnotatedAndroidWidgets;
2838

39+
/**
40+
* This class is not annotated by {@link AndroidFindBy} and {@link SelendroidFindBy}.
41+
* But the superclass is annotated by these annotations. This field was added to check that locator is
42+
* created correctly according to current platform and current automation.
43+
*/
2944
private ExtendedAndroidWidget singleExtendedAndroidWidget;
3045

46+
/**
47+
* This class is not annotated by {@link AndroidFindBy} and {@link SelendroidFindBy}.
48+
* But the superclass is annotated by these annotations. This field was added to check that locator is
49+
* created correctly according to current platform and current automation.
50+
*/
3151
private List<ExtendedAndroidWidget> multipleExtendedAndroidWidgets;
3252

53+
/**
54+
* The superclass is annotated by {@link AndroidFindBy} and {@link SelendroidFindBy}.
55+
* However there is the field which is annotated by this annotations.
56+
* This field was added to check that locator is
57+
* created correctly according to current platform and current automation and
58+
* annotations that mark the field.
59+
*/
3360
@AndroidFindBy(uiAutomator = "SOME_ANDROID_EXTERNALLY_DEFINED_LOCATOR")
3461
@SelendroidFindBy(linkText = "SOME_SELENDROID_EXTERNALLY_DEFINED_LOCATOR")
3562
private ExtendedAndroidWidget singleOverriddenAndroidWidget;
3663

64+
/**
65+
* The superclass is annotated by {@link AndroidFindBy} and {@link SelendroidFindBy}.
66+
* However there is the field which is annotated by this annotations.
67+
* This field was added to check that locator is
68+
* created correctly according to current platform and current automation and
69+
* annotations that mark the field.
70+
*/
3771
@AndroidFindBy(uiAutomator = "SOME_ANDROID_EXTERNALLY_DEFINED_LOCATOR")
3872
@SelendroidFindBy(linkText = "SOME_SELENDROID_EXTERNALLY_DEFINED_LOCATOR")
3973
private List<ExtendedAndroidWidget> multipleOverriddenAndroidWidgets;

src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AndroidWidgetTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,28 @@ public AndroidWidgetTest() {
1717
}
1818

1919
@Override
20-
public void commonTestCase() {
21-
testLogigByDefault(app.getWidget(), app.getWidgets(),
20+
public void checkThatWidgetsAreCreatedCorrectly() {
21+
checkThatLocatorsAreCreatedCorrectly(app.getWidget(), app.getWidgets(),
2222
AndroidUIAutomator(ANDROID_DEFAULT_WIDGET_LOCATOR), AndroidUIAutomator(ANDROID_SUB_WIDGET_LOCATOR));
2323
}
2424

2525
@Override
2626
public void checkCaseWhenWidgetClassHasDeclaredLocatorAnnotation() {
27-
testLogigByDefault(((ExtendedApp) app).getAnnotatedWidget(), ((ExtendedApp) app).getAnnotatedWidgets(),
27+
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getAnnotatedWidget(),
28+
((ExtendedApp) app).getAnnotatedWidgets(),
2829
AndroidUIAutomator(ANDROID_ROOT_WIDGET_LOCATOR), AndroidUIAutomator(ANDROID_SUB_WIDGET_LOCATOR));
2930
}
3031

3132
@Override
3233
public void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass() {
33-
testLogigByDefault(((ExtendedApp) app).getExtendedWidget(), ((ExtendedApp) app).getExtendedWidgets(),
34+
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidget(),
35+
((ExtendedApp) app).getExtendedWidgets(),
3436
AndroidUIAutomator(ANDROID_ROOT_WIDGET_LOCATOR), AndroidUIAutomator(ANDROID_SUB_WIDGET_LOCATOR));
3537
}
3638

3739
@Override
3840
public void checkCaseWhenBothWidgetFieldAndClassHaveDelaredAnnotations() {
39-
testLogigByDefault(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(),
41+
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(),
4042
((ExtendedApp) app).getExtendedWidgetsWithOverriddenLocators(),
4143
AndroidUIAutomator(ANDROID_EXTERNALLY_DEFINED_WIDGET_LOCATOR),
4244
AndroidUIAutomator(ANDROID_SUB_WIDGET_LOCATOR));

src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/SelendroidWidgetTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,28 @@ public SelendroidWidgetTest() {
1616
}
1717

1818
@Override
19-
public void commonTestCase() {
20-
testLogigByDefault(app.getWidget(), app.getWidgets(),
19+
public void checkThatWidgetsAreCreatedCorrectly() {
20+
checkThatLocatorsAreCreatedCorrectly(app.getWidget(), app.getWidgets(),
2121
linkText(ANDROID_SELENDROID_WIDGET_LOCATOR), linkText(SELENDROID_SUB_WIDGET_LOCATOR));
2222
}
2323

2424
@Override
2525
public void checkCaseWhenWidgetClassHasDeclaredLocatorAnnotation() {
26-
testLogigByDefault(((ExtendedApp) app).getAnnotatedWidget(), ((ExtendedApp) app).getAnnotatedWidgets(),
26+
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getAnnotatedWidget(),
27+
((ExtendedApp) app).getAnnotatedWidgets(),
2728
linkText(SELENDROID_ROOT_WIDGET_LOCATOR), linkText(SELENDROID_SUB_WIDGET_LOCATOR));
2829
}
2930

3031
@Override
3132
public void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass() {
32-
testLogigByDefault(((ExtendedApp) app).getExtendedWidget(), ((ExtendedApp) app).getExtendedWidgets(),
33+
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidget(),
34+
((ExtendedApp) app).getExtendedWidgets(),
3335
linkText(SELENDROID_ROOT_WIDGET_LOCATOR), linkText(SELENDROID_SUB_WIDGET_LOCATOR));
3436
}
3537

3638
@Override
3739
public void checkCaseWhenBothWidgetFieldAndClassHaveDelaredAnnotations() {
38-
testLogigByDefault(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(),
40+
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(),
3941
((ExtendedApp) app).getExtendedWidgetsWithOverriddenLocators(),
4042
linkText(SELENDROID_EXTERNALLY_DEFINED_WIDGET_LOCATOR), linkText(SELENDROID_SUB_WIDGET_LOCATOR));
4143
}

src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedAppTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public CombinedAppTest(AbstractApp app, WebDriver driver, Class<? extends Defaul
6767
}
6868

6969
@Override
70-
public void commonTestCase() {
70+
public void checkThatWidgetsAreCreatedCorrectly() {
7171
assertThat("Excpected widget class was " + widgetClass.getName(),
7272
app.getWidget().getSelfReference().getClass(),
7373
equalTo(widgetClass));

src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedWidgetTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public CombinedWidgetTest(AbstractApp app, WebDriver driver, Class<?> widgetClas
7474
}
7575

7676
@Override
77-
public void commonTestCase() {
77+
public void checkThatWidgetsAreCreatedCorrectly() {
7878
assertThat("Excpected widget class was " + widgetClass.getName(),
7979
app.getWidget().getSubWidget().getSelfReference().getClass(),
8080
equalTo(widgetClass));

src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ios/IosApp.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,58 @@ public class IosApp implements ExtendedApp {
2222
@iOSXCUITFindBy(iOSNsPredicate = "SOME_XCUIT_DEFAULT_LOCATOR")
2323
private List<DefaultIosWidget> multipleIosWidgets;
2424

25+
/**
26+
* This class is annotated by {@link io.appium.java_client.pagefactory.iOSFindBy} and
27+
* {@link io.appium.java_client.pagefactory.iOSXCUITFindBy}.
28+
* This field was added to check that locator is created correctly according to current platform
29+
* and current automation.
30+
*/
2531
private AnnotatedIosWidget singleAnnotatedIosWidget;
2632

33+
/**
34+
* This class is annotated by {@link io.appium.java_client.pagefactory.iOSFindBy} and
35+
* {@link io.appium.java_client.pagefactory.iOSXCUITFindBy}.
36+
* This field was added to check that locator is created correctly according to current platform
37+
* and current automation.
38+
*/
2739
private List<AnnotatedIosWidget> multipleIosIosWidgets;
2840

41+
/**
42+
* This class is not annotated by {@link io.appium.java_client.pagefactory.iOSFindBy} and
43+
* {@link io.appium.java_client.pagefactory.iOSXCUITFindBy}.
44+
* But the superclass is annotated by these annotations. This field was added to check that locator is
45+
* created correctly according to current platform and current automation.
46+
*/
2947
private ExtendedIosWidget singleExtendedIosWidget;
3048

49+
/**
50+
* This class is not annotated by {@link io.appium.java_client.pagefactory.iOSFindBy} and
51+
* {@link io.appium.java_client.pagefactory.iOSXCUITFindBy}.
52+
* But the superclass is annotated by these annotations. This field was added to check that locator is
53+
* created correctly according to current platform and current automation.
54+
*/
3155
private List<ExtendedIosWidget> multipleExtendedIosWidgets;
3256

57+
/**
58+
* The superclass is annotated by {@link io.appium.java_client.pagefactory.iOSFindBy} and
59+
* {@link io.appium.java_client.pagefactory.iOSXCUITFindBy}.
60+
* However there is the field which is annotated by this annotations.
61+
* This field was added to check that locator is
62+
* created correctly according to current platform and current automation and
63+
* annotations that mark the field.
64+
*/
3365
@iOSFindBy(uiAutomator = "IOS_EXTERNALLY_DEFINED_WIDGET_LOCATOR")
3466
@iOSXCUITFindBy(iOSNsPredicate = "SOME_XCUIT_EXTERNALLY_DEFINED_LOCATOR")
3567
private ExtendedIosWidget singleOverriddenIosWidget;
3668

69+
/**
70+
* The superclass is annotated by {@link io.appium.java_client.pagefactory.iOSFindBy} and
71+
* {@link io.appium.java_client.pagefactory.iOSXCUITFindBy}.
72+
* However there is the field which is annotated by this annotations.
73+
* This field was added to check that locator is
74+
* created correctly according to current platform and current automation and
75+
* annotations that mark the field.
76+
*/
3777
@iOSFindBy(uiAutomator = "IOS_EXTERNALLY_DEFINED_WIDGET_LOCATOR")
3878
@iOSXCUITFindBy(iOSNsPredicate = "SOME_XCUIT_EXTERNALLY_DEFINED_LOCATOR")
3979
private List<ExtendedIosWidget> multipleOverriddenIosWidgets;

src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ios/IosWidgetTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,28 @@ public IosWidgetTest() {
1717
}
1818

1919
@Override
20-
public void commonTestCase() {
21-
testLogigByDefault(app.getWidget(), app.getWidgets(),
20+
public void checkThatWidgetsAreCreatedCorrectly() {
21+
checkThatLocatorsAreCreatedCorrectly(app.getWidget(), app.getWidgets(),
2222
IosUIAutomation(IOS_DEFAULT_WIDGET_LOCATOR), IosUIAutomation(IOS_SUB_WIDGET_LOCATOR));
2323
}
2424

2525
@Override
2626
public void checkCaseWhenWidgetClassHasDeclaredLocatorAnnotation() {
27-
testLogigByDefault(((ExtendedApp) app).getAnnotatedWidget(), ((ExtendedApp) app).getAnnotatedWidgets(),
27+
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getAnnotatedWidget(),
28+
((ExtendedApp) app).getAnnotatedWidgets(),
2829
IosUIAutomation(IOS_ROOT_WIDGET_LOCATOR), IosUIAutomation(IOS_SUB_WIDGET_LOCATOR));
2930
}
3031

3132
@Override
3233
public void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass() {
33-
testLogigByDefault(((ExtendedApp) app).getExtendedWidget(), ((ExtendedApp) app).getExtendedWidgets(),
34+
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidget(),
35+
((ExtendedApp) app).getExtendedWidgets(),
3436
IosUIAutomation(IOS_ROOT_WIDGET_LOCATOR), IosUIAutomation(IOS_SUB_WIDGET_LOCATOR));
3537
}
3638

3739
@Override
3840
public void checkCaseWhenBothWidgetFieldAndClassHaveDelaredAnnotations() {
39-
testLogigByDefault(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(),
41+
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(),
4042
((ExtendedApp) app).getExtendedWidgetsWithOverriddenLocators(),
4143
IosUIAutomation(IOS_EXTERNALLY_DEFINED_WIDGET_LOCATOR), IosUIAutomation(IOS_SUB_WIDGET_LOCATOR));
4244
}

0 commit comments

Comments
 (0)