diff --git a/pom.xml b/pom.xml index 7d35f9b1a..41e55de29 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ 7.4.0 - 4.2.2 + 4.3.0 8.1.1 7.6.0 diff --git a/selcukes-core/src/main/java/io/github/selcukes/core/driver/DriverManager.java b/selcukes-core/src/main/java/io/github/selcukes/core/driver/DriverManager.java index 54d44bb07..46b637c5e 100644 --- a/selcukes-core/src/main/java/io/github/selcukes/core/driver/DriverManager.java +++ b/selcukes-core/src/main/java/io/github/selcukes/core/driver/DriverManager.java @@ -24,6 +24,7 @@ import lombok.experimental.UtilityClass; import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WrapsDriver; import org.openqa.selenium.support.events.EventFiringDecorator; import org.openqa.selenium.support.events.WebDriverListener; @@ -74,6 +75,12 @@ public static D getDriver() { return (D) DRIVER_THREAD.get(); } + public static WebDriver getWrappedDriver() { + if (getDriver() instanceof WrapsDriver) + return ((WrapsDriver) getDriver()).getWrappedDriver(); + return getDriver(); + } + public static void setDriver(D driver) { DRIVER_THREAD.set(driver); STORED_DRIVER.putIfAbsent(driver.hashCode(), driver); diff --git a/selcukes-core/src/main/java/io/github/selcukes/core/page/MobilePage.java b/selcukes-core/src/main/java/io/github/selcukes/core/page/MobilePage.java index 36947428a..656d5a7e2 100644 --- a/selcukes-core/src/main/java/io/github/selcukes/core/page/MobilePage.java +++ b/selcukes-core/src/main/java/io/github/selcukes/core/page/MobilePage.java @@ -53,23 +53,6 @@ public MobilePage enter(String accessibilityId, CharSequence text) { return this; } - public MobilePage tap(String accessibilityId) { - click(accessibilityId); - return this; - } - - @Override - public MobilePage tap(By by) { - click(by); - return this; - } - - @Override - public MobilePage doubleTap(By by) { - doubleClick(by); - return this; - } - public MobilePage swipe(String targetAccessibilityId, SwipeDirection swipeDirection) { swipe(AppiumBy.accessibilityId(targetAccessibilityId), swipeDirection); return this; diff --git a/selcukes-core/src/main/java/io/github/selcukes/core/page/Page.java b/selcukes-core/src/main/java/io/github/selcukes/core/page/Page.java index a50f1cfd0..e9e1300cd 100644 --- a/selcukes-core/src/main/java/io/github/selcukes/core/page/Page.java +++ b/selcukes-core/src/main/java/io/github/selcukes/core/page/Page.java @@ -22,7 +22,6 @@ import io.github.selcukes.core.wait.WaitManager; import org.openqa.selenium.*; import org.openqa.selenium.interactions.Actions; -import org.openqa.selenium.interactions.touch.TouchActions; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.Select; @@ -48,6 +47,16 @@ default Page navigateTo(String url) { return this; } + default Page maximize() { + getDriver().manage().window().maximize(); + return this; + } + + default Page implicitlyWait() { + getDriver().manage().timeouts().implicitlyWait(Duration.ofSeconds(1)); + return this; + } + default String title() { return getDriver().getTitle(); } @@ -114,23 +123,13 @@ default Actions actions() { return new Actions(getDriver()); } - default TouchActions touchActions() { - return new TouchActions(getDriver()); - } - - default Page tap(By by) { - touchActions().singleTap(find(by)).perform(); - return this; - } - - default Page doubleTap(By by) { - touchActions().doubleTap(find(by)).perform(); + default Page dragAndDrop(WebElement source, WebElement target) { + actions().dragAndDrop(source, target).perform(); return this; } - default Page swipe(By target) { - Point elementLocation = find(target).getLocation(); - touchActions().scroll(elementLocation.getX(), elementLocation.getY()).perform(); + default Page dragAndDrop(By source, By target) { + dragAndDrop(find(source, WaitCondition.VISIBLE), find(target, WaitCondition.VISIBLE)); return this; } diff --git a/selcukes-core/src/test/java/io/github/selcukes/core/tests/mobile/MobileAppTest.java b/selcukes-core/src/test/java/io/github/selcukes/core/tests/mobile/MobileAppTest.java index 7fec537c1..5bf9a9399 100644 --- a/selcukes-core/src/test/java/io/github/selcukes/core/tests/mobile/MobileAppTest.java +++ b/selcukes-core/src/test/java/io/github/selcukes/core/tests/mobile/MobileAppTest.java @@ -23,6 +23,7 @@ import io.github.selcukes.core.enums.SwipeDirection; import io.github.selcukes.core.page.MobilePage; import io.github.selcukes.core.page.Pages; +import io.github.selcukes.core.wait.WaitCondition; import org.openqa.selenium.By; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -41,43 +42,43 @@ void beforeTest() { @Test(enabled = false) public void expandAndScrollScreenTest() { - page.tap("Views") - .tap("Expandable Lists") - .tap("3. Simple Adapter") + page.click("Views") + .click("Expandable Lists") + .click("3. Simple Adapter") .swipe(By.xpath("//android.widget.TextView[@text='Group 18']"), SwipeDirection.DOWN) - .tap(By.xpath("//android.widget.TextView[@text='Group 18']")) - .swipe(By.xpath("//android.widget.TextView[@text='Child 13']"), SwipeDirection.DOWN) + .click(By.xpath("//android.widget.TextView[@text='Group 18']")); + page.swipe(By.xpath("//android.widget.TextView[@text='Child 13']"), SwipeDirection.DOWN) .swipe(By.xpath("//android.widget.TextView[@text='Group 1']"), SwipeDirection.UP); } @Test(enabled = false) public void expandAndScrollElementTest() { - page.tap("Views") + page.click("Views") .swipe("Splitting Touches across Views", SwipeDirection.DOWN) - .tap("Splitting Touches across Views") + .click("Splitting Touches across Views") .swipe(By.id("io.appium.android.apis:id/list2"), By.xpath("//android.widget.ListView[2]/android.widget.TextView[@text='Blue']"), SwipeDirection.DOWN) - .tap(By.xpath("//android.widget.ListView[2]/android.widget.TextView[@text='Blue']")) - .swipe(By.id("io.appium.android.apis:id/list2"), By.xpath("//android.widget.ListView[2]/android.widget.TextView[@text='Abbaye de Belloc']"), SwipeDirection.UP) - .tap(By.xpath("//android.widget.ListView[2]/android.widget.TextView[@text='Abbaye de Belloc']")); + .click(By.xpath("//android.widget.ListView[2]/android.widget.TextView[@text='Blue']"), WaitCondition.PRESENT); + page.swipe(By.id("io.appium.android.apis:id/list2"), By.xpath("//android.widget.ListView[2]/android.widget.TextView[@text='Abbaye de Belloc']"), SwipeDirection.UP) + .click(By.xpath("//android.widget.ListView[2]/android.widget.TextView[@text='Abbaye de Belloc']")); } @Test(enabled = false) public void alertTest() { - ((AndroidDriver) DriverManager.getDriver()) + ((AndroidDriver) DriverManager.getWrappedDriver()) .startActivity(new Activity("io.appium.android.apis", ".app.AlertDialogSamples")); - page.tap(By.id("io.appium.android.apis:id/two_buttons")) + page.click(By.id("io.appium.android.apis:id/two_buttons")) - .tap(By.id("android:id/button1")); + .click(By.id("android:id/button1")); } @Test(enabled = false) public void searchTest() { - ((AndroidDriver) DriverManager.getDriver()) + ((AndroidDriver) DriverManager.getWrappedDriver()) .startActivity(new Activity("io.appium.android.apis", ".app.SearchInvoke")); page.enter(By.id("txt_query_prefill"), "Hello world!") - .tap(By.id("btn_start_search")); + .click(By.id("btn_start_search")); } @AfterMethod diff --git a/selcukes-core/src/test/java/io/github/selcukes/core/tests/unit/ShadowRootTest.java b/selcukes-core/src/test/java/io/github/selcukes/core/tests/unit/ShadowRootTest.java index 51d82ec54..e7c411682 100644 --- a/selcukes-core/src/test/java/io/github/selcukes/core/tests/unit/ShadowRootTest.java +++ b/selcukes-core/src/test/java/io/github/selcukes/core/tests/unit/ShadowRootTest.java @@ -52,4 +52,14 @@ public void shadowElementTest() { } + @Test + public void dragAndDropTest() { + By source = By.xpath(".//*[@id='draggable']"); + By target = By.xpath(".//*[@id='droppable']"); + page.open("http://jqueryui.com/resources/demos/droppable/default.html") + .dragAndDrop(source, target) + .assertThat().element(target).textAs("Dropped!"); + + } + }