diff --git a/src/main/java/com/shaft/gui/element/ElementActions.java b/src/main/java/com/shaft/gui/element/ElementActions.java index f2b292e9598..4bcaaa1e303 100755 --- a/src/main/java/com/shaft/gui/element/ElementActions.java +++ b/src/main/java/com/shaft/gui/element/ElementActions.java @@ -703,15 +703,16 @@ public ElementActions select(By elementLocator, String valueOrVisibleText) { click(elementInformation.getLocator()); elementInformation = ElementInformation.fromList(ElementActionsHelper. identifyUniqueElement((WebDriver) DriverFactoryHelper.getDriver().get(), elementLocator)); - RelativeLocator.RelativeBy relativeBy = null; try { - relativeBy = SHAFT.GUI.Locator.hasAnyTagName().and().containsText(valueOrVisibleText).relativeBy().below(elementInformation.getLocator()); - } catch (Exception e) { + RelativeLocator.RelativeBy relativeBy = SHAFT.GUI.Locator.hasAnyTagName().and().containsText(valueOrVisibleText).relativeBy().below(elementInformation.getLocator()); + elementInformation = ElementInformation.fromList(ElementActionsHelper. + identifyUniqueElement((WebDriver) DriverFactoryHelper.getDriver().get(), relativeBy)); + } catch (Throwable var9) { ReportManager.logDiscrete("Cannot Find Element with the following Locator in the DropDown Options: " + By.xpath("//*[text()='" + valueOrVisibleText + "']")); ElementActionsHelper.failAction((WebDriver) DriverFactoryHelper.getDriver().get(), - valueOrVisibleText, By.xpath("//*[text()='" + valueOrVisibleText + "']"), e); + By.xpath("//*[text()='" + valueOrVisibleText + "']").toString(), elementLocator, var9); } - click(relativeBy); + click(elementInformation.getLocator()); } else { ReportManager.logDiscrete("Cannot Find Element with the following Locator in the DropDown Options: " + By.xpath("//*[text()='" + valueOrVisibleText + "']")); diff --git a/src/test/java/testPackage/appium/DragAndDropTest.java b/src/test/java/testPackage/appium/DragAndDropTest.java new file mode 100644 index 00000000000..cf817b1bf16 --- /dev/null +++ b/src/test/java/testPackage/appium/DragAndDropTest.java @@ -0,0 +1,38 @@ +package testPackage.appium; + +import com.shaft.driver.SHAFT; +import io.appium.java_client.AppiumBy; +import io.appium.java_client.remote.AutomationName; +import org.openqa.selenium.By; +import org.openqa.selenium.Platform; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class DragAndDropTest { + private SHAFT.GUI.WebDriver driver; + private final AppiumBy dragBtn = new AppiumBy.ByAndroidUIAutomator("UiSelector().text(\"Drag\")"); + private final By toBeDragged = By.xpath("//android.view.ViewGroup[@content-desc=\"drag-l1\"]/android.widget.ImageView"); + private final By toBeDropped =By.xpath("//android.view.ViewGroup[@content-desc=\"drop-l1\"]/android.view.ViewGroup"); + @BeforeMethod + public void setupUp(){ + System.setProperty("mobile_autoGrantPermissions", "true"); + SHAFT.Properties.platform.set().targetPlatform(Platform.ANDROID.name()); + SHAFT.Properties.mobile.set().automationName(AutomationName.ANDROID_UIAUTOMATOR2); + SHAFT.Properties.platform.set().executionAddress("127.0.0.1:4754"); + SHAFT.Properties.mobile.set().deviceName("Pixel 4 API 28"); + SHAFT.Properties.mobile.set().app("src/test/resources/testDataFiles/apps/wdio-demo.apk"); + driver = new SHAFT.GUI.WebDriver(); + } + + @Test + public void testDragAndDrop(){ + driver.element().touch().tap(dragBtn); + driver.element().touch().swipeToElement(toBeDragged, toBeDropped); + } + + @AfterMethod(alwaysRun = true) + public void teardown() { + driver.quit(); + } +} diff --git a/src/test/java/testPackage/unitTests/SelectMethod.java b/src/test/java/testPackage/unitTests/SelectMethod.java index d077ba0881e..3ed4ae0e9b7 100644 --- a/src/test/java/testPackage/unitTests/SelectMethod.java +++ b/src/test/java/testPackage/unitTests/SelectMethod.java @@ -20,11 +20,17 @@ protected void setUp() { } @Test - public void testSelect(){ + public void testValidSelect(){ login("Admin","admin123") .clickDropDownList("Support"); } + @Test + public void testInvalidSelect(){ + login("Admin","admin123") + .clickDropDownList("sds"); + } + @AfterMethod protected void tearDown(){ driver.get().quit();} diff --git a/src/test/resources/testDataFiles/apps/wdio-demo.apk b/src/test/resources/testDataFiles/apps/wdio-demo.apk new file mode 100644 index 00000000000..68e5bc80c99 Binary files /dev/null and b/src/test/resources/testDataFiles/apps/wdio-demo.apk differ