diff --git a/src/main/java/com/znsio/teswiz/entities/Direction.java b/src/main/java/com/znsio/teswiz/entities/Direction.java index 95685c211..c6949e3ac 100644 --- a/src/main/java/com/znsio/teswiz/entities/Direction.java +++ b/src/main/java/com/znsio/teswiz/entities/Direction.java @@ -2,7 +2,9 @@ public enum Direction { UP("up"), - DOWN("down"); + DOWN("down"), + LEFT("left"), + RIGHT("right"); private final String direction; Direction(String direction) { diff --git a/src/main/java/com/znsio/teswiz/runner/Driver.java b/src/main/java/com/znsio/teswiz/runner/Driver.java index 373b0cbc1..59e8c2848 100644 --- a/src/main/java/com/znsio/teswiz/runner/Driver.java +++ b/src/main/java/com/znsio/teswiz/runner/Driver.java @@ -4,6 +4,7 @@ import com.znsio.teswiz.entities.Direction; import com.znsio.teswiz.entities.Platform; import com.znsio.teswiz.exceptions.FileNotUploadedException; +import com.znsio.teswiz.exceptions.InvalidTestDataException; import io.appium.java_client.AppiumBy; import io.appium.java_client.AppiumDriver; import io.appium.java_client.HidesKeyboard; @@ -26,6 +27,7 @@ import org.openqa.selenium.interactions.Pause; import org.openqa.selenium.interactions.PointerInput; import org.openqa.selenium.interactions.Sequence; +import org.openqa.selenium.remote.RemoteWebElement; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; @@ -37,6 +39,7 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import java.util.Map; import static com.znsio.teswiz.tools.Wait.waitFor; @@ -604,7 +607,6 @@ public void doubleTap(WebElement element) { appiumDriver.perform(Arrays.asList(clickPosition)); } - public void flick() { AppiumDriver appiumDriver = (AppiumDriver) this.driver; Dimension screenSize = driver.manage().window().getSize(); @@ -625,4 +627,15 @@ public void flick() { appiumDriver.perform(Arrays.asList(flick)); } + + public void horizontalSwipeWithGesture(WebElement element, Direction direction) { + RemoteWebElement remoteWebElement = (RemoteWebElement) element; + if ((direction.equals(Direction.LEFT)) || direction.equals(Direction.RIGHT)) { + ((JavascriptExecutor) driver).executeScript("mobile: swipeGesture", Map.of("elementId", remoteWebElement.getId(), + "direction", direction.toString(), + "percent", 1, + "speed", 80 + )); + } else throw new InvalidTestDataException("Invalid Direction"); + } } \ No newline at end of file diff --git a/src/test/java/com/znsio/teswiz/businessLayer/jiocinema/JioCinemaBL.java b/src/test/java/com/znsio/teswiz/businessLayer/jiocinema/JioCinemaBL.java index ad2b8812b..3502f4c44 100644 --- a/src/test/java/com/znsio/teswiz/businessLayer/jiocinema/JioCinemaBL.java +++ b/src/test/java/com/znsio/teswiz/businessLayer/jiocinema/JioCinemaBL.java @@ -1,6 +1,7 @@ package com.znsio.teswiz.businessLayer.jiocinema; import com.context.TestExecutionContext; +import com.znsio.teswiz.entities.Direction; import com.znsio.teswiz.entities.Platform; import com.znsio.teswiz.runner.Runner; import com.znsio.teswiz.screen.jiocinema.JioCinemaScreen; @@ -40,6 +41,11 @@ public JioCinemaBL scrollTillTrendingInIndiaSection() { return this; } + public JioCinemaBL swipeMovieTrendingInIndiaSection(Direction direction, int movieNumberOnScreen) { + JioCinemaScreen.get().swipeTrendingItem(direction, movieNumberOnScreen); + return this; + } + public JioCinemaBL verifyMovieNumberVisibleOnScreen(int movieNumberOnScreen) { LOGGER.info("verifying movie number visible on trending in india screen after swipe"); assertThat(JioCinemaScreen.get().isMovieNumberVisibleOnScreen(movieNumberOnScreen)) diff --git a/src/test/java/com/znsio/teswiz/screen/android/jiocinema/JioCinemaScreenAndroid.java b/src/test/java/com/znsio/teswiz/screen/android/jiocinema/JioCinemaScreenAndroid.java index 48a6cbf27..ec83ab3ff 100644 --- a/src/test/java/com/znsio/teswiz/screen/android/jiocinema/JioCinemaScreenAndroid.java +++ b/src/test/java/com/znsio/teswiz/screen/android/jiocinema/JioCinemaScreenAndroid.java @@ -2,11 +2,14 @@ import com.applitools.eyes.MatchLevel; import com.applitools.eyes.appium.Target; +import com.znsio.teswiz.entities.Direction; import com.znsio.teswiz.runner.Driver; import com.znsio.teswiz.runner.Visual; import com.znsio.teswiz.screen.jiocinema.JioCinemaScreen; import io.appium.java_client.AppiumBy; import org.apache.log4j.Logger; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; public class JioCinemaScreenAndroid extends JioCinemaScreen { private static final Logger LOGGER = Logger.getLogger(JioCinemaScreenAndroid.class.getName()); @@ -14,6 +17,7 @@ public class JioCinemaScreenAndroid extends JioCinemaScreen { private final Visual visually; private final String SCREEN_NAME = JioCinemaScreenAndroid.class.getSimpleName(); private final String visibleMovieNumberXpath = "//android.widget.TextView[@text='%s']"; + private final String movieXpath = "//android.widget.TextView[@text='%s']//parent::android.view.View"; public JioCinemaScreenAndroid(Driver driver, Visual visually) { this.driver = driver; @@ -49,4 +53,13 @@ public boolean isMovieNumberVisibleOnScreen(int movieNumberOnScreen) { Target.region(AppiumBy.xpath(String.format(visibleMovieNumberXpath, movieNumberOnScreen)))); return isMovieVisibleOnScreen; } + + @Override + public JioCinemaScreen swipeTrendingItem(Direction direction, int movieNumberOnScreen) { + LOGGER.info(String.format("Swiping %s movie number : %s ", direction, movieNumberOnScreen)); + WebElement movieTrending = driver.waitTillElementIsVisible( + By.xpath(String.format(movieXpath, movieNumberOnScreen))); + driver.horizontalSwipeWithGesture(movieTrending, direction); + return this; + } } \ No newline at end of file diff --git a/src/test/java/com/znsio/teswiz/screen/jiocinema/JioCinemaScreen.java b/src/test/java/com/znsio/teswiz/screen/jiocinema/JioCinemaScreen.java index 1e2c75bd9..e37a809f6 100644 --- a/src/test/java/com/znsio/teswiz/screen/jiocinema/JioCinemaScreen.java +++ b/src/test/java/com/znsio/teswiz/screen/jiocinema/JioCinemaScreen.java @@ -1,5 +1,6 @@ package com.znsio.teswiz.screen.jiocinema; +import com.znsio.teswiz.entities.Direction; import com.znsio.teswiz.entities.Platform; import com.znsio.teswiz.runner.Driver; import com.znsio.teswiz.runner.Drivers; @@ -34,4 +35,7 @@ public static JioCinemaScreen get() { public abstract JioCinemaScreen scrollTillTrendingInIndiaSection(); public abstract boolean isMovieNumberVisibleOnScreen(int movieNumberOnScreen); + + public abstract JioCinemaScreen swipeTrendingItem(Direction direction, int movieNumberOnScreen); + } \ No newline at end of file diff --git a/src/test/java/com/znsio/teswiz/steps/JioCinemaSteps.java b/src/test/java/com/znsio/teswiz/steps/JioCinemaSteps.java index c9707bf05..573007748 100644 --- a/src/test/java/com/znsio/teswiz/steps/JioCinemaSteps.java +++ b/src/test/java/com/znsio/teswiz/steps/JioCinemaSteps.java @@ -3,6 +3,7 @@ import com.context.SessionContext; import com.context.TestExecutionContext; import com.znsio.teswiz.businessLayer.jiocinema.JioCinemaBL; +import com.znsio.teswiz.entities.Direction; import com.znsio.teswiz.entities.SAMPLE_TEST_CONTEXT; import com.znsio.teswiz.runner.Drivers; import com.znsio.teswiz.runner.Runner; @@ -40,4 +41,10 @@ public void iSwipeLeftOnTrendingInIndiaSection() { public void iAmAbleToViewNumberTrendingCinema(int movieNumberOnScreen) { new JioCinemaBL(SAMPLE_TEST_CONTEXT.ME, Runner.getPlatform()).verifyMovieNumberVisibleOnScreen(movieNumberOnScreen); } + + @When("I swipe {string} trending no {int} on trending in india section") + public void iSwipeTrendingNoOnTrendingInIndiaSection(String direction, int movieNumberOnScreen) { + new JioCinemaBL(SAMPLE_TEST_CONTEXT.ME, Runner.getPlatform()) + .swipeMovieTrendingInIndiaSection(Direction.valueOf(direction.toUpperCase()),movieNumberOnScreen); + } } \ No newline at end of file diff --git a/src/test/resources/com/znsio/teswiz/features/jioCinema.feature b/src/test/resources/com/znsio/teswiz/features/jioCinema.feature index c8d25ced9..ccf0beea2 100644 --- a/src/test/resources/com/znsio/teswiz/features/jioCinema.feature +++ b/src/test/resources/com/znsio/teswiz/features/jioCinema.feature @@ -9,4 +9,13 @@ Feature: jio cinema test When I swipe left on tending in india section Then I am able to view number 3 trending movie When I swipe right on tending in india section - Then I am able to view number 1 trending movie \ No newline at end of file + Then I am able to view number 1 trending movie + + # CONFIG=./configs/jiocinema_local_config.properties PLATFORM=android TAG=horizontalSwipeUsingGesturePluginTest ./gradlew run + @android @swipe @horizontalSwipeUsingGesturePluginTest + Scenario: validating horizontal swipe with gesture functionality + Given I navigate to jio Cinema application's home page + When I swipe "left" trending no 2 on trending in india section + Then I am able to view number 3 trending movie + When I swipe "right" trending no 2 on trending in india section + Then I am able to view number 1 trending movie