Skip to content

Commit

Permalink
The refactoring of widget tests: work on remarks by @mykola-mokhnach
Browse files Browse the repository at this point in the history
  • Loading branch information
TikhomirovSergey committed Jul 19, 2017
1 parent 73589c8 commit 94660c7
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ public String getAutomationName() {
return APPIUM;
}

@Override
public boolean isBrowser() {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ protected ExtendedWidgetTest(ExtendedApp app, WebDriver driver) {
@Test
public abstract void checkCaseWhenBothWidgetFieldAndClassHaveDelaredAnnotations();

protected static void testLogigByDefault(DefaultStubWidget single, List<DefaultStubWidget> multiple, By rootLocator,
By subLocator) {
protected static void checkThatLocatorsAreCreatedCorrectly(DefaultStubWidget single,
List<DefaultStubWidget> multiple, By rootLocator,
By subLocator) {

assertThat(single.toString(), containsString(rootLocator.toString()));
assertThat(multiple.stream().map(DefaultStubWidget::toString).collect(toList()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ protected WidgetTest(AbstractApp app, WebDriver driver) {
}

@Test
public abstract void commonTestCase();
public abstract void checkThatWidgetsAreCreatedCorrectly();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,52 @@ public class AndroidApp implements ExtendedApp {
@SelendroidFindBy(linkText = "SOME_SELENDROID_DEFAULT_LOCATOR")
private List<DefaultAndroidWidget> multipleAndroidWidgets;

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

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

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

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

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

/**
* The superclass is annotated by {@link AndroidFindBy} and {@link SelendroidFindBy}.
* However there is the field which is annotated by this annotations.
* This field was added to check that locator is
* created correctly according to current platform and current automation and
* annotations that mark the field.
*/
@AndroidFindBy(uiAutomator = "SOME_ANDROID_EXTERNALLY_DEFINED_LOCATOR")
@SelendroidFindBy(linkText = "SOME_SELENDROID_EXTERNALLY_DEFINED_LOCATOR")
private List<ExtendedAndroidWidget> multipleOverriddenAndroidWidgets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,28 @@ public AndroidWidgetTest() {
}

@Override
public void commonTestCase() {
testLogigByDefault(app.getWidget(), app.getWidgets(),
public void checkThatWidgetsAreCreatedCorrectly() {
checkThatLocatorsAreCreatedCorrectly(app.getWidget(), app.getWidgets(),
AndroidUIAutomator(ANDROID_DEFAULT_WIDGET_LOCATOR), AndroidUIAutomator(ANDROID_SUB_WIDGET_LOCATOR));
}

@Override
public void checkCaseWhenWidgetClassHasDeclaredLocatorAnnotation() {
testLogigByDefault(((ExtendedApp) app).getAnnotatedWidget(), ((ExtendedApp) app).getAnnotatedWidgets(),
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getAnnotatedWidget(),
((ExtendedApp) app).getAnnotatedWidgets(),
AndroidUIAutomator(ANDROID_ROOT_WIDGET_LOCATOR), AndroidUIAutomator(ANDROID_SUB_WIDGET_LOCATOR));
}

@Override
public void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass() {
testLogigByDefault(((ExtendedApp) app).getExtendedWidget(), ((ExtendedApp) app).getExtendedWidgets(),
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidget(),
((ExtendedApp) app).getExtendedWidgets(),
AndroidUIAutomator(ANDROID_ROOT_WIDGET_LOCATOR), AndroidUIAutomator(ANDROID_SUB_WIDGET_LOCATOR));
}

@Override
public void checkCaseWhenBothWidgetFieldAndClassHaveDelaredAnnotations() {
testLogigByDefault(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(),
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(),
((ExtendedApp) app).getExtendedWidgetsWithOverriddenLocators(),
AndroidUIAutomator(ANDROID_EXTERNALLY_DEFINED_WIDGET_LOCATOR),
AndroidUIAutomator(ANDROID_SUB_WIDGET_LOCATOR));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,28 @@ public SelendroidWidgetTest() {
}

@Override
public void commonTestCase() {
testLogigByDefault(app.getWidget(), app.getWidgets(),
public void checkThatWidgetsAreCreatedCorrectly() {
checkThatLocatorsAreCreatedCorrectly(app.getWidget(), app.getWidgets(),
linkText(ANDROID_SELENDROID_WIDGET_LOCATOR), linkText(SELENDROID_SUB_WIDGET_LOCATOR));
}

@Override
public void checkCaseWhenWidgetClassHasDeclaredLocatorAnnotation() {
testLogigByDefault(((ExtendedApp) app).getAnnotatedWidget(), ((ExtendedApp) app).getAnnotatedWidgets(),
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getAnnotatedWidget(),
((ExtendedApp) app).getAnnotatedWidgets(),
linkText(SELENDROID_ROOT_WIDGET_LOCATOR), linkText(SELENDROID_SUB_WIDGET_LOCATOR));
}

@Override
public void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass() {
testLogigByDefault(((ExtendedApp) app).getExtendedWidget(), ((ExtendedApp) app).getExtendedWidgets(),
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidget(),
((ExtendedApp) app).getExtendedWidgets(),
linkText(SELENDROID_ROOT_WIDGET_LOCATOR), linkText(SELENDROID_SUB_WIDGET_LOCATOR));
}

@Override
public void checkCaseWhenBothWidgetFieldAndClassHaveDelaredAnnotations() {
testLogigByDefault(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(),
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(),
((ExtendedApp) app).getExtendedWidgetsWithOverriddenLocators(),
linkText(SELENDROID_EXTERNALLY_DEFINED_WIDGET_LOCATOR), linkText(SELENDROID_SUB_WIDGET_LOCATOR));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public CombinedAppTest(AbstractApp app, WebDriver driver, Class<? extends Defaul
}

@Override
public void commonTestCase() {
public void checkThatWidgetsAreCreatedCorrectly() {
assertThat("Excpected widget class was " + widgetClass.getName(),
app.getWidget().getSelfReference().getClass(),
equalTo(widgetClass));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public CombinedWidgetTest(AbstractApp app, WebDriver driver, Class<?> widgetClas
}

@Override
public void commonTestCase() {
public void checkThatWidgetsAreCreatedCorrectly() {
assertThat("Excpected widget class was " + widgetClass.getName(),
app.getWidget().getSubWidget().getSelfReference().getClass(),
equalTo(widgetClass));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,58 @@ public class IosApp implements ExtendedApp {
@iOSXCUITFindBy(iOSNsPredicate = "SOME_XCUIT_DEFAULT_LOCATOR")
private List<DefaultIosWidget> multipleIosWidgets;

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

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

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

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

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

/**
* The superclass is annotated by {@link io.appium.java_client.pagefactory.iOSFindBy} and
* {@link io.appium.java_client.pagefactory.iOSXCUITFindBy}.
* However there is the field which is annotated by this annotations.
* This field was added to check that locator is
* created correctly according to current platform and current automation and
* annotations that mark the field.
*/
@iOSFindBy(uiAutomator = "IOS_EXTERNALLY_DEFINED_WIDGET_LOCATOR")
@iOSXCUITFindBy(iOSNsPredicate = "SOME_XCUIT_EXTERNALLY_DEFINED_LOCATOR")
private List<ExtendedIosWidget> multipleOverriddenIosWidgets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,28 @@ public IosWidgetTest() {
}

@Override
public void commonTestCase() {
testLogigByDefault(app.getWidget(), app.getWidgets(),
public void checkThatWidgetsAreCreatedCorrectly() {
checkThatLocatorsAreCreatedCorrectly(app.getWidget(), app.getWidgets(),
IosUIAutomation(IOS_DEFAULT_WIDGET_LOCATOR), IosUIAutomation(IOS_SUB_WIDGET_LOCATOR));
}

@Override
public void checkCaseWhenWidgetClassHasDeclaredLocatorAnnotation() {
testLogigByDefault(((ExtendedApp) app).getAnnotatedWidget(), ((ExtendedApp) app).getAnnotatedWidgets(),
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getAnnotatedWidget(),
((ExtendedApp) app).getAnnotatedWidgets(),
IosUIAutomation(IOS_ROOT_WIDGET_LOCATOR), IosUIAutomation(IOS_SUB_WIDGET_LOCATOR));
}

@Override
public void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass() {
testLogigByDefault(((ExtendedApp) app).getExtendedWidget(), ((ExtendedApp) app).getExtendedWidgets(),
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidget(),
((ExtendedApp) app).getExtendedWidgets(),
IosUIAutomation(IOS_ROOT_WIDGET_LOCATOR), IosUIAutomation(IOS_SUB_WIDGET_LOCATOR));
}

@Override
public void checkCaseWhenBothWidgetFieldAndClassHaveDelaredAnnotations() {
testLogigByDefault(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(),
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(),
((ExtendedApp) app).getExtendedWidgetsWithOverriddenLocators(),
IosUIAutomation(IOS_EXTERNALLY_DEFINED_WIDGET_LOCATOR), IosUIAutomation(IOS_SUB_WIDGET_LOCATOR));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,28 @@ public XCUITWidgetTest() {
}

@Override
public void commonTestCase() {
testLogigByDefault(app.getWidget(), app.getWidgets(),
public void checkThatWidgetsAreCreatedCorrectly() {
checkThatLocatorsAreCreatedCorrectly(app.getWidget(), app.getWidgets(),
iOSNsPredicateString(IOS_XCUIT_WIDGET_LOCATOR), iOSNsPredicateString(XCUIT_SUB_WIDGET_LOCATOR));
}

@Override
public void checkCaseWhenWidgetClassHasDeclaredLocatorAnnotation() {
testLogigByDefault(((ExtendedApp) app).getAnnotatedWidget(), ((ExtendedApp) app).getAnnotatedWidgets(),
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getAnnotatedWidget(),
((ExtendedApp) app).getAnnotatedWidgets(),
iOSNsPredicateString(XCUIT_ROOT_WIDGET_LOCATOR), iOSNsPredicateString(XCUIT_SUB_WIDGET_LOCATOR));
}

@Override
public void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass() {
testLogigByDefault(((ExtendedApp) app).getExtendedWidget(), ((ExtendedApp) app).getExtendedWidgets(),
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidget(),
((ExtendedApp) app).getExtendedWidgets(),
iOSNsPredicateString(XCUIT_ROOT_WIDGET_LOCATOR), iOSNsPredicateString(XCUIT_SUB_WIDGET_LOCATOR));
}

@Override
public void checkCaseWhenBothWidgetFieldAndClassHaveDelaredAnnotations() {
testLogigByDefault(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(),
checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(),
((ExtendedApp) app).getExtendedWidgetsWithOverriddenLocators(),
iOSNsPredicateString(XCUIT_EXTERNALLY_DEFINED_WIDGET_LOCATOR),
iOSNsPredicateString(XCUIT_SUB_WIDGET_LOCATOR));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,64 @@ public class WindowsApp implements ExtendedApp {
@iOSXCUITFindBy(iOSNsPredicate = "SOME_XCUIT_DEFAULT_LOCATOR")
private List<DefaultWindowsWidget> multipleIosWidgets;

/**
* This class is annotated by {@link WindowsFindBy} and
* {@link io.appium.java_client.pagefactory.iOSXCUITFindBy}.
* This field was added to check that locator is created correctly according to current platform.
* It is expected that the root element and sub-elements are found using
* {@link io.appium.java_client.MobileBy#windowsAutomation(String)}
*/
private AnnotatedWindowsWidget singleAnnotatedIosWidget;

/**
* This class is annotated by {@link WindowsFindBy} and
* {@link io.appium.java_client.pagefactory.iOSXCUITFindBy}.
* This field was added to check that locator is created correctly according to current platform.
* It is expected that the root element and sub-elements are found using
* {@link io.appium.java_client.MobileBy#windowsAutomation(String)}.
*/
private List<AnnotatedWindowsWidget> multipleIosIosWidgets;

/**
* This class is not annotated by {@link WindowsFindBy} and
* {@link io.appium.java_client.pagefactory.iOSXCUITFindBy}.
* But the superclass is annotated by these annotations. This field was added to check that locator is
* created correctly according to current platform.
* It is expected that the root element and sub-elements are found using
* {@link io.appium.java_client.MobileBy#windowsAutomation(String)}.
*/
private ExtendedWindowsWidget singleExtendedIosWidget;

/**
* This class is not annotated by {@link WindowsFindBy} and
* {@link io.appium.java_client.pagefactory.iOSXCUITFindBy}.
* But the superclass is annotated by these annotations. This field was added to check that locator is
* created correctly according to current platform.
* It is expected that the root element and sub-elements are found using
* {@link io.appium.java_client.MobileBy#windowsAutomation(String)}.
*/
private List<ExtendedWindowsWidget> multipleExtendedIosWidgets;

/**
* This class is not annotated by {@link WindowsFindBy} and
* {@link io.appium.java_client.pagefactory.iOSXCUITFindBy}.
* But the superclass is annotated by these annotations. This field was added to check that locator is
* created correctly according to current platform.
* It is expected that the root element and sub-elements are found using
* {@link io.appium.java_client.MobileBy#windowsAutomation(String)}.
*/
@WindowsFindBy(windowsAutomation = "WINDOWS_EXTERNALLY_DEFINED_WIDGET_LOCATOR")
@iOSXCUITFindBy(iOSNsPredicate = "SOME_XCUIT_EXTERNALLY_DEFINED_LOCATOR")
private ExtendedWindowsWidget singleOverriddenIosWidget;

/**
* This class is not annotated by {@link WindowsFindBy} and
* {@link io.appium.java_client.pagefactory.iOSXCUITFindBy}.
* But the superclass is annotated by these annotations. This field was added to check that locator is
* created correctly according to current platform.
* It is expected that the root element and sub-elements are found using
* {@link io.appium.java_client.MobileBy#windowsAutomation(String)}.
*/
@WindowsFindBy(windowsAutomation = "WINDOWS_EXTERNALLY_DEFINED_WIDGET_LOCATOR")
@iOSXCUITFindBy(iOSNsPredicate = "SOME_XCUIT_EXTERNALLY_DEFINED_LOCATOR")
private List<ExtendedWindowsWidget> multipleOverriddenIosWidgets;
Expand Down
Loading

0 comments on commit 94660c7

Please sign in to comment.