From 1c979b8185b7e9b8488bad4599387865225f7027 Mon Sep 17 00:00:00 2001 From: nviarbitski Date: Tue, 24 Mar 2020 12:09:32 +0300 Subject: [PATCH 01/21] Adding Swipe Configs in settings.json - Added new configuration.ISwipeConfiguration - Added new configuration.SwipeConfiguration - Adding getSwipeConfiguration() into IConfiguration - Adding getSwipeConfigurationImplementation() into IConfigurationModule - Adding swipeConfiguration into Configuration - Adding ISwipeConfiguration bind in MobileModule - Adding "swipe" object in settings.json: timeout in seconds shows the scroll speed, retries shows the number of swipe actions to swipe to element --- .../mobile/application/MobileModule.java | 2 ++ .../mobile/configuration/Configuration.java | 9 ++++++- .../mobile/configuration/IConfiguration.java | 7 +++++ .../configuration/IConfigurationsModule.java | 6 +++++ .../configuration/ISwipeConfiguration.java | 9 +++++++ .../configuration/SwipeConfiguration.java | 27 +++++++++++++++++++ src/test/resources/settings.json | 13 +++++---- 7 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 src/main/java/aquality/appium/mobile/configuration/ISwipeConfiguration.java create mode 100644 src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java diff --git a/src/main/java/aquality/appium/mobile/application/MobileModule.java b/src/main/java/aquality/appium/mobile/application/MobileModule.java index cd249ab..51d2efd 100644 --- a/src/main/java/aquality/appium/mobile/application/MobileModule.java +++ b/src/main/java/aquality/appium/mobile/application/MobileModule.java @@ -3,6 +3,7 @@ import aquality.appium.mobile.configuration.IApplicationProfile; import aquality.appium.mobile.configuration.IConfiguration; import aquality.appium.mobile.configuration.IConfigurationsModule; +import aquality.appium.mobile.configuration.ISwipeConfiguration; import aquality.appium.mobile.elements.IElementsModule; import aquality.appium.mobile.elements.interfaces.IElementFactory; import aquality.selenium.core.applications.AqualityModule; @@ -20,5 +21,6 @@ protected void configure() { bind(IApplicationProfile.class).to(getApplicationProfileImplementation()).in(Singleton.class); bind(IConfiguration.class).to(getConfigurationImplementation()); bind(IElementFactory.class).to(getElementFactoryImplementation()); + bind(ISwipeConfiguration.class).to(getSwipeConfigurationImplementation()).in(Singleton.class); } } diff --git a/src/main/java/aquality/appium/mobile/configuration/Configuration.java b/src/main/java/aquality/appium/mobile/configuration/Configuration.java index 8ce2ce7..da2600a 100644 --- a/src/main/java/aquality/appium/mobile/configuration/Configuration.java +++ b/src/main/java/aquality/appium/mobile/configuration/Configuration.java @@ -13,16 +13,18 @@ public class Configuration implements IConfiguration { private final IApplicationProfile applicationProfile; private final ILoggerConfiguration loggerConfiguration; private final IElementCacheConfiguration elementCacheConfiguration; + private final ISwipeConfiguration swipeConfiguration; @Inject public Configuration(ITimeoutConfiguration timeoutConfiguration, IRetryConfiguration retryConfiguration, IApplicationProfile applicationProfile, ILoggerConfiguration loggerConfiguration, - IElementCacheConfiguration elementCacheConfiguration) { + IElementCacheConfiguration elementCacheConfiguration, ISwipeConfiguration swipeConfiguration) { this.timeoutConfiguration = timeoutConfiguration; this.retryConfiguration = retryConfiguration; this.applicationProfile = applicationProfile; this.loggerConfiguration = loggerConfiguration; this.elementCacheConfiguration = elementCacheConfiguration; + this.swipeConfiguration = swipeConfiguration; } @Override @@ -49,4 +51,9 @@ public ILoggerConfiguration getLoggerConfiguration() { public IElementCacheConfiguration getElementCacheConfiguration() { return elementCacheConfiguration; } + + @Override + public ISwipeConfiguration getSwipeConfiguration() { + return swipeConfiguration; + } } \ No newline at end of file diff --git a/src/main/java/aquality/appium/mobile/configuration/IConfiguration.java b/src/main/java/aquality/appium/mobile/configuration/IConfiguration.java index 5e997f1..4376944 100644 --- a/src/main/java/aquality/appium/mobile/configuration/IConfiguration.java +++ b/src/main/java/aquality/appium/mobile/configuration/IConfiguration.java @@ -41,4 +41,11 @@ public interface IConfiguration { * @return Configuration of element caching. */ IElementCacheConfiguration getElementCacheConfiguration(); + + /** + * Gets configuration of swipes. + * + * @return Configuration of swipes. + */ + ISwipeConfiguration getSwipeConfiguration(); } \ No newline at end of file diff --git a/src/main/java/aquality/appium/mobile/configuration/IConfigurationsModule.java b/src/main/java/aquality/appium/mobile/configuration/IConfigurationsModule.java index a19d727..f04cca8 100644 --- a/src/main/java/aquality/appium/mobile/configuration/IConfigurationsModule.java +++ b/src/main/java/aquality/appium/mobile/configuration/IConfigurationsModule.java @@ -19,4 +19,10 @@ default Class getConfigurationImplementation() { return Configuration.class; } + /** + * @return class which implements {@link IConfiguration} + */ + default Class getSwipeConfigurationImplementation() { + return SwipeConfiguration.class; + } } diff --git a/src/main/java/aquality/appium/mobile/configuration/ISwipeConfiguration.java b/src/main/java/aquality/appium/mobile/configuration/ISwipeConfiguration.java new file mode 100644 index 0000000..f08e9b5 --- /dev/null +++ b/src/main/java/aquality/appium/mobile/configuration/ISwipeConfiguration.java @@ -0,0 +1,9 @@ +package aquality.appium.mobile.configuration; + +import java.time.Duration; + +public interface ISwipeConfiguration { + int getRetries(); + + Duration getTimeout(); +} diff --git a/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java b/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java new file mode 100644 index 0000000..370b71b --- /dev/null +++ b/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java @@ -0,0 +1,27 @@ +package aquality.appium.mobile.configuration; + +import aquality.selenium.core.utilities.ISettingsFile; +import com.google.inject.Inject; + +import java.time.Duration; + +public class SwipeConfiguration implements ISwipeConfiguration { + private final int retries; + private final Duration timeout; + + @Inject + public SwipeConfiguration(ISettingsFile settingsFile) { + this.retries = Integer.parseInt(settingsFile.getValue("/swipe/retries").toString()); + this.timeout = Duration.ofSeconds(Long.parseLong(settingsFile.getValue("/swipe/timeout").toString())); + } + + @Override + public int getRetries() { + return this.retries; + } + + @Override + public Duration getTimeout() { + return this.timeout; + } +} diff --git a/src/test/resources/settings.json b/src/test/resources/settings.json index b51c5c8..feeb57d 100644 --- a/src/test/resources/settings.json +++ b/src/test/resources/settings.json @@ -1,8 +1,7 @@ { - "platformName" : "android", + "platformName": "android", "isRemote": true, "remoteConnectionUrl": "http://127.0.0.1:4723/wd/hub", - "driverSettings": { "android": { "applicationPath": "./src/test/resources/apps/ApiDemos-debug.apk", @@ -24,10 +23,10 @@ } }, "timeouts": { - "timeoutImplicit" : 0, - "timeoutCondition" : 15, + "timeoutImplicit": 0, + "timeoutCondition": 15, "timeoutPollingInterval": 300, - "timeoutCommand":120 + "timeoutCommand": 120 }, "retry": { "number": 2, @@ -38,5 +37,9 @@ }, "elementCache": { "isEnabled": true + }, + "swipe": { + "timeout": 1, + "retries": 5 } } \ No newline at end of file From b7746c36f88315b53b2ad9fd2bf1214c112b7a5b Mon Sep 17 00:00:00 2001 From: nviarbitski Date: Tue, 24 Mar 2020 12:20:50 +0300 Subject: [PATCH 02/21] Adding Swipe Actions implementation - Adding elements.actions.SwipeActions: includes implementation of swipe, swipe with long press, scroll to element (vertical) - Adding Scren Size Type - Adding Swipe Direction --- .../mobile/elements/ScreenSizeType.java | 6 ++ .../mobile/elements/SwipeDirection.java | 6 ++ .../mobile/elements/actions/SwipeActions.java | 102 ++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 src/main/java/aquality/appium/mobile/elements/ScreenSizeType.java create mode 100644 src/main/java/aquality/appium/mobile/elements/SwipeDirection.java create mode 100644 src/main/java/aquality/appium/mobile/elements/actions/SwipeActions.java diff --git a/src/main/java/aquality/appium/mobile/elements/ScreenSizeType.java b/src/main/java/aquality/appium/mobile/elements/ScreenSizeType.java new file mode 100644 index 0000000..7382391 --- /dev/null +++ b/src/main/java/aquality/appium/mobile/elements/ScreenSizeType.java @@ -0,0 +1,6 @@ +package aquality.appium.mobile.elements; + +public enum ScreenSizeType { + HEIGHT, + WIDTH; +} diff --git a/src/main/java/aquality/appium/mobile/elements/SwipeDirection.java b/src/main/java/aquality/appium/mobile/elements/SwipeDirection.java new file mode 100644 index 0000000..3699fe6 --- /dev/null +++ b/src/main/java/aquality/appium/mobile/elements/SwipeDirection.java @@ -0,0 +1,6 @@ +package aquality.appium.mobile.elements; + +public enum SwipeDirection { + UP, + DOWN; +} diff --git a/src/main/java/aquality/appium/mobile/elements/actions/SwipeActions.java b/src/main/java/aquality/appium/mobile/elements/actions/SwipeActions.java new file mode 100644 index 0000000..faac8c3 --- /dev/null +++ b/src/main/java/aquality/appium/mobile/elements/actions/SwipeActions.java @@ -0,0 +1,102 @@ +package aquality.appium.mobile.elements.actions; + +import aquality.appium.mobile.application.AqualityServices; +import aquality.appium.mobile.configuration.ISwipeConfiguration; +import aquality.appium.mobile.elements.ScreenSizeType; +import aquality.appium.mobile.elements.SwipeDirection; +import aquality.appium.mobile.elements.interfaces.IElement; +import aquality.selenium.core.logging.Logger; +import io.appium.java_client.TouchAction; +import io.appium.java_client.touch.offset.PointOption; +import org.openqa.selenium.Dimension; + +import static io.appium.java_client.touch.WaitOptions.waitOptions; + +public class SwipeActions { + + /** + * returns new instance of TouchAction. + */ + private static TouchAction getTouchAction() { + return new TouchAction<>(AqualityServices.getApplication().getDriver()); + } + + /** + * Swipes from start coordinates to end coordinates using TouchAction. + * + * @param x1 horizontal start coordinate. + * @param y1 vertical start coordinate. + * @param x2 horizontal end coordinate. + * @param y2 vertical end coordinate. + */ + public static void swipe(int x1, int y1, int x2, int y2) { + Logger.getInstance().info(String.format("Swiping: from coordinates x:%s y:%s to x:%s y:%s", x1, y1, x2, y2)); + getTouchAction().press(PointOption.point(x1, y1)) + .waitAction(waitOptions(AqualityServices.get(ISwipeConfiguration.class).getTimeout())) + .moveTo(PointOption.point(x2, y2)).release().perform(); + } + + /** + * Swipes from start coordinates to end coordinates using LongPress. + * + * @param x1 horizontal start coordinate. + * @param y1 vertical start coordinate. + * @param x2 horizontal end coordinate. + * @param y2 vertical end coordinate. + */ + public static void swipeWithLongPress(int x1, int y1, int x2, int y2) { + Logger.getInstance().info(String.format("Swiping: from coordinates x:%s y:%s to x:%s y:%s", x1, y1, x2, y2)); + getTouchAction().longPress(PointOption.point(x1, y1)) + .moveTo(PointOption.point(x2, y2)).release().perform(); + } + + /** + * Returns the coordinate according to the screen height/width adjusted for the swipe coefficient. + * + * @param size width/height + * @param swipeCoefficient coefficient relative to the top/bottom of the screen + * @return coordinate to swipe from/to + */ + public static int getCoordinate(ScreenSizeType size, double swipeCoefficient) { + Dimension screenSize = AqualityServices.getApplication().getDriver().manage().window().getSize(); + if (size == ScreenSizeType.HEIGHT) { + return (int) (screenSize.getHeight() * swipeCoefficient); + } + return (int) (screenSize.getWidth() * swipeCoefficient); + } + + /** + * Scrolls until element is not displayed using the fixed number of retries. + * + * @param element element to swipe to. + * @param direction direction to swipe. + */ + public static void scrollToElement(IElement element, SwipeDirection direction) { + int numberOfRetires = AqualityServices.get(ISwipeConfiguration.class).getRetries(); + while (numberOfRetires >= 0) { + if (!element.state().isDisplayed()) { + switch (direction) { + case DOWN: + swipe( + getCoordinate(ScreenSizeType.WIDTH, 0.5), + getCoordinate(ScreenSizeType.HEIGHT, 0.8), + getCoordinate(ScreenSizeType.WIDTH, 0.5), + getCoordinate(ScreenSizeType.HEIGHT, 0.2)); + break; + case UP: + swipe( + getCoordinate(ScreenSizeType.WIDTH, 0.5), + getCoordinate(ScreenSizeType.HEIGHT, 0.2), + getCoordinate(ScreenSizeType.WIDTH, 0.5), + getCoordinate(ScreenSizeType.HEIGHT, 0.8)); + break; + default: + throw new IllegalArgumentException( + String.format("'%s' direction does not exist", direction.toString())); + } + } + numberOfRetires--; + } + } + +} From d167f138997248e9ff9af1dddc0803d3e4cc6e82 Mon Sep 17 00:00:00 2001 From: nviarbitski Date: Tue, 24 Mar 2020 12:23:35 +0300 Subject: [PATCH 03/21] Adding Test for Swipe Action - Adding elements and methods into ViewControlsScreen - Adding testSwipeToElement() test into AndroidBasicInteractionsTest --- .../AndroidBasicInteractionsTest.java | 13 +++++++ .../apidemos/screens/ViewControlsScreen.java | 34 +++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/test/java/samples/android/nativeapp/AndroidBasicInteractionsTest.java b/src/test/java/samples/android/nativeapp/AndroidBasicInteractionsTest.java index 52c2de1..d6fd913 100644 --- a/src/test/java/samples/android/nativeapp/AndroidBasicInteractionsTest.java +++ b/src/test/java/samples/android/nativeapp/AndroidBasicInteractionsTest.java @@ -90,6 +90,19 @@ public void testOpensAlert() { alertDialog.close(); } + @Test + public void testSwipeToElement() { + ViewControlsScreen viewControlsScreen = new ViewControlsScreen(); + openRadioButtonsScreen(); + viewControlsScreen.scrollToAllInsideScrollViewLabel(); + Assert.assertEquals( + viewControlsScreen.getAllInsideScrollViewLabelText(), + "(And all inside of a ScrollView!)", + "Label text does not match expected"); + viewControlsScreen.scrollToDisabledButton(); + Assert.assertFalse(viewControlsScreen.isDisabledButtonClickable()); + } + private void logStep(String step) { AqualityServices.getLogger().info(step); } diff --git a/src/test/java/samples/android/nativeapp/apidemos/screens/ViewControlsScreen.java b/src/test/java/samples/android/nativeapp/apidemos/screens/ViewControlsScreen.java index 0082c7c..a9331ff 100644 --- a/src/test/java/samples/android/nativeapp/apidemos/screens/ViewControlsScreen.java +++ b/src/test/java/samples/android/nativeapp/apidemos/screens/ViewControlsScreen.java @@ -1,6 +1,10 @@ package samples.android.nativeapp.apidemos.screens; +import aquality.appium.mobile.elements.SwipeDirection; +import aquality.appium.mobile.elements.actions.SwipeActions; +import aquality.appium.mobile.elements.interfaces.IButton; import aquality.appium.mobile.elements.interfaces.ICheckBox; +import aquality.appium.mobile.elements.interfaces.ILabel; import aquality.appium.mobile.elements.interfaces.IRadioButton; import aquality.appium.mobile.screens.AndroidScreen; import io.appium.java_client.MobileBy; @@ -11,15 +15,41 @@ public ViewControlsScreen() { super(By.id("android:id/content"), "View/Controls"); } - public IRadioButton getRadioButton(int number){ + public IRadioButton getRadioButton(int number) { return getElementFactory().getRadioButton( MobileBy.AccessibilityId(String.format("RadioButton %d", number)), String.valueOf(number)); } - public ICheckBox getCheckBox(int number){ + public ICheckBox getCheckBox(int number) { return getElementFactory().getCheckBox( MobileBy.AccessibilityId(String.format("Checkbox %d", number)), String.valueOf(number)); } + + private ILabel lblAllInsideScrollView() { + return getElementFactory().getLabel( + MobileBy.AccessibilityId("(And all inside of a ScrollView!)"), + "All inside of Scroll View"); + } + + private IButton btnDisabled() { + return getElementFactory().getButton(MobileBy.id("button_disabled"), "Disabled"); + } + + public void scrollToAllInsideScrollViewLabel() { + SwipeActions.scrollToElement(lblAllInsideScrollView(), SwipeDirection.DOWN); + } + + public String getAllInsideScrollViewLabelText() { + return lblAllInsideScrollView().getText(); + } + + public void scrollToDisabledButton() { + SwipeActions.scrollToElement(btnDisabled(), SwipeDirection.UP); + } + + public boolean isDisabledButtonClickable() { + return btnDisabled().state().isClickable(); + } } From dd33cd4b2eab2d447ef5e32c9abc2301b0d8cd77 Mon Sep 17 00:00:00 2001 From: nviarbitski Date: Mon, 6 Apr 2020 01:30:19 +0300 Subject: [PATCH 04/21] Fixing Swipe Configs; - Updated ISwipeCongifuration with new settings. - Updated SwipeConfiguration with implementation for new settings. - Updating "swipe" object in test.resources.settings.json. - Adding "swipe" object in test.resources.settings.androidwebsession.json. - Adding "swipe" object in main.resources.settings.json. --- .../configuration/ISwipeConfiguration.java | 70 +++++++++++++++++++ .../configuration/SwipeConfiguration.java | 64 +++++++++++++++++ src/main/resources/settings.json | 12 ++++ .../resources/settings.androidwebsession.json | 12 ++++ src/test/resources/settings.json | 10 ++- 5 files changed, 167 insertions(+), 1 deletion(-) diff --git a/src/main/java/aquality/appium/mobile/configuration/ISwipeConfiguration.java b/src/main/java/aquality/appium/mobile/configuration/ISwipeConfiguration.java index f08e9b5..750a014 100644 --- a/src/main/java/aquality/appium/mobile/configuration/ISwipeConfiguration.java +++ b/src/main/java/aquality/appium/mobile/configuration/ISwipeConfiguration.java @@ -2,8 +2,78 @@ import java.time.Duration; +/** + * Describes Swipe settings. + */ public interface ISwipeConfiguration { + /** + * Gets number of retries to perform swipe. + * + * @return arguments map. + */ int getRetries(); + /** + * Gets the timeout to perform a swipe. + * + * @return timeout to perform swipe. + */ Duration getTimeout(); + + /** + * Gets the coefficient to calculate the 'x' coordinate of top point for swipe action. + * + * @return coefficient to calculate the 'x' coordinate of top point for swipe action + */ + double getHorizontalSwipeTopPointXCoefficient(); + + /** + * Gets the coefficient to calculate the 'x' coordinate of bottom point for swipe action. + * + * @return coefficient to calculate the 'x' coordinate of bottom point for swipe action + */ + double getHorizontalSwipeBottomPointXCoefficient(); + + /** + * Gets the coefficient to calculate the 'y' coordinate of top point for swipe action. + * + * @return coefficient to calculate the 'y' coordinate of top point for swipe action + */ + double getHorizontalSwipeTopPointYCoefficient(); + + /** + * Gets the coefficient to calculate the 'y' coordinate of bottom point for swipe action. + * + * @return coefficient to calculate the 'y' coordinate of bottom point for swipe action + */ + double getHorizontalSwipeBottomPointYCoefficient(); + + /** + * Gets the coefficient to calculate the 'x' coordinate of top point for swipe action. + * + * @return timeout to perform swipe. + */ + double getVerticalSwipeLeftPointXCoefficient(); + + /** + * Gets the coefficient to calculate the 'x' coordinate of right-hand point for swipe action. + * + * @return coefficient to calculate the 'x' coordinate of right-hand point for swipe action + */ + double getVerticalSwipeRightPointXCoefficient(); + + /** + * Gets the coefficient to calculate the 'y' coordinate of left-hand point for swipe action. + * + * @return coefficient to calculate the 'y' coordinate of left-hand point for swipe action + */ + double getVerticalSwipeLeftPointYCoefficient(); + + + /** + * Gets the coefficient to calculate the 'y' coordinate of right-hand point for swipe action. + * + * @return coefficient to calculate the 'y' coordinate of right-hand point for swipe action + */ + double getVerticalSwipeRightPointYCoefficient(); } diff --git a/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java b/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java index 370b71b..7ac598c 100644 --- a/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java +++ b/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java @@ -8,11 +8,35 @@ public class SwipeConfiguration implements ISwipeConfiguration { private final int retries; private final Duration timeout; + private final double horizontalSwipeTopPointXCoefficient; + private final double horizontalSwipeBottomPointXCoefficient; + private final double horizontalSwipeTopPointYCoefficient; + private final double horizontalSwipeBottomPointYCoefficient; + private final double verticalSwipeLeftPointXCoefficient; + private final double verticalSwipeRightPointXCoefficient; + private final double verticalSwipeLeftPointYCoefficient; + private final double verticalSwipeRightPointYCoefficient; @Inject public SwipeConfiguration(ISettingsFile settingsFile) { this.retries = Integer.parseInt(settingsFile.getValue("/swipe/retries").toString()); this.timeout = Duration.ofSeconds(Long.parseLong(settingsFile.getValue("/swipe/timeout").toString())); + this.horizontalSwipeTopPointXCoefficient = Double.parseDouble( + settingsFile.getValue("/swipe/horizontalSwipeTopPointXCoefficient").toString()); + this.horizontalSwipeBottomPointXCoefficient = Double.parseDouble( + settingsFile.getValue("/swipe/horizontalSwipeBottomPointXCoefficient").toString()); + this.horizontalSwipeTopPointYCoefficient = Double.parseDouble( + settingsFile.getValue("/swipe/horizontalSwipeTopPointYCoefficient").toString()); + this.horizontalSwipeBottomPointYCoefficient = Double.parseDouble( + settingsFile.getValue("/swipe/horizontalSwipeBottomPointYCoefficient").toString()); + this.verticalSwipeLeftPointXCoefficient = Double.parseDouble( + settingsFile.getValue("/swipe/verticalSwipeLeftPointXCoefficient").toString()); + this.verticalSwipeRightPointXCoefficient = Double.parseDouble( + settingsFile.getValue("/swipe/verticalSwipeRightPointXCoefficient").toString()); + this.verticalSwipeLeftPointYCoefficient = Double.parseDouble( + settingsFile.getValue("/swipe/verticalSwipeLeftPointYCoefficient").toString()); + this.verticalSwipeRightPointYCoefficient = Double.parseDouble( + settingsFile.getValue("/swipe/verticalSwipeRightPointYCoefficient").toString()); } @Override @@ -24,4 +48,44 @@ public int getRetries() { public Duration getTimeout() { return this.timeout; } + + @Override + public double getHorizontalSwipeTopPointXCoefficient() { + return this.horizontalSwipeTopPointXCoefficient; + } + + @Override + public double getHorizontalSwipeBottomPointXCoefficient() { + return this.horizontalSwipeBottomPointXCoefficient; + } + + @Override + public double getHorizontalSwipeTopPointYCoefficient() { + return this.horizontalSwipeTopPointYCoefficient; + } + + @Override + public double getHorizontalSwipeBottomPointYCoefficient() { + return this.horizontalSwipeBottomPointYCoefficient; + } + + @Override + public double getVerticalSwipeLeftPointXCoefficient() { + return this.verticalSwipeLeftPointXCoefficient; + } + + @Override + public double getVerticalSwipeRightPointXCoefficient() { + return this.verticalSwipeRightPointXCoefficient; + } + + @Override + public double getVerticalSwipeLeftPointYCoefficient() { + return this.verticalSwipeLeftPointYCoefficient; + } + + @Override + public double getVerticalSwipeRightPointYCoefficient() { + return this.verticalSwipeRightPointYCoefficient; + } } diff --git a/src/main/resources/settings.json b/src/main/resources/settings.json index 0aec4b5..ee4a5e9 100644 --- a/src/main/resources/settings.json +++ b/src/main/resources/settings.json @@ -42,5 +42,17 @@ }, "elementCache": { "isEnabled": false + }, + "swipe": { + "timeout": 1, + "retries": 5, + "horizontalSwipeTopCoefficient": 0.2, + "horizontalSwipeBottomCoefficient": 0.8, + "horizontalSwipeLeftCoefficient": 0.5, + "horizontalSwipeRightCoefficient": 0.5, + "verticalSwipeTopCoefficient": 0.5, + "verticalSwipeBottomCoefficient": 0.5, + "verticalSwipeLeftCoefficient": 0.2, + "verticalSwipeRightCoefficient": 0.8 } } \ No newline at end of file diff --git a/src/test/resources/settings.androidwebsession.json b/src/test/resources/settings.androidwebsession.json index edc0f42..1e15f9d 100644 --- a/src/test/resources/settings.androidwebsession.json +++ b/src/test/resources/settings.androidwebsession.json @@ -35,5 +35,17 @@ }, "elementCache": { "isEnabled": true + }, + "swipe": { + "timeout": 1, + "retries": 5, + "horizontalSwipeTopPointXCoefficient": 0.5, + "horizontalSwipeBottomPointXCoefficient": 0.5, + "horizontalSwipeTopPointYCoefficient": 0.2, + "horizontalSwipeBottomPointYCoefficient": 0.8, + "verticalSwipeLeftPointXCoefficient": 0.2, + "verticalSwipeRightPointXCoefficient": 0.8, + "verticalSwipeLeftPointYCoefficient": 0.5, + "verticalSwipeRightPointYCoefficient": 0.5 } } \ No newline at end of file diff --git a/src/test/resources/settings.json b/src/test/resources/settings.json index 39fcd6b..3d7995d 100644 --- a/src/test/resources/settings.json +++ b/src/test/resources/settings.json @@ -47,6 +47,14 @@ }, "swipe": { "timeout": 1, - "retries": 5 + "retries": 5, + "horizontalSwipeTopPointXCoefficient": 0.5, + "horizontalSwipeBottomPointXCoefficient": 0.5, + "horizontalSwipeTopPointYCoefficient": 0.2, + "horizontalSwipeBottomPointYCoefficient": 0.8, + "verticalSwipeLeftPointXCoefficient": 0.2, + "verticalSwipeRightPointXCoefficient": 0.8, + "verticalSwipeLeftPointYCoefficient": 0.5, + "verticalSwipeRightPointYCoefficient": 0.5 } } \ No newline at end of file From 3172ef3de8ccefb73d964b65c7bbf60700441e09 Mon Sep 17 00:00:00 2001 From: nviarbitski Date: Mon, 6 Apr 2020 01:36:59 +0300 Subject: [PATCH 05/21] Replacing implementation of SwipeActions with TouchActions: - Deleting ScreenSizeType enum. - Deleting aquality.appium.mobile.elements.actions.SwipeActions. - Moving SwipeDirection into aquality.appium.mobile.actions. - Adding ITouchActions interface. - Adding TouchActions as implementation of ITouchActions, replacing SwipeActions with it. --- .../appium/mobile/actions/ITouchActions.java | 25 +++++ .../appium/mobile/actions/SwipeDirection.java | 8 ++ .../appium/mobile/actions/TouchActions.java | 45 ++++++++ .../mobile/elements/ScreenSizeType.java | 6 -- .../mobile/elements/SwipeDirection.java | 6 -- .../mobile/elements/actions/SwipeActions.java | 102 ------------------ 6 files changed, 78 insertions(+), 114 deletions(-) create mode 100644 src/main/java/aquality/appium/mobile/actions/ITouchActions.java create mode 100644 src/main/java/aquality/appium/mobile/actions/SwipeDirection.java create mode 100644 src/main/java/aquality/appium/mobile/actions/TouchActions.java delete mode 100644 src/main/java/aquality/appium/mobile/elements/ScreenSizeType.java delete mode 100644 src/main/java/aquality/appium/mobile/elements/SwipeDirection.java delete mode 100644 src/main/java/aquality/appium/mobile/elements/actions/SwipeActions.java diff --git a/src/main/java/aquality/appium/mobile/actions/ITouchActions.java b/src/main/java/aquality/appium/mobile/actions/ITouchActions.java new file mode 100644 index 0000000..23f8532 --- /dev/null +++ b/src/main/java/aquality/appium/mobile/actions/ITouchActions.java @@ -0,0 +1,25 @@ +package aquality.appium.mobile.actions; + +import org.openqa.selenium.Point; + +/** + * Describes general Touch Actions. + */ +public interface ITouchActions { + + /** + * Swipes from start point to end point using TouchAction. + * + * @param startPoint point on screen to swipe from. + * @param endPoint point on screen to swipe to. + */ + void swipe(Point startPoint, Point endPoint); + + /** + * Swipes from start point to end point using LongPress. + * + * @param startPoint point on screen to swipe from. + * @param endPoint point on screen to swipe to. + */ + void swipeWithLongPress(Point startPoint, Point endPoint); +} diff --git a/src/main/java/aquality/appium/mobile/actions/SwipeDirection.java b/src/main/java/aquality/appium/mobile/actions/SwipeDirection.java new file mode 100644 index 0000000..81dbba1 --- /dev/null +++ b/src/main/java/aquality/appium/mobile/actions/SwipeDirection.java @@ -0,0 +1,8 @@ +package aquality.appium.mobile.actions; + +public enum SwipeDirection { + UP, + DOWN, + LEFT, + RIGHT; +} diff --git a/src/main/java/aquality/appium/mobile/actions/TouchActions.java b/src/main/java/aquality/appium/mobile/actions/TouchActions.java new file mode 100644 index 0000000..3820e0d --- /dev/null +++ b/src/main/java/aquality/appium/mobile/actions/TouchActions.java @@ -0,0 +1,45 @@ +package aquality.appium.mobile.actions; + +import aquality.appium.mobile.application.AqualityServices; +import aquality.appium.mobile.configuration.ISwipeConfiguration; +import aquality.selenium.core.logging.Logger; +import io.appium.java_client.TouchAction; +import io.appium.java_client.touch.offset.PointOption; +import org.openqa.selenium.Point; + +import static io.appium.java_client.touch.WaitOptions.waitOptions; + +public class TouchActions implements ITouchActions { + + @Override + public void swipe(Point startPoint, Point endPoint) { + Logger.getInstance().info(String.format( + "Swiping: from coordinates x:%s y:%s to x:%s y:%s", + startPoint.getX(), + startPoint.getY(), + endPoint.getX(), + endPoint.getY())); + getTouchAction().press(PointOption.point(startPoint)) + .waitAction(waitOptions(AqualityServices.get(ISwipeConfiguration.class).getTimeout())) + .moveTo(PointOption.point(endPoint)).release().perform(); + } + + @Override + public void swipeWithLongPress(Point startPoint, Point endPoint) { + Logger.getInstance().info(String.format( + "Swiping: from coordinates x:%s y:%s to x:%s y:%s", + startPoint.getX(), + startPoint.getY(), + endPoint.getX(), + endPoint.getY())); + getTouchAction().longPress(PointOption.point(startPoint)) + .moveTo(PointOption.point(endPoint)).release().perform(); + } + + /** + * returns new instance of io.appium.java_client.TouchAction. + */ + private TouchAction getTouchAction() { + return new TouchAction<>(AqualityServices.getApplication().getDriver()); + } +} diff --git a/src/main/java/aquality/appium/mobile/elements/ScreenSizeType.java b/src/main/java/aquality/appium/mobile/elements/ScreenSizeType.java deleted file mode 100644 index 7382391..0000000 --- a/src/main/java/aquality/appium/mobile/elements/ScreenSizeType.java +++ /dev/null @@ -1,6 +0,0 @@ -package aquality.appium.mobile.elements; - -public enum ScreenSizeType { - HEIGHT, - WIDTH; -} diff --git a/src/main/java/aquality/appium/mobile/elements/SwipeDirection.java b/src/main/java/aquality/appium/mobile/elements/SwipeDirection.java deleted file mode 100644 index 3699fe6..0000000 --- a/src/main/java/aquality/appium/mobile/elements/SwipeDirection.java +++ /dev/null @@ -1,6 +0,0 @@ -package aquality.appium.mobile.elements; - -public enum SwipeDirection { - UP, - DOWN; -} diff --git a/src/main/java/aquality/appium/mobile/elements/actions/SwipeActions.java b/src/main/java/aquality/appium/mobile/elements/actions/SwipeActions.java deleted file mode 100644 index faac8c3..0000000 --- a/src/main/java/aquality/appium/mobile/elements/actions/SwipeActions.java +++ /dev/null @@ -1,102 +0,0 @@ -package aquality.appium.mobile.elements.actions; - -import aquality.appium.mobile.application.AqualityServices; -import aquality.appium.mobile.configuration.ISwipeConfiguration; -import aquality.appium.mobile.elements.ScreenSizeType; -import aquality.appium.mobile.elements.SwipeDirection; -import aquality.appium.mobile.elements.interfaces.IElement; -import aquality.selenium.core.logging.Logger; -import io.appium.java_client.TouchAction; -import io.appium.java_client.touch.offset.PointOption; -import org.openqa.selenium.Dimension; - -import static io.appium.java_client.touch.WaitOptions.waitOptions; - -public class SwipeActions { - - /** - * returns new instance of TouchAction. - */ - private static TouchAction getTouchAction() { - return new TouchAction<>(AqualityServices.getApplication().getDriver()); - } - - /** - * Swipes from start coordinates to end coordinates using TouchAction. - * - * @param x1 horizontal start coordinate. - * @param y1 vertical start coordinate. - * @param x2 horizontal end coordinate. - * @param y2 vertical end coordinate. - */ - public static void swipe(int x1, int y1, int x2, int y2) { - Logger.getInstance().info(String.format("Swiping: from coordinates x:%s y:%s to x:%s y:%s", x1, y1, x2, y2)); - getTouchAction().press(PointOption.point(x1, y1)) - .waitAction(waitOptions(AqualityServices.get(ISwipeConfiguration.class).getTimeout())) - .moveTo(PointOption.point(x2, y2)).release().perform(); - } - - /** - * Swipes from start coordinates to end coordinates using LongPress. - * - * @param x1 horizontal start coordinate. - * @param y1 vertical start coordinate. - * @param x2 horizontal end coordinate. - * @param y2 vertical end coordinate. - */ - public static void swipeWithLongPress(int x1, int y1, int x2, int y2) { - Logger.getInstance().info(String.format("Swiping: from coordinates x:%s y:%s to x:%s y:%s", x1, y1, x2, y2)); - getTouchAction().longPress(PointOption.point(x1, y1)) - .moveTo(PointOption.point(x2, y2)).release().perform(); - } - - /** - * Returns the coordinate according to the screen height/width adjusted for the swipe coefficient. - * - * @param size width/height - * @param swipeCoefficient coefficient relative to the top/bottom of the screen - * @return coordinate to swipe from/to - */ - public static int getCoordinate(ScreenSizeType size, double swipeCoefficient) { - Dimension screenSize = AqualityServices.getApplication().getDriver().manage().window().getSize(); - if (size == ScreenSizeType.HEIGHT) { - return (int) (screenSize.getHeight() * swipeCoefficient); - } - return (int) (screenSize.getWidth() * swipeCoefficient); - } - - /** - * Scrolls until element is not displayed using the fixed number of retries. - * - * @param element element to swipe to. - * @param direction direction to swipe. - */ - public static void scrollToElement(IElement element, SwipeDirection direction) { - int numberOfRetires = AqualityServices.get(ISwipeConfiguration.class).getRetries(); - while (numberOfRetires >= 0) { - if (!element.state().isDisplayed()) { - switch (direction) { - case DOWN: - swipe( - getCoordinate(ScreenSizeType.WIDTH, 0.5), - getCoordinate(ScreenSizeType.HEIGHT, 0.8), - getCoordinate(ScreenSizeType.WIDTH, 0.5), - getCoordinate(ScreenSizeType.HEIGHT, 0.2)); - break; - case UP: - swipe( - getCoordinate(ScreenSizeType.WIDTH, 0.5), - getCoordinate(ScreenSizeType.HEIGHT, 0.2), - getCoordinate(ScreenSizeType.WIDTH, 0.5), - getCoordinate(ScreenSizeType.HEIGHT, 0.8)); - break; - default: - throw new IllegalArgumentException( - String.format("'%s' direction does not exist", direction.toString())); - } - } - numberOfRetires--; - } - } - -} From e6bb23cd18298b11f8079f7bf26c246cb6ae9c21 Mon Sep 17 00:00:00 2001 From: nviarbitski Date: Mon, 6 Apr 2020 01:43:41 +0300 Subject: [PATCH 06/21] Adding ElementTouchActions - Adding IElementTouchActions interface. - Adding ElementTouchActions as implementation for working with elements. - Updating ViewControlsScreen with new implementation of ElementTouchActions. --- .../elements/actions/ElementTouchActions.java | 122 ++++++++++++++++++ .../actions/IElementTouchActions.java | 35 +++++ .../apidemos/screens/ViewControlsScreen.java | 29 ++--- 3 files changed, 170 insertions(+), 16 deletions(-) create mode 100644 src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java create mode 100644 src/main/java/aquality/appium/mobile/elements/actions/IElementTouchActions.java diff --git a/src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java b/src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java new file mode 100644 index 0000000..ace6760 --- /dev/null +++ b/src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java @@ -0,0 +1,122 @@ +package aquality.appium.mobile.elements.actions; + +import aquality.appium.mobile.actions.SwipeDirection; +import aquality.appium.mobile.actions.TouchActions; +import aquality.appium.mobile.application.AqualityServices; +import aquality.appium.mobile.configuration.ISwipeConfiguration; +import aquality.appium.mobile.elements.interfaces.IElement; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; + +public class ElementTouchActions implements IElementTouchActions { + + private final Point scrollDownStartPoint = recalculatePointCoordinates( + getBottomRightCornerPoint(), + AqualityServices.get(ISwipeConfiguration.class).getHorizontalSwipeBottomPointXCoefficient(), + AqualityServices.get(ISwipeConfiguration.class).getHorizontalSwipeBottomPointYCoefficient()); + + private final Point scrollDownEndPoint = recalculatePointCoordinates( + getBottomRightCornerPoint(), + AqualityServices.get(ISwipeConfiguration.class).getHorizontalSwipeTopPointXCoefficient(), + AqualityServices.get(ISwipeConfiguration.class).getHorizontalSwipeTopPointYCoefficient()); + + private final Point swipeLeftStartPoint = recalculatePointCoordinates( + getBottomRightCornerPoint(), + AqualityServices.get(ISwipeConfiguration.class).getVerticalSwipeRightPointXCoefficient(), + AqualityServices.get(ISwipeConfiguration.class).getVerticalSwipeRightPointYCoefficient()); + + private final Point swipeLeftEndPoint = recalculatePointCoordinates( + getBottomRightCornerPoint(), + AqualityServices.get(ISwipeConfiguration.class).getVerticalSwipeLeftPointXCoefficient(), + AqualityServices.get(ISwipeConfiguration.class).getVerticalSwipeLeftPointYCoefficient()); + + private final Point scrollUpStartPoint = scrollDownEndPoint; + + private final Point scrollUpEndPoint = scrollDownStartPoint; + + private final Point swipeRightStartPoint = swipeLeftEndPoint; + + private final Point swipeRightEndPoint = swipeLeftStartPoint; + + @Override + public void swipe(IElement element, Point endPoint) { + Point elementCenter = getElementCenter(element); + getTouchActions().swipe(elementCenter, endPoint); + } + + @Override + public void swipeWithLongPress(IElement element, Point endPoint) { + Point elementCenter = getElementCenter(element); + getTouchActions().swipeWithLongPress(elementCenter, endPoint); + } + + @Override + public void scrollToElement(IElement element, SwipeDirection direction) { + int numberOfRetries = AqualityServices.get(ISwipeConfiguration.class).getRetries(); + TouchActions touchActions = getTouchActions(); + while (numberOfRetries > 0) { + if (!element.state().isDisplayed()) { + switch (direction) { + case DOWN: + touchActions.swipe(scrollDownStartPoint, scrollDownEndPoint); + break; + case UP: + touchActions.swipe(scrollUpStartPoint, scrollUpEndPoint); + break; + case LEFT: + touchActions.swipe(swipeLeftStartPoint, swipeLeftEndPoint); + break; + case RIGHT: + touchActions.swipe(swipeRightStartPoint, swipeRightEndPoint); + break; + default: + throw new IllegalArgumentException( + String.format("'%s' direction does not exist", direction.toString())); + } + } + numberOfRetries--; + } + } + + /** + * returns new instance of aquality.appium.mobile.actions.TouchActions. + */ + private TouchActions getTouchActions() { + return new TouchActions(); + } + + /** + * returns the the center of provided element as Point. + * + * @param element element. + */ + private Point getElementCenter(IElement element) { + Dimension elementSize = element.getElement().getSize(); + Point elementLocation = element.getElement().getLocation(); + int centerX = elementLocation.getX() - elementSize.width / 2; + int centerY = elementLocation.getY() - elementSize.height / 2; + return new Point(centerX, centerY); + } + + /** + * returns Point in the bottom right corner of the screen. + */ + private Point getBottomRightCornerPoint() { + Dimension screenSize = AqualityServices.getApplication().getDriver().manage().window().getSize(); + return new Point(screenSize.width, screenSize.height); + } + + /** + * Returns the point with recalculated coordinates. + * + * @param point point to recalculate coordinates + * @param coefficientX coefficient to recalculate the point's x coordinate. Example: x' = x * coefficientX + * @param coefficientY coefficient to recalculate the point's y coordinate. Example: y' = y * coefficientY + * @return point with recalculated coordinates according to the xCoefficient and yCoefficient + */ + private Point recalculatePointCoordinates(Point point, double coefficientX, double coefficientY) { + return new Point( + (int) (point.getX() * coefficientX), + (int) (point.getY() * coefficientY)); + } +} diff --git a/src/main/java/aquality/appium/mobile/elements/actions/IElementTouchActions.java b/src/main/java/aquality/appium/mobile/elements/actions/IElementTouchActions.java new file mode 100644 index 0000000..ed21102 --- /dev/null +++ b/src/main/java/aquality/appium/mobile/elements/actions/IElementTouchActions.java @@ -0,0 +1,35 @@ +package aquality.appium.mobile.elements.actions; + +import aquality.appium.mobile.actions.SwipeDirection; +import aquality.appium.mobile.elements.interfaces.IElement; +import org.openqa.selenium.Point; + +/** + * Describes Touch Actions for elements. + */ +public interface IElementTouchActions { + + /** + * Swipes from element to end point using TouchAction. + * + * @param element element on screen to swipe from. + * @param endPoint point on screen to swipe to. + */ + void swipe(IElement element, Point endPoint); + + /** + * Swipes from element to end point using LongPress. + * + * @param element element on screen to swipe from. + * @param endPoint point on screen to swipe to. + */ + void swipeWithLongPress(IElement element, Point endPoint); + + /** + * Scrolls current screen in provided direction until element is displayed. + * + * @param element element to scroll to. + * @param direction direction to swipe. + */ + void scrollToElement(IElement element, SwipeDirection direction); +} diff --git a/src/test/java/samples/android/nativeapp/apidemos/screens/ViewControlsScreen.java b/src/test/java/samples/android/nativeapp/apidemos/screens/ViewControlsScreen.java index a9331ff..29960cb 100644 --- a/src/test/java/samples/android/nativeapp/apidemos/screens/ViewControlsScreen.java +++ b/src/test/java/samples/android/nativeapp/apidemos/screens/ViewControlsScreen.java @@ -1,7 +1,7 @@ package samples.android.nativeapp.apidemos.screens; -import aquality.appium.mobile.elements.SwipeDirection; -import aquality.appium.mobile.elements.actions.SwipeActions; +import aquality.appium.mobile.actions.SwipeDirection; +import aquality.appium.mobile.elements.actions.ElementTouchActions; import aquality.appium.mobile.elements.interfaces.IButton; import aquality.appium.mobile.elements.interfaces.ICheckBox; import aquality.appium.mobile.elements.interfaces.ILabel; @@ -11,9 +11,6 @@ import org.openqa.selenium.By; public class ViewControlsScreen extends AndroidScreen { - public ViewControlsScreen() { - super(By.id("android:id/content"), "View/Controls"); - } public IRadioButton getRadioButton(int number) { return getElementFactory().getRadioButton( @@ -27,29 +24,29 @@ public ICheckBox getCheckBox(int number) { String.valueOf(number)); } - private ILabel lblAllInsideScrollView() { - return getElementFactory().getLabel( - MobileBy.AccessibilityId("(And all inside of a ScrollView!)"), - "All inside of Scroll View"); - } + private final IButton btnDisabled = getElementFactory().getButton(MobileBy.id("button_disabled"), "Disabled"); - private IButton btnDisabled() { - return getElementFactory().getButton(MobileBy.id("button_disabled"), "Disabled"); + public ViewControlsScreen() { + super(By.id("android:id/content"), "View/Controls"); } public void scrollToAllInsideScrollViewLabel() { - SwipeActions.scrollToElement(lblAllInsideScrollView(), SwipeDirection.DOWN); + new ElementTouchActions().scrollToElement(lblAllInsideScrollView, SwipeDirection.DOWN); } public String getAllInsideScrollViewLabelText() { - return lblAllInsideScrollView().getText(); + return lblAllInsideScrollView.getText(); } public void scrollToDisabledButton() { - SwipeActions.scrollToElement(btnDisabled(), SwipeDirection.UP); + new ElementTouchActions().scrollToElement(btnDisabled, SwipeDirection.UP); } public boolean isDisabledButtonClickable() { - return btnDisabled().state().isClickable(); + return btnDisabled.state().isClickable(); } + + private final ILabel lblAllInsideScrollView = getElementFactory().getLabel( + MobileBy.AccessibilityId("(And all inside of a ScrollView!)"), + "All inside of Scroll View"); } From 60aa4318a5bf9bd94143a359e53e3a67aad8c51f Mon Sep 17 00:00:00 2001 From: nviarbitski Date: Wed, 8 Apr 2020 01:43:57 +0300 Subject: [PATCH 07/21] Adding localization - Added loc.action.swipe and loc.action.swipeLongPress into resources.localization.be/en/ru.json - Fixed spacing in DriverSettings --- .../appium/mobile/configuration/DriverSettings.java | 8 ++++---- src/main/resources/localization/be.json | 4 +++- src/main/resources/localization/en.json | 4 +++- src/main/resources/localization/ru.json | 4 +++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/aquality/appium/mobile/configuration/DriverSettings.java b/src/main/java/aquality/appium/mobile/configuration/DriverSettings.java index 66df445..ac6938c 100644 --- a/src/main/java/aquality/appium/mobile/configuration/DriverSettings.java +++ b/src/main/java/aquality/appium/mobile/configuration/DriverSettings.java @@ -28,13 +28,13 @@ public Capabilities getCapabilities() { Map capabilitiesFromSettings = getCapabilitiesFromSettings(); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilitiesFromSettings.forEach(capabilities::setCapability); - if(hasApplicationPath()) { + if (hasApplicationPath()) { capabilities.setCapability(APP_CAPABILITY_KEY, getAbsolutePath(getApplicationPath())); } return capabilities; } - private Map getCapabilitiesFromSettings(){ + private Map getCapabilitiesFromSettings() { return settingsFile.getMap(getDriverCapabilitiesJsonPath()); } @@ -58,11 +58,11 @@ public String getApplicationPath() { return String.valueOf(settingsFile.getValue(getDriverSettingsPath() + "/" + APPLICATION_PATH_KEY)); } - private String getDriverCapabilitiesJsonPath(){ + private String getDriverCapabilitiesJsonPath() { return getDriverSettingsPath() + "/capabilities"; } - private String getDriverSettingsPath(){ + private String getDriverSettingsPath() { return String.format("/driverSettings/%1$s", platformName.toString().toLowerCase()); } } diff --git a/src/main/resources/localization/be.json b/src/main/resources/localization/be.json index df07dab..5956638 100644 --- a/src/main/resources/localization/be.json +++ b/src/main/resources/localization/be.json @@ -37,5 +37,7 @@ "loc.text.typing" : "Уводзім '%s'", "loc.text.focusing": "Факусуемся на полі", "loc.text.unfocusing": "Адводзім фокус з поля", - "loc.text.masked_value": "********" + "loc.text.masked_value": "********", + "loc.action.swipe": "Праводзім па экране з каардынатаў (x:%1$s; y:%2$s) у (x:%3$s; y:%4$s)", + "loc.action.swipeLongPress": "Праводзім па экране доўгім націскам з каардынатаў (x:%1$s; y:%2$s) у (x:%3$s; y:%4$s)" } diff --git a/src/main/resources/localization/en.json b/src/main/resources/localization/en.json index ccead49..3cbea6d 100644 --- a/src/main/resources/localization/en.json +++ b/src/main/resources/localization/en.json @@ -37,5 +37,7 @@ "loc.text.typing": "Typing '%s'", "loc.text.focusing": "Focusing on field", "loc.text.unfocusing": "Unfocusing from field", - "loc.text.masked_value": "********" + "loc.text.masked_value": "********", + "loc.action.swipe": "Swiping from coordinates (x:%1$s; y:%2$s) to (x:%3$s; y:%4$s)", + "loc.action.swipeLongPress": "Swiping using long press from coordinates (x:%1$s; y:%2$s) to (x:%3$s; y:%4$s)" } diff --git a/src/main/resources/localization/ru.json b/src/main/resources/localization/ru.json index 4686ab9..6ce8c03 100644 --- a/src/main/resources/localization/ru.json +++ b/src/main/resources/localization/ru.json @@ -37,5 +37,7 @@ "loc.text.typing": "Ввод текста '%s'", "loc.text.focusing": "Наведение курсора на поле", "loc.text.unfocusing": "Сдвиг курсора с поля", - "loc.text.masked_value": "********" + "loc.text.masked_value": "********", + "loc.action.swipe": "Проводим по экрану из координат (x:%1$s; y:%2$s) в (x:%3$s; y:%4$s)", + "loc.action.swipeLongPress": "Проводим по экрану долгим нажатием из координат (x:%1$s; y:%2$s) в (x:%3$s; y:%4$s)" } From 33809f0cb5ac699434d6246c36a28d2e11907efe Mon Sep 17 00:00:00 2001 From: nviarbitski Date: Wed, 8 Apr 2020 01:46:59 +0300 Subject: [PATCH 08/21] Updating Swipe Configuration - Adding getTouchActionsImplementation in IConfigurationModule - Fixing javadoc for getSwipeConfigutationImplementation in IConfigurationModule - Adding ITouchActions binding in MobileModule - Adding getTouchActions into AqualityServices - Fixing cast in SwipeConfiguration --- .../appium/mobile/application/AqualityServices.java | 10 ++++++++++ .../appium/mobile/application/MobileModule.java | 2 ++ .../mobile/configuration/IConfigurationsModule.java | 12 +++++++++++- .../mobile/configuration/SwipeConfiguration.java | 2 +- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/aquality/appium/mobile/application/AqualityServices.java b/src/main/java/aquality/appium/mobile/application/AqualityServices.java index 5282e05..3903f48 100644 --- a/src/main/java/aquality/appium/mobile/application/AqualityServices.java +++ b/src/main/java/aquality/appium/mobile/application/AqualityServices.java @@ -1,5 +1,6 @@ package aquality.appium.mobile.application; +import aquality.appium.mobile.actions.ITouchActions; import aquality.appium.mobile.configuration.IApplicationProfile; import aquality.appium.mobile.configuration.IConfiguration; import aquality.appium.mobile.configuration.ILocalServiceSettings; @@ -178,4 +179,13 @@ public static ILocalServiceSettings getLocalServiceSettings() { public static IConfiguration getConfiguration() { return get(IConfiguration.class); } + + /** + * Gets the the utility used to perform touch actions. + * + * @return instance of touch actions. + */ + public static ITouchActions getTouchActions() { + return get(ITouchActions.class); + } } diff --git a/src/main/java/aquality/appium/mobile/application/MobileModule.java b/src/main/java/aquality/appium/mobile/application/MobileModule.java index ce8842c..b3d2276 100644 --- a/src/main/java/aquality/appium/mobile/application/MobileModule.java +++ b/src/main/java/aquality/appium/mobile/application/MobileModule.java @@ -1,5 +1,6 @@ package aquality.appium.mobile.application; +import aquality.appium.mobile.actions.ITouchActions; import aquality.appium.mobile.configuration.IApplicationProfile; import aquality.appium.mobile.configuration.IConfiguration; import aquality.appium.mobile.configuration.IConfigurationsModule; @@ -24,5 +25,6 @@ protected void configure() { bind(IConfiguration.class).to(getConfigurationImplementation()); bind(IElementFactory.class).to(getElementFactoryImplementation()); bind(ISwipeConfiguration.class).to(getSwipeConfigurationImplementation()).in(Singleton.class); + bind(ITouchActions.class).to(getTouchActionsImplementation()).in(Singleton.class); } } diff --git a/src/main/java/aquality/appium/mobile/configuration/IConfigurationsModule.java b/src/main/java/aquality/appium/mobile/configuration/IConfigurationsModule.java index c526a33..57fb11d 100644 --- a/src/main/java/aquality/appium/mobile/configuration/IConfigurationsModule.java +++ b/src/main/java/aquality/appium/mobile/configuration/IConfigurationsModule.java @@ -1,5 +1,8 @@ package aquality.appium.mobile.configuration; +import aquality.appium.mobile.actions.ITouchActions; +import aquality.appium.mobile.actions.TouchActions; + /** * Describes implementations of configurations to be registered in DI container. */ @@ -27,9 +30,16 @@ default Class getConfigurationImplementation() { } /** - * @return class which implements {@link IConfiguration} + * @return class which implements {@link ISwipeConfiguration} */ default Class getSwipeConfigurationImplementation() { return SwipeConfiguration.class; } + + /** + * @return class which implements {@link ITouchActions} + */ + default Class getTouchActionsImplementation() { + return TouchActions.class; + } } diff --git a/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java b/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java index 7ac598c..4c1fe51 100644 --- a/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java +++ b/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java @@ -19,7 +19,7 @@ public class SwipeConfiguration implements ISwipeConfiguration { @Inject public SwipeConfiguration(ISettingsFile settingsFile) { - this.retries = Integer.parseInt(settingsFile.getValue("/swipe/retries").toString()); + this.retries = (int) settingsFile.getValue("/swipe/retries"); this.timeout = Duration.ofSeconds(Long.parseLong(settingsFile.getValue("/swipe/timeout").toString())); this.horizontalSwipeTopPointXCoefficient = Double.parseDouble( settingsFile.getValue("/swipe/horizontalSwipeTopPointXCoefficient").toString()); From 5a0c56c7e32484873981bc547b11a4260a8b8446 Mon Sep 17 00:00:00 2001 From: nviarbitski Date: Wed, 8 Apr 2020 01:51:53 +0300 Subject: [PATCH 09/21] Adding getTouchActions() into Element - adding getTouchActions into IElement - adding getTouchActions implementation into Element --- .../java/aquality/appium/mobile/elements/Element.java | 7 +++++++ .../appium/mobile/elements/interfaces/IElement.java | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/aquality/appium/mobile/elements/Element.java b/src/main/java/aquality/appium/mobile/elements/Element.java index d4462fb..96a48a6 100644 --- a/src/main/java/aquality/appium/mobile/elements/Element.java +++ b/src/main/java/aquality/appium/mobile/elements/Element.java @@ -2,6 +2,8 @@ import aquality.appium.mobile.application.Application; import aquality.appium.mobile.application.AqualityServices; +import aquality.appium.mobile.elements.actions.ElementTouchActions; +import aquality.appium.mobile.elements.actions.IElementTouchActions; import aquality.appium.mobile.elements.interfaces.IElement; import aquality.appium.mobile.elements.interfaces.IElementFactory; import aquality.selenium.core.configurations.IElementCacheConfiguration; @@ -86,4 +88,9 @@ public void sendKeys(Keys key) { logElementAction("loc.text.sending.keys", Keys.class.getSimpleName().concat(".").concat(key.name())); doWithRetry(() -> getElement().sendKeys(key)); } + + @Override + public IElementTouchActions getTouchActions() { + return new ElementTouchActions(this); + } } diff --git a/src/main/java/aquality/appium/mobile/elements/interfaces/IElement.java b/src/main/java/aquality/appium/mobile/elements/interfaces/IElement.java index 5d7ab6f..7069fa0 100644 --- a/src/main/java/aquality/appium/mobile/elements/interfaces/IElement.java +++ b/src/main/java/aquality/appium/mobile/elements/interfaces/IElement.java @@ -2,6 +2,7 @@ import aquality.appium.mobile.elements.Attributes; import aquality.appium.mobile.elements.ElementType; +import aquality.appium.mobile.elements.actions.IElementTouchActions; import aquality.selenium.core.elements.ElementState; import io.appium.java_client.MobileElement; import org.openqa.selenium.By; @@ -99,4 +100,11 @@ default MobileElement getElement() { default String getAttribute(Attributes attribute) { return getAttribute(attribute.toString()); } + + /** + * Gets the the utility used to perform touch actions for element. + * + * @return instance of element touch actions. + */ + IElementTouchActions getTouchActions(); } From e34d8ef501adf84ad2efd51fb2c0c0e2fcd5e6a4 Mon Sep 17 00:00:00 2001 From: nviarbitski Date: Wed, 8 Apr 2020 01:53:52 +0300 Subject: [PATCH 10/21] Updating implementation of TouchActions - Adding performTouchAction with UnaryOperator - Replacing logger with getLocalizedLogger --- .../appium/mobile/actions/TouchActions.java | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/main/java/aquality/appium/mobile/actions/TouchActions.java b/src/main/java/aquality/appium/mobile/actions/TouchActions.java index 3820e0d..c93f831 100644 --- a/src/main/java/aquality/appium/mobile/actions/TouchActions.java +++ b/src/main/java/aquality/appium/mobile/actions/TouchActions.java @@ -2,44 +2,42 @@ import aquality.appium.mobile.application.AqualityServices; import aquality.appium.mobile.configuration.ISwipeConfiguration; -import aquality.selenium.core.logging.Logger; +import aquality.selenium.core.utilities.IElementActionRetrier; import io.appium.java_client.TouchAction; import io.appium.java_client.touch.offset.PointOption; import org.openqa.selenium.Point; - +import java.util.function.UnaryOperator; import static io.appium.java_client.touch.WaitOptions.waitOptions; public class TouchActions implements ITouchActions { @Override public void swipe(Point startPoint, Point endPoint) { - Logger.getInstance().info(String.format( - "Swiping: from coordinates x:%s y:%s to x:%s y:%s", + AqualityServices.getLocalizedLogger().info( + "loc.action.swipe", startPoint.getX(), startPoint.getY(), endPoint.getX(), - endPoint.getY())); - getTouchAction().press(PointOption.point(startPoint)) - .waitAction(waitOptions(AqualityServices.get(ISwipeConfiguration.class).getTimeout())) - .moveTo(PointOption.point(endPoint)).release().perform(); + endPoint.getY()); + performTouchAction(touchAction -> touchAction.press(PointOption.point(startPoint)) + .waitAction(waitOptions(AqualityServices.get(ISwipeConfiguration.class).getTimeout())), endPoint); } @Override public void swipeWithLongPress(Point startPoint, Point endPoint) { - Logger.getInstance().info(String.format( - "Swiping: from coordinates x:%s y:%s to x:%s y:%s", + AqualityServices.getLocalizedLogger().info( + "loc.action.swipeLongPress", startPoint.getX(), startPoint.getY(), endPoint.getX(), - endPoint.getY())); - getTouchAction().longPress(PointOption.point(startPoint)) - .moveTo(PointOption.point(endPoint)).release().perform(); + endPoint.getY()); + performTouchAction(touchAction -> touchAction.longPress(PointOption.point(startPoint)) + .waitAction(waitOptions(AqualityServices.get(ISwipeConfiguration.class).getTimeout())), endPoint); } - /** - * returns new instance of io.appium.java_client.TouchAction. - */ - private TouchAction getTouchAction() { - return new TouchAction<>(AqualityServices.getApplication().getDriver()); + private void performTouchAction(UnaryOperator> function, Point endPoint) { + TouchAction touchAction = new TouchAction<>(AqualityServices.getApplication().getDriver()); + AqualityServices.get(IElementActionRetrier.class).doWithRetry(() -> + function.apply(touchAction).moveTo(PointOption.point(endPoint)).release().perform()); } } From f9c2378af95957ee964eb78b51d8b8cc970a2b9f Mon Sep 17 00:00:00 2001 From: nviarbitski Date: Wed, 8 Apr 2020 01:55:57 +0300 Subject: [PATCH 11/21] Updating implementation of IElementTouchActions - removing IElement element from interface methods' arguments in IElementTouchActions - adding element into class constructor - fixing code smells - removing IElement element from interface methods implementation - adding calls to AqualityServices.getTouchActions() --- .../elements/actions/ElementTouchActions.java | 108 ++++++++---------- .../actions/IElementTouchActions.java | 10 +- 2 files changed, 53 insertions(+), 65 deletions(-) diff --git a/src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java b/src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java index ace6760..ecd2335 100644 --- a/src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java +++ b/src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java @@ -1,7 +1,7 @@ package aquality.appium.mobile.elements.actions; +import aquality.appium.mobile.actions.ITouchActions; import aquality.appium.mobile.actions.SwipeDirection; -import aquality.appium.mobile.actions.TouchActions; import aquality.appium.mobile.application.AqualityServices; import aquality.appium.mobile.configuration.ISwipeConfiguration; import aquality.appium.mobile.elements.interfaces.IElement; @@ -9,51 +9,54 @@ import org.openqa.selenium.Point; public class ElementTouchActions implements IElementTouchActions { - - private final Point scrollDownStartPoint = recalculatePointCoordinates( - getBottomRightCornerPoint(), - AqualityServices.get(ISwipeConfiguration.class).getHorizontalSwipeBottomPointXCoefficient(), - AqualityServices.get(ISwipeConfiguration.class).getHorizontalSwipeBottomPointYCoefficient()); - - private final Point scrollDownEndPoint = recalculatePointCoordinates( - getBottomRightCornerPoint(), - AqualityServices.get(ISwipeConfiguration.class).getHorizontalSwipeTopPointXCoefficient(), - AqualityServices.get(ISwipeConfiguration.class).getHorizontalSwipeTopPointYCoefficient()); - - private final Point swipeLeftStartPoint = recalculatePointCoordinates( - getBottomRightCornerPoint(), - AqualityServices.get(ISwipeConfiguration.class).getVerticalSwipeRightPointXCoefficient(), - AqualityServices.get(ISwipeConfiguration.class).getVerticalSwipeRightPointYCoefficient()); - - private final Point swipeLeftEndPoint = recalculatePointCoordinates( - getBottomRightCornerPoint(), - AqualityServices.get(ISwipeConfiguration.class).getVerticalSwipeLeftPointXCoefficient(), - AqualityServices.get(ISwipeConfiguration.class).getVerticalSwipeLeftPointYCoefficient()); - - private final Point scrollUpStartPoint = scrollDownEndPoint; - - private final Point scrollUpEndPoint = scrollDownStartPoint; - - private final Point swipeRightStartPoint = swipeLeftEndPoint; - - private final Point swipeRightEndPoint = swipeLeftStartPoint; + private IElement element; + private Point scrollDownStartPoint; + private Point scrollDownEndPoint; + private Point swipeLeftStartPoint; + private Point swipeLeftEndPoint; + private Point scrollUpStartPoint; + private Point scrollUpEndPoint; + private Point swipeRightStartPoint; + private Point swipeRightEndPoint; + + public ElementTouchActions(IElement element) { + this.element = element; + this.scrollDownStartPoint = recalculatePointCoordinates( + getBottomRightCornerPoint(), + getISwipeConfiguration().getHorizontalSwipeBottomPointXCoefficient(), + getISwipeConfiguration().getHorizontalSwipeBottomPointYCoefficient()); + this.scrollDownEndPoint = recalculatePointCoordinates( + getBottomRightCornerPoint(), + getISwipeConfiguration().getHorizontalSwipeTopPointXCoefficient(), + getISwipeConfiguration().getHorizontalSwipeTopPointYCoefficient()); + this.swipeLeftStartPoint = recalculatePointCoordinates( + getBottomRightCornerPoint(), + getISwipeConfiguration().getVerticalSwipeRightPointXCoefficient(), + getISwipeConfiguration().getVerticalSwipeRightPointYCoefficient()); + this.swipeLeftEndPoint = recalculatePointCoordinates( + getBottomRightCornerPoint(), + getISwipeConfiguration().getVerticalSwipeLeftPointXCoefficient(), + getISwipeConfiguration().getVerticalSwipeLeftPointYCoefficient()); + this.scrollUpStartPoint = this.scrollDownEndPoint; + this.scrollUpEndPoint = this.scrollDownStartPoint; + this.swipeRightStartPoint = this.swipeLeftEndPoint; + this.swipeRightEndPoint = this.swipeLeftStartPoint; + } @Override - public void swipe(IElement element, Point endPoint) { - Point elementCenter = getElementCenter(element); - getTouchActions().swipe(elementCenter, endPoint); + public void swipe(Point endPoint) { + AqualityServices.getTouchActions().swipe(element.getElement().getCenter(), endPoint); } @Override - public void swipeWithLongPress(IElement element, Point endPoint) { - Point elementCenter = getElementCenter(element); - getTouchActions().swipeWithLongPress(elementCenter, endPoint); + public void swipeWithLongPress(Point endPoint) { + AqualityServices.getTouchActions().swipeWithLongPress(element.getElement().getCenter(), endPoint); } @Override - public void scrollToElement(IElement element, SwipeDirection direction) { + public void scrollToElement(SwipeDirection direction) { int numberOfRetries = AqualityServices.get(ISwipeConfiguration.class).getRetries(); - TouchActions touchActions = getTouchActions(); + ITouchActions touchActions = AqualityServices.getTouchActions(); while (numberOfRetries > 0) { if (!element.state().isDisplayed()) { switch (direction) { @@ -79,27 +82,7 @@ public void scrollToElement(IElement element, SwipeDirection direction) { } /** - * returns new instance of aquality.appium.mobile.actions.TouchActions. - */ - private TouchActions getTouchActions() { - return new TouchActions(); - } - - /** - * returns the the center of provided element as Point. - * - * @param element element. - */ - private Point getElementCenter(IElement element) { - Dimension elementSize = element.getElement().getSize(); - Point elementLocation = element.getElement().getLocation(); - int centerX = elementLocation.getX() - elementSize.width / 2; - int centerY = elementLocation.getY() - elementSize.height / 2; - return new Point(centerX, centerY); - } - - /** - * returns Point in the bottom right corner of the screen. + * Returns Point in the bottom right corner of the screen. */ private Point getBottomRightCornerPoint() { Dimension screenSize = AqualityServices.getApplication().getDriver().manage().window().getSize(); @@ -119,4 +102,13 @@ private Point recalculatePointCoordinates(Point point, double coefficientX, doub (int) (point.getX() * coefficientX), (int) (point.getY() * coefficientY)); } + + /** + * Returns ISwipeConfiguration class. + * + * @return ISwipeConfiguration class + */ + private ISwipeConfiguration getISwipeConfiguration() { + return AqualityServices.get(ISwipeConfiguration.class); + } } diff --git a/src/main/java/aquality/appium/mobile/elements/actions/IElementTouchActions.java b/src/main/java/aquality/appium/mobile/elements/actions/IElementTouchActions.java index ed21102..ce509b4 100644 --- a/src/main/java/aquality/appium/mobile/elements/actions/IElementTouchActions.java +++ b/src/main/java/aquality/appium/mobile/elements/actions/IElementTouchActions.java @@ -1,7 +1,6 @@ package aquality.appium.mobile.elements.actions; import aquality.appium.mobile.actions.SwipeDirection; -import aquality.appium.mobile.elements.interfaces.IElement; import org.openqa.selenium.Point; /** @@ -12,24 +11,21 @@ public interface IElementTouchActions { /** * Swipes from element to end point using TouchAction. * - * @param element element on screen to swipe from. * @param endPoint point on screen to swipe to. */ - void swipe(IElement element, Point endPoint); + void swipe(Point endPoint); /** * Swipes from element to end point using LongPress. * - * @param element element on screen to swipe from. * @param endPoint point on screen to swipe to. */ - void swipeWithLongPress(IElement element, Point endPoint); + void swipeWithLongPress(Point endPoint); /** * Scrolls current screen in provided direction until element is displayed. * - * @param element element to scroll to. * @param direction direction to swipe. */ - void scrollToElement(IElement element, SwipeDirection direction); + void scrollToElement(SwipeDirection direction); } From 89730cacdc2cdc1d60cb0103fafb07807cbb3dc8 Mon Sep 17 00:00:00 2001 From: nviarbitski Date: Wed, 8 Apr 2020 02:00:51 +0300 Subject: [PATCH 12/21] Adding horizontal scroll test and fixing vertical scroll test - replacing explicit call to ElementTouchActions with IElement.getTouchActions in ViewControlsScreen - renaming testSwipeToElement to testVerticalSwipeToElement - adding View Tabs Scrollable Screen - adding new activity for View Tabs Scrollable in ApplicationActivity - adding testHorizontalSwipeToElement --- .../AndroidBasicInteractionsTest.java | 26 ++++++++-- .../apidemos/ApplicationActivity.java | 4 +- .../apidemos/screens/ViewControlsScreen.java | 4 +- .../screens/ViewTabsScrollableScreen.java | 47 +++++++++++++++++++ 4 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 src/test/java/samples/android/nativeapp/apidemos/screens/ViewTabsScrollableScreen.java diff --git a/src/test/java/samples/android/nativeapp/AndroidBasicInteractionsTest.java b/src/test/java/samples/android/nativeapp/AndroidBasicInteractionsTest.java index d6fd913..b19df78 100644 --- a/src/test/java/samples/android/nativeapp/AndroidBasicInteractionsTest.java +++ b/src/test/java/samples/android/nativeapp/AndroidBasicInteractionsTest.java @@ -12,10 +12,7 @@ import samples.android.ITestCheckBox; import samples.android.ITestRadioButton; import samples.android.nativeapp.apidemos.ApplicationActivity; -import samples.android.nativeapp.apidemos.screens.AlertsMenuScreen; -import samples.android.nativeapp.apidemos.screens.InvokeSearchScreen; -import samples.android.nativeapp.apidemos.screens.TwoButtonsAlert; -import samples.android.nativeapp.apidemos.screens.ViewControlsScreen; +import samples.android.nativeapp.apidemos.screens.*; import testreport.ScreenshotListener; @Listeners(ScreenshotListener.class) @@ -91,7 +88,7 @@ public void testOpensAlert() { } @Test - public void testSwipeToElement() { + public void testVerticalSwipeToElement() { ViewControlsScreen viewControlsScreen = new ViewControlsScreen(); openRadioButtonsScreen(); viewControlsScreen.scrollToAllInsideScrollViewLabel(); @@ -103,6 +100,25 @@ public void testSwipeToElement() { Assert.assertFalse(viewControlsScreen.isDisabledButtonClickable()); } + @Test + public void testHorizontalSwipeToElement() { + ViewTabsScrollableScreen viewTabsScrollableScreen = ApplicationActivity.VIEW_TABS_SCROLLABLE.open(); + Assert.assertTrue(viewTabsScrollableScreen.isDisplayed(), + String.format("%s screen should be opened", viewTabsScrollableScreen.getName())); + viewTabsScrollableScreen.swipeTab(5, 1); + viewTabsScrollableScreen.selectTab(9); + Assert.assertEquals( + viewTabsScrollableScreen.getTabContentText(9), + "Content for tab with tag Tab 9", + "Label text does not match expected"); + viewTabsScrollableScreen.swipeTab(6, 9); + viewTabsScrollableScreen.selectTab(4); + Assert.assertEquals( + viewTabsScrollableScreen.getTabContentText(4), + "Content for tab with tag Tab 4", + "Label text does not match expected"); + } + private void logStep(String step) { AqualityServices.getLogger().info(step); } diff --git a/src/test/java/samples/android/nativeapp/apidemos/ApplicationActivity.java b/src/test/java/samples/android/nativeapp/apidemos/ApplicationActivity.java index 6371f83..3ee2b3b 100644 --- a/src/test/java/samples/android/nativeapp/apidemos/ApplicationActivity.java +++ b/src/test/java/samples/android/nativeapp/apidemos/ApplicationActivity.java @@ -7,6 +7,7 @@ import samples.android.nativeapp.apidemos.screens.AlertsMenuScreen; import samples.android.nativeapp.apidemos.screens.InvokeSearchScreen; import samples.android.nativeapp.apidemos.screens.ViewControlsScreen; +import samples.android.nativeapp.apidemos.screens.ViewTabsScrollableScreen; import java.lang.reflect.InvocationTargetException; @@ -14,7 +15,8 @@ public enum ApplicationActivity { SEARCH(".app.SearchInvoke", InvokeSearchScreen.class), ALERT_DIALOGS(".app.AlertDialogSamples", AlertsMenuScreen.class), - VIEW_CONTROLS(".view.Controls1", ViewControlsScreen.class); + VIEW_CONTROLS(".view.Controls1", ViewControlsScreen.class), + VIEW_TABS_SCROLLABLE(".view.Tabs5", ViewTabsScrollableScreen.class); private final String PACKAGE = "io.appium.android.apis"; private final String activity; diff --git a/src/test/java/samples/android/nativeapp/apidemos/screens/ViewControlsScreen.java b/src/test/java/samples/android/nativeapp/apidemos/screens/ViewControlsScreen.java index 29960cb..316a165 100644 --- a/src/test/java/samples/android/nativeapp/apidemos/screens/ViewControlsScreen.java +++ b/src/test/java/samples/android/nativeapp/apidemos/screens/ViewControlsScreen.java @@ -31,7 +31,7 @@ public ViewControlsScreen() { } public void scrollToAllInsideScrollViewLabel() { - new ElementTouchActions().scrollToElement(lblAllInsideScrollView, SwipeDirection.DOWN); + lblAllInsideScrollView.getTouchActions().scrollToElement(SwipeDirection.DOWN); } public String getAllInsideScrollViewLabelText() { @@ -39,7 +39,7 @@ public String getAllInsideScrollViewLabelText() { } public void scrollToDisabledButton() { - new ElementTouchActions().scrollToElement(btnDisabled, SwipeDirection.UP); + btnDisabled.getTouchActions().scrollToElement(SwipeDirection.UP); } public boolean isDisabledButtonClickable() { diff --git a/src/test/java/samples/android/nativeapp/apidemos/screens/ViewTabsScrollableScreen.java b/src/test/java/samples/android/nativeapp/apidemos/screens/ViewTabsScrollableScreen.java new file mode 100644 index 0000000..ea199e7 --- /dev/null +++ b/src/test/java/samples/android/nativeapp/apidemos/screens/ViewTabsScrollableScreen.java @@ -0,0 +1,47 @@ +package samples.android.nativeapp.apidemos.screens; + +import aquality.appium.mobile.elements.interfaces.IButton; +import aquality.appium.mobile.elements.interfaces.ILabel; +import aquality.appium.mobile.screens.AndroidScreen; +import io.appium.java_client.MobileBy; +import org.openqa.selenium.By; +import org.openqa.selenium.Point; + +public class ViewTabsScrollableScreen extends AndroidScreen { + + private static final String TAB_TEXT = "Content for tab with tag Tab %s"; + + public IButton getTab(int tabNumber) { + return getElementFactory().getButton( + MobileBy.xpath(String.format("//*[@text='TAB %s' and @resource-id = 'android:id/title']", tabNumber)), + String.valueOf(tabNumber)); + } + + public ILabel getTabContent(int tabNumber) { + return getElementFactory().getLabel( + MobileBy.xpath(String.format("//*[@text='%s']", generateTabText(tabNumber))), + String.valueOf(tabNumber)); + } + + public ViewTabsScrollableScreen() { + super(By.id("android:id/content"), "View/Tabs/Scrollable"); + } + + public void swipeTab(int startTabNumber, int endTabNumber) { + Point endTabPoint = getTab(endTabNumber).getElement().getCenter(); + getTab(startTabNumber).getTouchActions().swipe(endTabPoint); + } + + public String getTabContentText(int tabNumber) { + return getTabContent(tabNumber).getText(); + + } + + public void selectTab(int tabNumber) { + getTab(tabNumber).click(); + } + + private String generateTabText(int tabNumber) { + return String.format(TAB_TEXT, tabNumber); + } +} From 4bb88c6180faa853396ca84491eb8916088f1acf Mon Sep 17 00:00:00 2001 From: nviarbitski Date: Wed, 8 Apr 2020 02:25:10 +0300 Subject: [PATCH 13/21] Fixing adding new tabs into testHorizontalSwipeToElement --- .../nativeapp/AndroidBasicInteractionsTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/samples/android/nativeapp/AndroidBasicInteractionsTest.java b/src/test/java/samples/android/nativeapp/AndroidBasicInteractionsTest.java index b19df78..faee868 100644 --- a/src/test/java/samples/android/nativeapp/AndroidBasicInteractionsTest.java +++ b/src/test/java/samples/android/nativeapp/AndroidBasicInteractionsTest.java @@ -105,13 +105,13 @@ public void testHorizontalSwipeToElement() { ViewTabsScrollableScreen viewTabsScrollableScreen = ApplicationActivity.VIEW_TABS_SCROLLABLE.open(); Assert.assertTrue(viewTabsScrollableScreen.isDisplayed(), String.format("%s screen should be opened", viewTabsScrollableScreen.getName())); - viewTabsScrollableScreen.swipeTab(5, 1); - viewTabsScrollableScreen.selectTab(9); + viewTabsScrollableScreen.swipeTab(4, 1); + viewTabsScrollableScreen.selectTab(7); Assert.assertEquals( - viewTabsScrollableScreen.getTabContentText(9), - "Content for tab with tag Tab 9", + viewTabsScrollableScreen.getTabContentText(7), + "Content for tab with tag Tab 7", "Label text does not match expected"); - viewTabsScrollableScreen.swipeTab(6, 9); + viewTabsScrollableScreen.swipeTab(5, 7); viewTabsScrollableScreen.selectTab(4); Assert.assertEquals( viewTabsScrollableScreen.getTabContentText(4), From 5ba81fffc42d6743b5ee8c3b292aa49b0ade34d8 Mon Sep 17 00:00:00 2001 From: nviarbitski Date: Wed, 8 Apr 2020 18:45:55 +0300 Subject: [PATCH 14/21] Changins Mobile Modules - Moving getTouchActionsImplementation from IConfigurationModule into IActionsModule - Making performTouchAction protected in TouchActions - Removing waitAction from swipeWithLongPress - Adding new IActionsModule to implement into MobileModule - Adding replacting Double.parseDouble with getSwipeCoefficient in SwipeConfiguration - Removing extra space in ViewTabsScrollableScreen --- .../appium/mobile/actions/IActionsModule.java | 14 +++++++++++++ .../appium/mobile/actions/TouchActions.java | 5 ++--- .../mobile/application/MobileModule.java | 3 ++- .../configuration/IConfigurationsModule.java | 10 ---------- .../configuration/SwipeConfiguration.java | 20 +++++++++++-------- .../screens/ViewTabsScrollableScreen.java | 1 - 6 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 src/main/java/aquality/appium/mobile/actions/IActionsModule.java diff --git a/src/main/java/aquality/appium/mobile/actions/IActionsModule.java b/src/main/java/aquality/appium/mobile/actions/IActionsModule.java new file mode 100644 index 0000000..b4bf47c --- /dev/null +++ b/src/main/java/aquality/appium/mobile/actions/IActionsModule.java @@ -0,0 +1,14 @@ +package aquality.appium.mobile.actions; + +/** + * Describes implementations of actions services to be registered in DI container. + */ +public interface IActionsModule extends aquality.selenium.core.configurations.IConfigurationsModule { + + /** + * @return class which implements {@link ITouchActions} + */ + default Class getTouchActionsImplementation() { + return TouchActions.class; + } +} diff --git a/src/main/java/aquality/appium/mobile/actions/TouchActions.java b/src/main/java/aquality/appium/mobile/actions/TouchActions.java index c93f831..1bce3e7 100644 --- a/src/main/java/aquality/appium/mobile/actions/TouchActions.java +++ b/src/main/java/aquality/appium/mobile/actions/TouchActions.java @@ -31,11 +31,10 @@ public void swipeWithLongPress(Point startPoint, Point endPoint) { startPoint.getY(), endPoint.getX(), endPoint.getY()); - performTouchAction(touchAction -> touchAction.longPress(PointOption.point(startPoint)) - .waitAction(waitOptions(AqualityServices.get(ISwipeConfiguration.class).getTimeout())), endPoint); + performTouchAction(touchAction -> touchAction.longPress(PointOption.point(startPoint)), endPoint); } - private void performTouchAction(UnaryOperator> function, Point endPoint) { + protected void performTouchAction(UnaryOperator> function, Point endPoint) { TouchAction touchAction = new TouchAction<>(AqualityServices.getApplication().getDriver()); AqualityServices.get(IElementActionRetrier.class).doWithRetry(() -> function.apply(touchAction).moveTo(PointOption.point(endPoint)).release().perform()); diff --git a/src/main/java/aquality/appium/mobile/application/MobileModule.java b/src/main/java/aquality/appium/mobile/application/MobileModule.java index b3d2276..59dc778 100644 --- a/src/main/java/aquality/appium/mobile/application/MobileModule.java +++ b/src/main/java/aquality/appium/mobile/application/MobileModule.java @@ -1,5 +1,6 @@ package aquality.appium.mobile.application; +import aquality.appium.mobile.actions.IActionsModule; import aquality.appium.mobile.actions.ITouchActions; import aquality.appium.mobile.configuration.IApplicationProfile; import aquality.appium.mobile.configuration.IConfiguration; @@ -12,7 +13,7 @@ import com.google.inject.Provider; import com.google.inject.Singleton; -public class MobileModule extends AqualityModule implements IConfigurationsModule, IElementsModule { +public class MobileModule extends AqualityModule implements IConfigurationsModule, IElementsModule, IActionsModule { public MobileModule(Provider applicationProvider) { super(applicationProvider); } diff --git a/src/main/java/aquality/appium/mobile/configuration/IConfigurationsModule.java b/src/main/java/aquality/appium/mobile/configuration/IConfigurationsModule.java index 57fb11d..536a860 100644 --- a/src/main/java/aquality/appium/mobile/configuration/IConfigurationsModule.java +++ b/src/main/java/aquality/appium/mobile/configuration/IConfigurationsModule.java @@ -1,8 +1,5 @@ package aquality.appium.mobile.configuration; -import aquality.appium.mobile.actions.ITouchActions; -import aquality.appium.mobile.actions.TouchActions; - /** * Describes implementations of configurations to be registered in DI container. */ @@ -35,11 +32,4 @@ default Class getConfigurationImplementation() { default Class getSwipeConfigurationImplementation() { return SwipeConfiguration.class; } - - /** - * @return class which implements {@link ITouchActions} - */ - default Class getTouchActionsImplementation() { - return TouchActions.class; - } } diff --git a/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java b/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java index 4c1fe51..4179928 100644 --- a/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java +++ b/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java @@ -21,21 +21,21 @@ public class SwipeConfiguration implements ISwipeConfiguration { public SwipeConfiguration(ISettingsFile settingsFile) { this.retries = (int) settingsFile.getValue("/swipe/retries"); this.timeout = Duration.ofSeconds(Long.parseLong(settingsFile.getValue("/swipe/timeout").toString())); - this.horizontalSwipeTopPointXCoefficient = Double.parseDouble( + this.horizontalSwipeTopPointXCoefficient = getSwipeCoefficient( settingsFile.getValue("/swipe/horizontalSwipeTopPointXCoefficient").toString()); - this.horizontalSwipeBottomPointXCoefficient = Double.parseDouble( + this.horizontalSwipeBottomPointXCoefficient = getSwipeCoefficient( settingsFile.getValue("/swipe/horizontalSwipeBottomPointXCoefficient").toString()); - this.horizontalSwipeTopPointYCoefficient = Double.parseDouble( + this.horizontalSwipeTopPointYCoefficient = getSwipeCoefficient( settingsFile.getValue("/swipe/horizontalSwipeTopPointYCoefficient").toString()); - this.horizontalSwipeBottomPointYCoefficient = Double.parseDouble( + this.horizontalSwipeBottomPointYCoefficient = getSwipeCoefficient( settingsFile.getValue("/swipe/horizontalSwipeBottomPointYCoefficient").toString()); - this.verticalSwipeLeftPointXCoefficient = Double.parseDouble( + this.verticalSwipeLeftPointXCoefficient = getSwipeCoefficient( settingsFile.getValue("/swipe/verticalSwipeLeftPointXCoefficient").toString()); - this.verticalSwipeRightPointXCoefficient = Double.parseDouble( + this.verticalSwipeRightPointXCoefficient = getSwipeCoefficient( settingsFile.getValue("/swipe/verticalSwipeRightPointXCoefficient").toString()); - this.verticalSwipeLeftPointYCoefficient = Double.parseDouble( + this.verticalSwipeLeftPointYCoefficient = getSwipeCoefficient( settingsFile.getValue("/swipe/verticalSwipeLeftPointYCoefficient").toString()); - this.verticalSwipeRightPointYCoefficient = Double.parseDouble( + this.verticalSwipeRightPointYCoefficient = getSwipeCoefficient( settingsFile.getValue("/swipe/verticalSwipeRightPointYCoefficient").toString()); } @@ -88,4 +88,8 @@ public double getVerticalSwipeLeftPointYCoefficient() { public double getVerticalSwipeRightPointYCoefficient() { return this.verticalSwipeRightPointYCoefficient; } + + private double getSwipeCoefficient(String name) { + return Double.parseDouble(name); + } } diff --git a/src/test/java/samples/android/nativeapp/apidemos/screens/ViewTabsScrollableScreen.java b/src/test/java/samples/android/nativeapp/apidemos/screens/ViewTabsScrollableScreen.java index ea199e7..3454475 100644 --- a/src/test/java/samples/android/nativeapp/apidemos/screens/ViewTabsScrollableScreen.java +++ b/src/test/java/samples/android/nativeapp/apidemos/screens/ViewTabsScrollableScreen.java @@ -34,7 +34,6 @@ public void swipeTab(int startTabNumber, int endTabNumber) { public String getTabContentText(int tabNumber) { return getTabContent(tabNumber).getText(); - } public void selectTab(int tabNumber) { From 4f97ad3c8e4a69be2264ee1101c08ae51a59e80f Mon Sep 17 00:00:00 2001 From: n-verbitsky Date: Wed, 8 Apr 2020 20:16:39 +0300 Subject: [PATCH 15/21] updating getSwipeCoefficient in SwipeConfiguration --- .../configuration/SwipeConfiguration.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java b/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java index 4179928..9112504 100644 --- a/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java +++ b/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java @@ -22,21 +22,21 @@ public SwipeConfiguration(ISettingsFile settingsFile) { this.retries = (int) settingsFile.getValue("/swipe/retries"); this.timeout = Duration.ofSeconds(Long.parseLong(settingsFile.getValue("/swipe/timeout").toString())); this.horizontalSwipeTopPointXCoefficient = getSwipeCoefficient( - settingsFile.getValue("/swipe/horizontalSwipeTopPointXCoefficient").toString()); + settingsFile, "horizontalSwipeTopPointXCoefficient"); this.horizontalSwipeBottomPointXCoefficient = getSwipeCoefficient( - settingsFile.getValue("/swipe/horizontalSwipeBottomPointXCoefficient").toString()); + settingsFile, "horizontalSwipeBottomPointXCoefficient"); this.horizontalSwipeTopPointYCoefficient = getSwipeCoefficient( - settingsFile.getValue("/swipe/horizontalSwipeTopPointYCoefficient").toString()); + settingsFile, "horizontalSwipeTopPointYCoefficient"); this.horizontalSwipeBottomPointYCoefficient = getSwipeCoefficient( - settingsFile.getValue("/swipe/horizontalSwipeBottomPointYCoefficient").toString()); + settingsFile, "horizontalSwipeBottomPointYCoefficient"); this.verticalSwipeLeftPointXCoefficient = getSwipeCoefficient( - settingsFile.getValue("/swipe/verticalSwipeLeftPointXCoefficient").toString()); + settingsFile, "verticalSwipeLeftPointXCoefficient"); this.verticalSwipeRightPointXCoefficient = getSwipeCoefficient( - settingsFile.getValue("/swipe/verticalSwipeRightPointXCoefficient").toString()); + settingsFile, "verticalSwipeRightPointXCoefficient"); this.verticalSwipeLeftPointYCoefficient = getSwipeCoefficient( - settingsFile.getValue("/swipe/verticalSwipeLeftPointYCoefficient").toString()); + settingsFile, "verticalSwipeLeftPointYCoefficient"); this.verticalSwipeRightPointYCoefficient = getSwipeCoefficient( - settingsFile.getValue("/swipe/verticalSwipeRightPointYCoefficient").toString()); + settingsFile, "verticalSwipeRightPointYCoefficient"); } @Override @@ -89,7 +89,7 @@ public double getVerticalSwipeRightPointYCoefficient() { return this.verticalSwipeRightPointYCoefficient; } - private double getSwipeCoefficient(String name) { - return Double.parseDouble(name); + private double getSwipeCoefficient(ISettingsFile settingsFile, String swipeCoefficientKey) { + return Double.parseDouble(settingsFile.getValue(String.format("/swipe/%s", swipeCoefficientKey)).toString()); } } From e32c78a9a6491b4a0f79468e7245523a84f35c74 Mon Sep 17 00:00:00 2001 From: n-verbitsky Date: Mon, 11 May 2020 23:18:17 +0300 Subject: [PATCH 16/21] Updating ISwipeConfiguration into ITouchActionsConfiguration - ISwipeConfiguration: -- Renaming ISwipeConfiguration into ITouchActionsConfiguration -- Renaming getRetries into getSwipeRetries -- Renaming getTimeout into getSwipeTimeout - SwipeConfiguration: -- Renaming SwipeConfiguration into TouchActionsConfiguration -- Renaming getRetries into getSwipeRetries -- Renaming getTimeout into getSwipeTimeout - IConfiguration: -- Renaming getSwipeConfiguration() into getTouchActionsConfiguration() and updating description - IConfigurationsModule -- Renaming getSwipeConfigurationImplementation() into getTouchActionsConfigurationImplementation() and updating description - MobileModule: -- adding ITouchActionsConfiguration binding instead of ISwipeConfiguration --- .../mobile/application/MobileModule.java | 6 ++--- .../mobile/configuration/Configuration.java | 11 +++++----- .../mobile/configuration/IConfiguration.java | 6 ++--- .../configuration/IConfigurationsModule.java | 6 ++--- ...n.java => ITouchActionsConfiguration.java} | 8 +++---- ...on.java => TouchActionsConfiguration.java} | 22 +++++++++---------- 6 files changed, 30 insertions(+), 29 deletions(-) rename src/main/java/aquality/appium/mobile/configuration/{ISwipeConfiguration.java => ITouchActionsConfiguration.java} (94%) rename src/main/java/aquality/appium/mobile/configuration/{SwipeConfiguration.java => TouchActionsConfiguration.java} (82%) diff --git a/src/main/java/aquality/appium/mobile/application/MobileModule.java b/src/main/java/aquality/appium/mobile/application/MobileModule.java index 927a1c6..d773dae 100644 --- a/src/main/java/aquality/appium/mobile/application/MobileModule.java +++ b/src/main/java/aquality/appium/mobile/application/MobileModule.java @@ -6,7 +6,7 @@ import aquality.appium.mobile.configuration.IConfiguration; import aquality.appium.mobile.configuration.IConfigurationsModule; import aquality.appium.mobile.configuration.ILocalServiceSettings; -import aquality.appium.mobile.configuration.ISwipeConfiguration; +import aquality.appium.mobile.configuration.ITouchActionsConfiguration; import aquality.appium.mobile.elements.IElementsModule; import aquality.appium.mobile.elements.interfaces.IElementFactory; import aquality.appium.mobile.screens.screenfactory.IScreenFactoryProvider; @@ -15,7 +15,7 @@ import com.google.inject.Provider; import com.google.inject.Singleton; -public class MobileModule extends AqualityModule implements IConfigurationsModule, IElementsModule, IScreensModule { +public class MobileModule extends AqualityModule implements IConfigurationsModule, IElementsModule, IScreensModule, IActionsModule { public MobileModule(Provider applicationProvider) { super(applicationProvider); @@ -29,7 +29,7 @@ protected void configure() { bind(IConfiguration.class).to(getConfigurationImplementation()); bind(IElementFactory.class).to(getElementFactoryImplementation()); bind(IScreenFactoryProvider.class).to(getScreenFactoryProviderImplementation()); - bind(ISwipeConfiguration.class).to(getSwipeConfigurationImplementation()).in(Singleton.class); + bind(ITouchActionsConfiguration.class).to(getTouchActionsConfigurationImplementation()).in(Singleton.class); bind(ITouchActions.class).to(getTouchActionsImplementation()).in(Singleton.class); } } diff --git a/src/main/java/aquality/appium/mobile/configuration/Configuration.java b/src/main/java/aquality/appium/mobile/configuration/Configuration.java index da2600a..4a78722 100644 --- a/src/main/java/aquality/appium/mobile/configuration/Configuration.java +++ b/src/main/java/aquality/appium/mobile/configuration/Configuration.java @@ -13,18 +13,19 @@ public class Configuration implements IConfiguration { private final IApplicationProfile applicationProfile; private final ILoggerConfiguration loggerConfiguration; private final IElementCacheConfiguration elementCacheConfiguration; - private final ISwipeConfiguration swipeConfiguration; + private final ITouchActionsConfiguration touchActionsConfiguration; @Inject public Configuration(ITimeoutConfiguration timeoutConfiguration, IRetryConfiguration retryConfiguration, IApplicationProfile applicationProfile, ILoggerConfiguration loggerConfiguration, - IElementCacheConfiguration elementCacheConfiguration, ISwipeConfiguration swipeConfiguration) { + IElementCacheConfiguration elementCacheConfiguration, + ITouchActionsConfiguration touchActionsConfiguration) { this.timeoutConfiguration = timeoutConfiguration; this.retryConfiguration = retryConfiguration; this.applicationProfile = applicationProfile; this.loggerConfiguration = loggerConfiguration; this.elementCacheConfiguration = elementCacheConfiguration; - this.swipeConfiguration = swipeConfiguration; + this.touchActionsConfiguration = touchActionsConfiguration; } @Override @@ -53,7 +54,7 @@ public IElementCacheConfiguration getElementCacheConfiguration() { } @Override - public ISwipeConfiguration getSwipeConfiguration() { - return swipeConfiguration; + public ITouchActionsConfiguration getTouchActionsConfiguration() { + return touchActionsConfiguration; } } \ No newline at end of file diff --git a/src/main/java/aquality/appium/mobile/configuration/IConfiguration.java b/src/main/java/aquality/appium/mobile/configuration/IConfiguration.java index 4376944..10369e1 100644 --- a/src/main/java/aquality/appium/mobile/configuration/IConfiguration.java +++ b/src/main/java/aquality/appium/mobile/configuration/IConfiguration.java @@ -43,9 +43,9 @@ public interface IConfiguration { IElementCacheConfiguration getElementCacheConfiguration(); /** - * Gets configuration of swipes. + * Gets configuration of touch actions. * - * @return Configuration of swipes. + * @return Configuration of touch actions. */ - ISwipeConfiguration getSwipeConfiguration(); + ITouchActionsConfiguration getTouchActionsConfiguration(); } \ No newline at end of file diff --git a/src/main/java/aquality/appium/mobile/configuration/IConfigurationsModule.java b/src/main/java/aquality/appium/mobile/configuration/IConfigurationsModule.java index 536a860..2b1a6eb 100644 --- a/src/main/java/aquality/appium/mobile/configuration/IConfigurationsModule.java +++ b/src/main/java/aquality/appium/mobile/configuration/IConfigurationsModule.java @@ -27,9 +27,9 @@ default Class getConfigurationImplementation() { } /** - * @return class which implements {@link ISwipeConfiguration} + * @return class which implements {@link ITouchActionsConfiguration} */ - default Class getSwipeConfigurationImplementation() { - return SwipeConfiguration.class; + default Class getTouchActionsConfigurationImplementation() { + return TouchActionsConfiguration.class; } } diff --git a/src/main/java/aquality/appium/mobile/configuration/ISwipeConfiguration.java b/src/main/java/aquality/appium/mobile/configuration/ITouchActionsConfiguration.java similarity index 94% rename from src/main/java/aquality/appium/mobile/configuration/ISwipeConfiguration.java rename to src/main/java/aquality/appium/mobile/configuration/ITouchActionsConfiguration.java index 750a014..058329c 100644 --- a/src/main/java/aquality/appium/mobile/configuration/ISwipeConfiguration.java +++ b/src/main/java/aquality/appium/mobile/configuration/ITouchActionsConfiguration.java @@ -3,22 +3,22 @@ import java.time.Duration; /** - * Describes Swipe settings. + * Describes Touch Actions settings. */ -public interface ISwipeConfiguration { +public interface ITouchActionsConfiguration { /** * Gets number of retries to perform swipe. * * @return arguments map. */ - int getRetries(); + int getSwipeRetries(); /** * Gets the timeout to perform a swipe. * * @return timeout to perform swipe. */ - Duration getTimeout(); + Duration getSwipeTimeout(); /** * Gets the coefficient to calculate the 'x' coordinate of top point for swipe action. diff --git a/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java b/src/main/java/aquality/appium/mobile/configuration/TouchActionsConfiguration.java similarity index 82% rename from src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java rename to src/main/java/aquality/appium/mobile/configuration/TouchActionsConfiguration.java index 9112504..bc08b2c 100644 --- a/src/main/java/aquality/appium/mobile/configuration/SwipeConfiguration.java +++ b/src/main/java/aquality/appium/mobile/configuration/TouchActionsConfiguration.java @@ -5,9 +5,9 @@ import java.time.Duration; -public class SwipeConfiguration implements ISwipeConfiguration { - private final int retries; - private final Duration timeout; +public class TouchActionsConfiguration implements ITouchActionsConfiguration { + private final int swipeRetries; + private final Duration swipeTimeout; private final double horizontalSwipeTopPointXCoefficient; private final double horizontalSwipeBottomPointXCoefficient; private final double horizontalSwipeTopPointYCoefficient; @@ -18,9 +18,9 @@ public class SwipeConfiguration implements ISwipeConfiguration { private final double verticalSwipeRightPointYCoefficient; @Inject - public SwipeConfiguration(ISettingsFile settingsFile) { - this.retries = (int) settingsFile.getValue("/swipe/retries"); - this.timeout = Duration.ofSeconds(Long.parseLong(settingsFile.getValue("/swipe/timeout").toString())); + public TouchActionsConfiguration(ISettingsFile settingsFile) { + this.swipeRetries = (int) settingsFile.getValue("/touchActions/swipe/retries"); + this.swipeTimeout = Duration.ofSeconds(Long.parseLong(settingsFile.getValue("/touchActions/swipe/timeout").toString())); this.horizontalSwipeTopPointXCoefficient = getSwipeCoefficient( settingsFile, "horizontalSwipeTopPointXCoefficient"); this.horizontalSwipeBottomPointXCoefficient = getSwipeCoefficient( @@ -40,13 +40,13 @@ public SwipeConfiguration(ISettingsFile settingsFile) { } @Override - public int getRetries() { - return this.retries; + public int getSwipeRetries() { + return this.swipeRetries; } @Override - public Duration getTimeout() { - return this.timeout; + public Duration getSwipeTimeout() { + return this.swipeTimeout; } @Override @@ -90,6 +90,6 @@ public double getVerticalSwipeRightPointYCoefficient() { } private double getSwipeCoefficient(ISettingsFile settingsFile, String swipeCoefficientKey) { - return Double.parseDouble(settingsFile.getValue(String.format("/swipe/%s", swipeCoefficientKey)).toString()); + return Double.parseDouble(settingsFile.getValue(String.format("/touchActions/swipe/%s", swipeCoefficientKey)).toString()); } } From 7930c56933fbe9542d870b0554bf7a122c4df549 Mon Sep 17 00:00:00 2001 From: n-verbitsky Date: Mon, 11 May 2020 23:19:09 +0300 Subject: [PATCH 17/21] Updating settings - src/main/resources/settings.json: -- Adding touchActions object -- Moving swipe object under touchActions object - src/test/resources/settings.androidwebsession.json: -- Adding touchActions object -- Moving swipe object under touchActions object - src/test/resources/settings.json -- Adding touchActions object -- Moving swipe object under touchActions object --- src/main/resources/settings.json | 24 ++++++++++--------- .../resources/settings.androidwebsession.json | 24 ++++++++++--------- src/test/resources/settings.json | 24 ++++++++++--------- 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/src/main/resources/settings.json b/src/main/resources/settings.json index 402efe0..946592e 100644 --- a/src/main/resources/settings.json +++ b/src/main/resources/settings.json @@ -45,16 +45,18 @@ "elementCache": { "isEnabled": true }, - "swipe": { - "timeout": 1, - "retries": 5, - "horizontalSwipeBottomCoefficient": 0.8, - "horizontalSwipeTopCoefficient": 0.2, - "horizontalSwipeLeftCoefficient": 0.5, - "horizontalSwipeRightCoefficient": 0.5, - "verticalSwipeTopCoefficient": 0.5, - "verticalSwipeBottomCoefficient": 0.5, - "verticalSwipeLeftCoefficient": 0.2, - "verticalSwipeRightCoefficient": 0.8 + "touchActions": { + "swipe": { + "timeout": 1, + "retries": 5, + "horizontalSwipeTopPointXCoefficient": 0.5, + "horizontalSwipeBottomPointXCoefficient": 0.5, + "horizontalSwipeTopPointYCoefficient": 0.2, + "horizontalSwipeBottomPointYCoefficient": 0.8, + "verticalSwipeLeftPointXCoefficient": 0.2, + "verticalSwipeRightPointXCoefficient": 0.8, + "verticalSwipeLeftPointYCoefficient": 0.5, + "verticalSwipeRightPointYCoefficient": 0.5 + } } } \ No newline at end of file diff --git a/src/test/resources/settings.androidwebsession.json b/src/test/resources/settings.androidwebsession.json index 8dd736e..b6c018c 100644 --- a/src/test/resources/settings.androidwebsession.json +++ b/src/test/resources/settings.androidwebsession.json @@ -37,16 +37,18 @@ "elementCache": { "isEnabled": true }, - "swipe": { - "timeout": 1, - "retries": 5, - "horizontalSwipeTopPointXCoefficient": 0.5, - "horizontalSwipeBottomPointXCoefficient": 0.5, - "horizontalSwipeTopPointYCoefficient": 0.2, - "horizontalSwipeBottomPointYCoefficient": 0.8, - "verticalSwipeLeftPointXCoefficient": 0.2, - "verticalSwipeRightPointXCoefficient": 0.8, - "verticalSwipeLeftPointYCoefficient": 0.5, - "verticalSwipeRightPointYCoefficient": 0.5 + "touchActions": { + "swipe": { + "timeout": 1, + "retries": 5, + "horizontalSwipeTopPointXCoefficient": 0.5, + "horizontalSwipeBottomPointXCoefficient": 0.5, + "horizontalSwipeTopPointYCoefficient": 0.2, + "horizontalSwipeBottomPointYCoefficient": 0.8, + "verticalSwipeLeftPointXCoefficient": 0.2, + "verticalSwipeRightPointXCoefficient": 0.8, + "verticalSwipeLeftPointYCoefficient": 0.5, + "verticalSwipeRightPointYCoefficient": 0.5 + } } } \ No newline at end of file diff --git a/src/test/resources/settings.json b/src/test/resources/settings.json index 5f72135..289b48f 100644 --- a/src/test/resources/settings.json +++ b/src/test/resources/settings.json @@ -47,16 +47,18 @@ "elementCache": { "isEnabled": true }, - "swipe": { - "timeout": 1, - "retries": 5, - "horizontalSwipeTopPointXCoefficient": 0.5, - "horizontalSwipeBottomPointXCoefficient": 0.5, - "horizontalSwipeTopPointYCoefficient": 0.2, - "horizontalSwipeBottomPointYCoefficient": 0.8, - "verticalSwipeLeftPointXCoefficient": 0.2, - "verticalSwipeRightPointXCoefficient": 0.8, - "verticalSwipeLeftPointYCoefficient": 0.5, - "verticalSwipeRightPointYCoefficient": 0.5 + "touchActions": { + "swipe": { + "timeout": 1, + "retries": 5, + "horizontalSwipeTopPointXCoefficient": 0.5, + "horizontalSwipeBottomPointXCoefficient": 0.5, + "horizontalSwipeTopPointYCoefficient": 0.2, + "horizontalSwipeBottomPointYCoefficient": 0.8, + "verticalSwipeLeftPointXCoefficient": 0.2, + "verticalSwipeRightPointXCoefficient": 0.8, + "verticalSwipeLeftPointYCoefficient": 0.5, + "verticalSwipeRightPointYCoefficient": 0.5 + } } } \ No newline at end of file From b8edd47d7376a572b7371ebd20990ead295f41c5 Mon Sep 17 00:00:00 2001 From: n-verbitsky Date: Mon, 11 May 2020 23:25:21 +0300 Subject: [PATCH 18/21] Minor fixes: - TouchActions: -- Updating imports -- beautifying code - ITouchActions -- Adding detailed description for swipeWithLongPress() - ElementTouchActions -- Updating imports -- Updating references to ITouchActionsConfiguration - ViewControlsScreen -- updating imports - AndroidBasicInteractionsTest -- Adding new call to isDisplayed() --- .../appium/mobile/actions/ITouchActions.java | 2 +- .../appium/mobile/actions/TouchActions.java | 8 ++++-- .../elements/actions/ElementTouchActions.java | 28 +++++++++---------- .../AndroidBasicInteractionsTest.java | 2 +- .../apidemos/screens/ViewControlsScreen.java | 1 - 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/main/java/aquality/appium/mobile/actions/ITouchActions.java b/src/main/java/aquality/appium/mobile/actions/ITouchActions.java index 23f8532..ead6dbb 100644 --- a/src/main/java/aquality/appium/mobile/actions/ITouchActions.java +++ b/src/main/java/aquality/appium/mobile/actions/ITouchActions.java @@ -16,7 +16,7 @@ public interface ITouchActions { void swipe(Point startPoint, Point endPoint); /** - * Swipes from start point to end point using LongPress. + * Performs long press action and moves cursor from a start point to an end end point imitating the swipe action * * @param startPoint point on screen to swipe from. * @param endPoint point on screen to swipe to. diff --git a/src/main/java/aquality/appium/mobile/actions/TouchActions.java b/src/main/java/aquality/appium/mobile/actions/TouchActions.java index 1bce3e7..336e2b7 100644 --- a/src/main/java/aquality/appium/mobile/actions/TouchActions.java +++ b/src/main/java/aquality/appium/mobile/actions/TouchActions.java @@ -1,7 +1,7 @@ package aquality.appium.mobile.actions; import aquality.appium.mobile.application.AqualityServices; -import aquality.appium.mobile.configuration.ISwipeConfiguration; +import aquality.appium.mobile.configuration.ITouchActionsConfiguration; import aquality.selenium.core.utilities.IElementActionRetrier; import io.appium.java_client.TouchAction; import io.appium.java_client.touch.offset.PointOption; @@ -19,8 +19,10 @@ public void swipe(Point startPoint, Point endPoint) { startPoint.getY(), endPoint.getX(), endPoint.getY()); - performTouchAction(touchAction -> touchAction.press(PointOption.point(startPoint)) - .waitAction(waitOptions(AqualityServices.get(ISwipeConfiguration.class).getTimeout())), endPoint); + performTouchAction(touchAction -> touchAction + .press(PointOption.point(startPoint)) + .waitAction(waitOptions(AqualityServices.get(ITouchActionsConfiguration.class).getSwipeTimeout())), + endPoint); } @Override diff --git a/src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java b/src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java index ecd2335..e496a41 100644 --- a/src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java +++ b/src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java @@ -3,7 +3,7 @@ import aquality.appium.mobile.actions.ITouchActions; import aquality.appium.mobile.actions.SwipeDirection; import aquality.appium.mobile.application.AqualityServices; -import aquality.appium.mobile.configuration.ISwipeConfiguration; +import aquality.appium.mobile.configuration.ITouchActionsConfiguration; import aquality.appium.mobile.elements.interfaces.IElement; import org.openqa.selenium.Dimension; import org.openqa.selenium.Point; @@ -23,20 +23,20 @@ public ElementTouchActions(IElement element) { this.element = element; this.scrollDownStartPoint = recalculatePointCoordinates( getBottomRightCornerPoint(), - getISwipeConfiguration().getHorizontalSwipeBottomPointXCoefficient(), - getISwipeConfiguration().getHorizontalSwipeBottomPointYCoefficient()); + getITouchActionsConfiguration().getHorizontalSwipeBottomPointXCoefficient(), + getITouchActionsConfiguration().getHorizontalSwipeBottomPointYCoefficient()); this.scrollDownEndPoint = recalculatePointCoordinates( getBottomRightCornerPoint(), - getISwipeConfiguration().getHorizontalSwipeTopPointXCoefficient(), - getISwipeConfiguration().getHorizontalSwipeTopPointYCoefficient()); + getITouchActionsConfiguration().getHorizontalSwipeTopPointXCoefficient(), + getITouchActionsConfiguration().getHorizontalSwipeTopPointYCoefficient()); this.swipeLeftStartPoint = recalculatePointCoordinates( getBottomRightCornerPoint(), - getISwipeConfiguration().getVerticalSwipeRightPointXCoefficient(), - getISwipeConfiguration().getVerticalSwipeRightPointYCoefficient()); + getITouchActionsConfiguration().getVerticalSwipeRightPointXCoefficient(), + getITouchActionsConfiguration().getVerticalSwipeRightPointYCoefficient()); this.swipeLeftEndPoint = recalculatePointCoordinates( getBottomRightCornerPoint(), - getISwipeConfiguration().getVerticalSwipeLeftPointXCoefficient(), - getISwipeConfiguration().getVerticalSwipeLeftPointYCoefficient()); + getITouchActionsConfiguration().getVerticalSwipeLeftPointXCoefficient(), + getITouchActionsConfiguration().getVerticalSwipeLeftPointYCoefficient()); this.scrollUpStartPoint = this.scrollDownEndPoint; this.scrollUpEndPoint = this.scrollDownStartPoint; this.swipeRightStartPoint = this.swipeLeftEndPoint; @@ -55,7 +55,7 @@ public void swipeWithLongPress(Point endPoint) { @Override public void scrollToElement(SwipeDirection direction) { - int numberOfRetries = AqualityServices.get(ISwipeConfiguration.class).getRetries(); + int numberOfRetries = AqualityServices.get(ITouchActionsConfiguration.class).getSwipeRetries(); ITouchActions touchActions = AqualityServices.getTouchActions(); while (numberOfRetries > 0) { if (!element.state().isDisplayed()) { @@ -104,11 +104,11 @@ private Point recalculatePointCoordinates(Point point, double coefficientX, doub } /** - * Returns ISwipeConfiguration class. + * Returns ITouchActionsConfiguration class. * - * @return ISwipeConfiguration class + * @return ITouchActionsConfiguration class */ - private ISwipeConfiguration getISwipeConfiguration() { - return AqualityServices.get(ISwipeConfiguration.class); + private ITouchActionsConfiguration getITouchActionsConfiguration() { + return AqualityServices.get(ITouchActionsConfiguration.class); } } diff --git a/src/test/java/samples/android/nativeapp/AndroidBasicInteractionsTest.java b/src/test/java/samples/android/nativeapp/AndroidBasicInteractionsTest.java index 5c33a83..2fcf8dd 100644 --- a/src/test/java/samples/android/nativeapp/AndroidBasicInteractionsTest.java +++ b/src/test/java/samples/android/nativeapp/AndroidBasicInteractionsTest.java @@ -101,7 +101,7 @@ public void testVerticalSwipeToElement() { @Test public void testHorizontalSwipeToElement() { ViewTabsScrollableScreen viewTabsScrollableScreen = ApplicationActivity.VIEW_TABS_SCROLLABLE.open(); - Assert.assertTrue(viewTabsScrollableScreen.isDisplayed(), + Assert.assertTrue(viewTabsScrollableScreen.state().isDisplayed(), String.format("%s screen should be opened", viewTabsScrollableScreen.getName())); viewTabsScrollableScreen.swipeTab(4, 1); viewTabsScrollableScreen.selectTab(7); diff --git a/src/test/java/samples/android/nativeapp/apidemos/screens/ViewControlsScreen.java b/src/test/java/samples/android/nativeapp/apidemos/screens/ViewControlsScreen.java index 316a165..3b0ec93 100644 --- a/src/test/java/samples/android/nativeapp/apidemos/screens/ViewControlsScreen.java +++ b/src/test/java/samples/android/nativeapp/apidemos/screens/ViewControlsScreen.java @@ -1,7 +1,6 @@ package samples.android.nativeapp.apidemos.screens; import aquality.appium.mobile.actions.SwipeDirection; -import aquality.appium.mobile.elements.actions.ElementTouchActions; import aquality.appium.mobile.elements.interfaces.IButton; import aquality.appium.mobile.elements.interfaces.ICheckBox; import aquality.appium.mobile.elements.interfaces.ILabel; From 997b2a91cda98c7625f0f30b19ac2b070a1288a3 Mon Sep 17 00:00:00 2001 From: n-verbitsky Date: Sun, 24 May 2020 12:08:11 +0300 Subject: [PATCH 19/21] Updating the swipe coefficients calculation: - test.resources.settings.json, test.resources.settings.androidwebsession.json, src.resources.settings.json: -- replacing swipe coefficients with verticalOffset and horizontalOffset -- replacing swipe timeout with swipe duration - ITouchActionsConfiguration, TouchActionsConfiguration: -- replacing getSwipeTimeout() with getSwipeDuration() -- getSwipePointCoefficients() with getSwipeVerticalOffset() and getSwipeHorizontalOffset() -- added explicit documentation for getSwipeHorizontalOffset() and getSwipeVerticalOffset() - actions.TouchActions: -- replacing call to getSwipeTimeout() with getSwipeDuration() - elements.actions.ELementTouchActions: -- replacted getITouchActionsConfiguration() with getConfiguration() -- replaced getITouchActionsConfiguration().getSwipePointCoefficient() with getSwipeOffset() - elements.actions.IELementTouchActions: -- made interface parameters final - actions.SwipeDirection, action.ITouchActions: -- updated javadoc - actions.IActionsModule -- replaced import --- .../appium/mobile/actions/IActionsModule.java | 4 +- .../appium/mobile/actions/ITouchActions.java | 2 +- .../appium/mobile/actions/SwipeDirection.java | 3 + .../appium/mobile/actions/TouchActions.java | 4 +- .../ITouchActionsConfiguration.java | 81 +++++++------------ .../TouchActionsConfiguration.java | 78 +++--------------- .../elements/actions/ElementTouchActions.java | 32 ++++---- .../actions/IElementTouchActions.java | 6 +- src/main/resources/settings.json | 15 +--- .../resources/settings.androidwebsession.json | 21 ++--- src/test/resources/settings.json | 13 +-- 11 files changed, 83 insertions(+), 176 deletions(-) diff --git a/src/main/java/aquality/appium/mobile/actions/IActionsModule.java b/src/main/java/aquality/appium/mobile/actions/IActionsModule.java index b4bf47c..12ac05a 100644 --- a/src/main/java/aquality/appium/mobile/actions/IActionsModule.java +++ b/src/main/java/aquality/appium/mobile/actions/IActionsModule.java @@ -1,9 +1,11 @@ package aquality.appium.mobile.actions; +import aquality.appium.mobile.configuration.IConfigurationsModule; + /** * Describes implementations of actions services to be registered in DI container. */ -public interface IActionsModule extends aquality.selenium.core.configurations.IConfigurationsModule { +public interface IActionsModule extends IConfigurationsModule { /** * @return class which implements {@link ITouchActions} diff --git a/src/main/java/aquality/appium/mobile/actions/ITouchActions.java b/src/main/java/aquality/appium/mobile/actions/ITouchActions.java index ead6dbb..3fd7082 100644 --- a/src/main/java/aquality/appium/mobile/actions/ITouchActions.java +++ b/src/main/java/aquality/appium/mobile/actions/ITouchActions.java @@ -16,7 +16,7 @@ public interface ITouchActions { void swipe(Point startPoint, Point endPoint); /** - * Performs long press action and moves cursor from a start point to an end end point imitating the swipe action + * Performs long press action and moves cursor from a start point to an end end point imitating the swipe action. * * @param startPoint point on screen to swipe from. * @param endPoint point on screen to swipe to. diff --git a/src/main/java/aquality/appium/mobile/actions/SwipeDirection.java b/src/main/java/aquality/appium/mobile/actions/SwipeDirection.java index 81dbba1..888610b 100644 --- a/src/main/java/aquality/appium/mobile/actions/SwipeDirection.java +++ b/src/main/java/aquality/appium/mobile/actions/SwipeDirection.java @@ -1,5 +1,8 @@ package aquality.appium.mobile.actions; +/** + * The enum describing the possible swipe directions. + */ public enum SwipeDirection { UP, DOWN, diff --git a/src/main/java/aquality/appium/mobile/actions/TouchActions.java b/src/main/java/aquality/appium/mobile/actions/TouchActions.java index 336e2b7..848b30c 100644 --- a/src/main/java/aquality/appium/mobile/actions/TouchActions.java +++ b/src/main/java/aquality/appium/mobile/actions/TouchActions.java @@ -20,8 +20,8 @@ public void swipe(Point startPoint, Point endPoint) { endPoint.getX(), endPoint.getY()); performTouchAction(touchAction -> touchAction - .press(PointOption.point(startPoint)) - .waitAction(waitOptions(AqualityServices.get(ITouchActionsConfiguration.class).getSwipeTimeout())), + .press(PointOption.point(startPoint)) + .waitAction(waitOptions(AqualityServices.get(ITouchActionsConfiguration.class).getSwipeDuration())), endPoint); } diff --git a/src/main/java/aquality/appium/mobile/configuration/ITouchActionsConfiguration.java b/src/main/java/aquality/appium/mobile/configuration/ITouchActionsConfiguration.java index 058329c..e9c6a66 100644 --- a/src/main/java/aquality/appium/mobile/configuration/ITouchActionsConfiguration.java +++ b/src/main/java/aquality/appium/mobile/configuration/ITouchActionsConfiguration.java @@ -14,66 +14,43 @@ public interface ITouchActionsConfiguration { int getSwipeRetries(); /** - * Gets the timeout to perform a swipe. + * Gets the number of seconds required to perform a swipe action. * - * @return timeout to perform swipe. + * @return number of seconds required to perform a swipe action. */ - Duration getSwipeTimeout(); + Duration getSwipeDuration(); /** - * Gets the coefficient to calculate the 'x' coordinate of top point for swipe action. + * Gets the offset coefficient to adjust the start/end point for swipe action relatively to the parallel screen edge. + * Example for swipe down action: + * The offset coefficient is used to calculate start/end point's Y coordinate. + * If offset coefficient == 0.2, then the start point's Y coordinate == screen's length * (1 - 0.2). + * If offset coefficient == 0.2, then the end point's Y coordinate == screen's length * 0.2. + * The vice versa for swipe up action. + * Example for swipe left action: + * The offset coefficient is used to calculate start/end point's X coordinate. + * If offset coefficient == 0.2, then the start point's X coordinate == screen's width * (1 - 0.2). + * If offset coefficient == 0.2, then the end point's X coordinate == screen's width * 0.2. + * The vice versa for swipe right action. * - * @return coefficient to calculate the 'x' coordinate of top point for swipe action + * @return offset coefficient to adjust the start/end point for swipe action relatively to the parallel screen edge */ - double getHorizontalSwipeTopPointXCoefficient(); + double getSwipeVerticalOffset(); /** - * Gets the coefficient to calculate the 'x' coordinate of bottom point for swipe action. + * Gets the offset coefficient to adjust the start/end point for swipe action relatively to the perpendicular screen edge. + * Example for swipe down action: + * The offset coefficient is used to calculate start/end point's X coordinate. + * If offset coefficient == 0.5, then the start point's X coordinate == screen's width * (1 - 0.5). + * If offset coefficient == 0.5, then the end point's X coordinate == screen's width * 0.5. + * The vice versa for swipe up action. + * Example for swipe left action: + * The offset coefficient is used to calculate start/end point's X coordinate. + * If offset coefficient == 0.5, then the start point's Y coordinate == screen's length * (1 - 0.5). + * If offset coefficient == 0.5, then the end point's Y coordinate == screen's length * 0.5. + * The vice versa for swipe right action. * - * @return coefficient to calculate the 'x' coordinate of bottom point for swipe action + * @return offset coefficient to adjust the start/end point for swipe action relatively to the perpendicular screen edge */ - double getHorizontalSwipeBottomPointXCoefficient(); - - /** - * Gets the coefficient to calculate the 'y' coordinate of top point for swipe action. - * - * @return coefficient to calculate the 'y' coordinate of top point for swipe action - */ - double getHorizontalSwipeTopPointYCoefficient(); - - /** - * Gets the coefficient to calculate the 'y' coordinate of bottom point for swipe action. - * - * @return coefficient to calculate the 'y' coordinate of bottom point for swipe action - */ - double getHorizontalSwipeBottomPointYCoefficient(); - - /** - * Gets the coefficient to calculate the 'x' coordinate of top point for swipe action. - * - * @return timeout to perform swipe. - */ - double getVerticalSwipeLeftPointXCoefficient(); - - /** - * Gets the coefficient to calculate the 'x' coordinate of right-hand point for swipe action. - * - * @return coefficient to calculate the 'x' coordinate of right-hand point for swipe action - */ - double getVerticalSwipeRightPointXCoefficient(); - - /** - * Gets the coefficient to calculate the 'y' coordinate of left-hand point for swipe action. - * - * @return coefficient to calculate the 'y' coordinate of left-hand point for swipe action - */ - double getVerticalSwipeLeftPointYCoefficient(); - - - /** - * Gets the coefficient to calculate the 'y' coordinate of right-hand point for swipe action. - * - * @return coefficient to calculate the 'y' coordinate of right-hand point for swipe action - */ - double getVerticalSwipeRightPointYCoefficient(); + double getSwipeHorizontalOffset(); } diff --git a/src/main/java/aquality/appium/mobile/configuration/TouchActionsConfiguration.java b/src/main/java/aquality/appium/mobile/configuration/TouchActionsConfiguration.java index bc08b2c..57827db 100644 --- a/src/main/java/aquality/appium/mobile/configuration/TouchActionsConfiguration.java +++ b/src/main/java/aquality/appium/mobile/configuration/TouchActionsConfiguration.java @@ -6,37 +6,17 @@ import java.time.Duration; public class TouchActionsConfiguration implements ITouchActionsConfiguration { + private final Duration swipeDuration; private final int swipeRetries; - private final Duration swipeTimeout; - private final double horizontalSwipeTopPointXCoefficient; - private final double horizontalSwipeBottomPointXCoefficient; - private final double horizontalSwipeTopPointYCoefficient; - private final double horizontalSwipeBottomPointYCoefficient; - private final double verticalSwipeLeftPointXCoefficient; - private final double verticalSwipeRightPointXCoefficient; - private final double verticalSwipeLeftPointYCoefficient; - private final double verticalSwipeRightPointYCoefficient; + private final double swipeVerticalOffset; + private final double swipeHorizontalOffset; @Inject public TouchActionsConfiguration(ISettingsFile settingsFile) { + this.swipeDuration = Duration.ofSeconds(Long.parseLong(settingsFile.getValue("/touchActions/swipe/duration").toString())); this.swipeRetries = (int) settingsFile.getValue("/touchActions/swipe/retries"); - this.swipeTimeout = Duration.ofSeconds(Long.parseLong(settingsFile.getValue("/touchActions/swipe/timeout").toString())); - this.horizontalSwipeTopPointXCoefficient = getSwipeCoefficient( - settingsFile, "horizontalSwipeTopPointXCoefficient"); - this.horizontalSwipeBottomPointXCoefficient = getSwipeCoefficient( - settingsFile, "horizontalSwipeBottomPointXCoefficient"); - this.horizontalSwipeTopPointYCoefficient = getSwipeCoefficient( - settingsFile, "horizontalSwipeTopPointYCoefficient"); - this.horizontalSwipeBottomPointYCoefficient = getSwipeCoefficient( - settingsFile, "horizontalSwipeBottomPointYCoefficient"); - this.verticalSwipeLeftPointXCoefficient = getSwipeCoefficient( - settingsFile, "verticalSwipeLeftPointXCoefficient"); - this.verticalSwipeRightPointXCoefficient = getSwipeCoefficient( - settingsFile, "verticalSwipeRightPointXCoefficient"); - this.verticalSwipeLeftPointYCoefficient = getSwipeCoefficient( - settingsFile, "verticalSwipeLeftPointYCoefficient"); - this.verticalSwipeRightPointYCoefficient = getSwipeCoefficient( - settingsFile, "verticalSwipeRightPointYCoefficient"); + this.swipeVerticalOffset = (double) settingsFile.getValue("/touchActions/swipe/verticalOffset"); + this.swipeHorizontalOffset = (double) settingsFile.getValue("/touchActions/swipe/horizontalOffset"); } @Override @@ -45,51 +25,17 @@ public int getSwipeRetries() { } @Override - public Duration getSwipeTimeout() { - return this.swipeTimeout; + public Duration getSwipeDuration() { + return this.swipeDuration; } @Override - public double getHorizontalSwipeTopPointXCoefficient() { - return this.horizontalSwipeTopPointXCoefficient; + public double getSwipeVerticalOffset() { + return this.swipeVerticalOffset; } @Override - public double getHorizontalSwipeBottomPointXCoefficient() { - return this.horizontalSwipeBottomPointXCoefficient; - } - - @Override - public double getHorizontalSwipeTopPointYCoefficient() { - return this.horizontalSwipeTopPointYCoefficient; - } - - @Override - public double getHorizontalSwipeBottomPointYCoefficient() { - return this.horizontalSwipeBottomPointYCoefficient; - } - - @Override - public double getVerticalSwipeLeftPointXCoefficient() { - return this.verticalSwipeLeftPointXCoefficient; - } - - @Override - public double getVerticalSwipeRightPointXCoefficient() { - return this.verticalSwipeRightPointXCoefficient; - } - - @Override - public double getVerticalSwipeLeftPointYCoefficient() { - return this.verticalSwipeLeftPointYCoefficient; - } - - @Override - public double getVerticalSwipeRightPointYCoefficient() { - return this.verticalSwipeRightPointYCoefficient; - } - - private double getSwipeCoefficient(ISettingsFile settingsFile, String swipeCoefficientKey) { - return Double.parseDouble(settingsFile.getValue(String.format("/touchActions/swipe/%s", swipeCoefficientKey)).toString()); + public double getSwipeHorizontalOffset() { + return this.swipeHorizontalOffset; } } diff --git a/src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java b/src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java index e496a41..9f9b6fe 100644 --- a/src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java +++ b/src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java @@ -23,20 +23,20 @@ public ElementTouchActions(IElement element) { this.element = element; this.scrollDownStartPoint = recalculatePointCoordinates( getBottomRightCornerPoint(), - getITouchActionsConfiguration().getHorizontalSwipeBottomPointXCoefficient(), - getITouchActionsConfiguration().getHorizontalSwipeBottomPointYCoefficient()); + (1 - getConfiguration().getSwipeHorizontalOffset()), + (1 - getConfiguration().getSwipeVerticalOffset())); this.scrollDownEndPoint = recalculatePointCoordinates( getBottomRightCornerPoint(), - getITouchActionsConfiguration().getHorizontalSwipeTopPointXCoefficient(), - getITouchActionsConfiguration().getHorizontalSwipeTopPointYCoefficient()); + getConfiguration().getSwipeHorizontalOffset(), + getConfiguration().getSwipeVerticalOffset()); this.swipeLeftStartPoint = recalculatePointCoordinates( getBottomRightCornerPoint(), - getITouchActionsConfiguration().getVerticalSwipeRightPointXCoefficient(), - getITouchActionsConfiguration().getVerticalSwipeRightPointYCoefficient()); + (1 - getConfiguration().getSwipeVerticalOffset()), + (1 - getConfiguration().getSwipeHorizontalOffset())); this.swipeLeftEndPoint = recalculatePointCoordinates( getBottomRightCornerPoint(), - getITouchActionsConfiguration().getVerticalSwipeLeftPointXCoefficient(), - getITouchActionsConfiguration().getVerticalSwipeLeftPointYCoefficient()); + getConfiguration().getSwipeVerticalOffset(), + getConfiguration().getSwipeHorizontalOffset()); this.scrollUpStartPoint = this.scrollDownEndPoint; this.scrollUpEndPoint = this.scrollDownStartPoint; this.swipeRightStartPoint = this.swipeLeftEndPoint; @@ -92,15 +92,15 @@ private Point getBottomRightCornerPoint() { /** * Returns the point with recalculated coordinates. * - * @param point point to recalculate coordinates - * @param coefficientX coefficient to recalculate the point's x coordinate. Example: x' = x * coefficientX - * @param coefficientY coefficient to recalculate the point's y coordinate. Example: y' = y * coefficientY - * @return point with recalculated coordinates according to the xCoefficient and yCoefficient + * @param point point to recalculate coordinates + * @param horizontalOffset coefficient to recalculate the point with horizontal offset. + * @param verticalOffset coefficient to recalculate the point with vertical offset. + * @return point with recalculated coordinates with horizontal and vertical offset. */ - private Point recalculatePointCoordinates(Point point, double coefficientX, double coefficientY) { + private Point recalculatePointCoordinates(Point point, double horizontalOffset, double verticalOffset) { return new Point( - (int) (point.getX() * coefficientX), - (int) (point.getY() * coefficientY)); + (int) (point.getX() * horizontalOffset), + (int) (point.getY() * verticalOffset)); } /** @@ -108,7 +108,7 @@ private Point recalculatePointCoordinates(Point point, double coefficientX, doub * * @return ITouchActionsConfiguration class */ - private ITouchActionsConfiguration getITouchActionsConfiguration() { + private ITouchActionsConfiguration getConfiguration() { return AqualityServices.get(ITouchActionsConfiguration.class); } } diff --git a/src/main/java/aquality/appium/mobile/elements/actions/IElementTouchActions.java b/src/main/java/aquality/appium/mobile/elements/actions/IElementTouchActions.java index ce509b4..6727a9a 100644 --- a/src/main/java/aquality/appium/mobile/elements/actions/IElementTouchActions.java +++ b/src/main/java/aquality/appium/mobile/elements/actions/IElementTouchActions.java @@ -13,19 +13,19 @@ public interface IElementTouchActions { * * @param endPoint point on screen to swipe to. */ - void swipe(Point endPoint); + void swipe(final Point endPoint); /** * Swipes from element to end point using LongPress. * * @param endPoint point on screen to swipe to. */ - void swipeWithLongPress(Point endPoint); + void swipeWithLongPress(final Point endPoint); /** * Scrolls current screen in provided direction until element is displayed. * * @param direction direction to swipe. */ - void scrollToElement(SwipeDirection direction); + void scrollToElement(final SwipeDirection direction); } diff --git a/src/main/resources/settings.json b/src/main/resources/settings.json index 946592e..f427ceb 100644 --- a/src/main/resources/settings.json +++ b/src/main/resources/settings.json @@ -1,9 +1,8 @@ { - "platformName" : "android", + "platformName": "android", "isRemote": false, "remoteConnectionUrl": "http://127.0.0.1:4723/wd/hub", "screensLocation": "", - "driverSettings": { "android": { "deviceKey": "", @@ -47,16 +46,10 @@ }, "touchActions": { "swipe": { - "timeout": 1, + "duration": 1, "retries": 5, - "horizontalSwipeTopPointXCoefficient": 0.5, - "horizontalSwipeBottomPointXCoefficient": 0.5, - "horizontalSwipeTopPointYCoefficient": 0.2, - "horizontalSwipeBottomPointYCoefficient": 0.8, - "verticalSwipeLeftPointXCoefficient": 0.2, - "verticalSwipeRightPointXCoefficient": 0.8, - "verticalSwipeLeftPointYCoefficient": 0.5, - "verticalSwipeRightPointYCoefficient": 0.5 + "verticalOffset": 0.2, + "horizontalOffset": 0.5 } } } \ No newline at end of file diff --git a/src/test/resources/settings.androidwebsession.json b/src/test/resources/settings.androidwebsession.json index b6c018c..1c9af04 100644 --- a/src/test/resources/settings.androidwebsession.json +++ b/src/test/resources/settings.androidwebsession.json @@ -1,9 +1,8 @@ { - "platformName" : "android", + "platformName": "android", "isRemote": true, "remoteConnectionUrl": "http://127.0.0.1:4723/wd/hub", "screensLocation": "integration", - "driverSettings": { "android": { "capabilities": { @@ -22,10 +21,10 @@ } }, "timeouts": { - "timeoutImplicit" : 0, - "timeoutCondition" : 15, + "timeoutImplicit": 0, + "timeoutCondition": 15, "timeoutPollingInterval": 300, - "timeoutCommand":120 + "timeoutCommand": 120 }, "retry": { "number": 2, @@ -39,16 +38,10 @@ }, "touchActions": { "swipe": { - "timeout": 1, + "duration": 1, "retries": 5, - "horizontalSwipeTopPointXCoefficient": 0.5, - "horizontalSwipeBottomPointXCoefficient": 0.5, - "horizontalSwipeTopPointYCoefficient": 0.2, - "horizontalSwipeBottomPointYCoefficient": 0.8, - "verticalSwipeLeftPointXCoefficient": 0.2, - "verticalSwipeRightPointXCoefficient": 0.8, - "verticalSwipeLeftPointYCoefficient": 0.5, - "verticalSwipeRightPointYCoefficient": 0.5 + "verticalOffset": 0.2, + "horizontalOffset": 0.5 } } } \ No newline at end of file diff --git a/src/test/resources/settings.json b/src/test/resources/settings.json index 289b48f..f04bb75 100644 --- a/src/test/resources/settings.json +++ b/src/test/resources/settings.json @@ -3,7 +3,6 @@ "isRemote": true, "remoteConnectionUrl": "http://127.0.0.1:4723/wd/hub", "screensLocation": "integration", - "driverSettings": { "android": { "deviceKey": "Android_Emulator", @@ -49,16 +48,10 @@ }, "touchActions": { "swipe": { - "timeout": 1, + "duration": 1, "retries": 5, - "horizontalSwipeTopPointXCoefficient": 0.5, - "horizontalSwipeBottomPointXCoefficient": 0.5, - "horizontalSwipeTopPointYCoefficient": 0.2, - "horizontalSwipeBottomPointYCoefficient": 0.8, - "verticalSwipeLeftPointXCoefficient": 0.2, - "verticalSwipeRightPointXCoefficient": 0.8, - "verticalSwipeLeftPointYCoefficient": 0.5, - "verticalSwipeRightPointYCoefficient": 0.5 + "verticalOffset": 0.2, + "horizontalOffset": 0.5 } } } \ No newline at end of file From dbf631f9a0a8540c44fd9446838470cbaf3ba2b3 Mon Sep 17 00:00:00 2001 From: n-verbitsky Date: Wed, 3 Jun 2020 15:59:00 +0300 Subject: [PATCH 20/21] Removing registration of dependencies as singleton --- .../java/aquality/appium/mobile/application/MobileModule.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/aquality/appium/mobile/application/MobileModule.java b/src/main/java/aquality/appium/mobile/application/MobileModule.java index c8aef82..6932974 100644 --- a/src/main/java/aquality/appium/mobile/application/MobileModule.java +++ b/src/main/java/aquality/appium/mobile/application/MobileModule.java @@ -29,7 +29,7 @@ protected void configure() { bind(IConfiguration.class).to(getConfigurationImplementation()); bind(IElementFactory.class).to(getElementFactoryImplementation()); bind(IScreenFactory.class).to(getScreenFactoryImplementation()); - bind(ITouchActionsConfiguration.class).to(getTouchActionsConfigurationImplementation()).in(Singleton.class); - bind(ITouchActions.class).to(getTouchActionsImplementation()).in(Singleton.class); + bind(ITouchActionsConfiguration.class).to(getTouchActionsConfigurationImplementation()); + bind(ITouchActions.class).to(getTouchActionsImplementation()); } } From 0f90061760be9b84a7310a97c8f79b2883c7fc22 Mon Sep 17 00:00:00 2001 From: n-verbitsky Date: Thu, 4 Jun 2020 00:23:29 +0300 Subject: [PATCH 21/21] increasing minor version in pom.xml --- pom.xml | 2 +- src/main/java/aquality/appium/mobile/actions/ITouchActions.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3dd0a26..58203a1 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.aquality-automation aquality-appium-mobile - 2.0.0 + 2.1.0 jar Aquality Appium Mobile diff --git a/src/main/java/aquality/appium/mobile/actions/ITouchActions.java b/src/main/java/aquality/appium/mobile/actions/ITouchActions.java index 3fd7082..6f4c624 100644 --- a/src/main/java/aquality/appium/mobile/actions/ITouchActions.java +++ b/src/main/java/aquality/appium/mobile/actions/ITouchActions.java @@ -16,7 +16,7 @@ public interface ITouchActions { void swipe(Point startPoint, Point endPoint); /** - * Performs long press action and moves cursor from a start point to an end end point imitating the swipe action. + * Performs long press action and moves cursor from a start point to an end point imitating the swipe action. * * @param startPoint point on screen to swipe from. * @param endPoint point on screen to swipe to.