diff --git a/selcukes-core/src/main/java/io/github/selcukes/core/driver/MobileManager.java b/selcukes-core/src/main/java/io/github/selcukes/core/driver/AppiumManager.java similarity index 54% rename from selcukes-core/src/main/java/io/github/selcukes/core/driver/MobileManager.java rename to selcukes-core/src/main/java/io/github/selcukes/core/driver/AppiumManager.java index 0a72d10db..70acb88a4 100644 --- a/selcukes-core/src/main/java/io/github/selcukes/core/driver/MobileManager.java +++ b/selcukes-core/src/main/java/io/github/selcukes/core/driver/AppiumManager.java @@ -17,37 +17,35 @@ package io.github.selcukes.core.driver; import io.appium.java_client.AppiumDriver; +import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.service.local.AppiumDriverLocalService; import io.appium.java_client.service.local.AppiumServiceBuilder; +import io.appium.java_client.service.local.flags.GeneralServerFlag; import io.github.selcukes.commons.config.ConfigFactory; import io.github.selcukes.commons.exception.DriverSetupException; -import io.github.selcukes.core.enums.DriverType; +import io.github.selcukes.commons.helper.FileHelper; import lombok.CustomLog; -import lombok.SneakyThrows; import org.openqa.selenium.Capabilities; -import java.net.URL; - @CustomLog -public class MobileManager implements RemoteManager { +public class AppiumManager implements RemoteManager { AppiumDriver driver; AppiumDriverLocalService service; @Override public AppiumDriver createDriver() { - String browser = ConfigFactory.getConfig().getWeb().get("browserName"); + if (null == driver) { try { - logger.info(() -> "Initiating New Browser Session..."); - service = new AppiumServiceBuilder() - .withIPAddress("127.0.0.1") - .usingPort(4723) - .build(); - service.start(); - - MobileOptions browserOptions = new MobileOptions(); - Capabilities capabilities = browserOptions.getMobileOptions(DriverType.valueOf(browser)); - driver = new AppiumDriver(getServiceUrl(), capabilities); + logger.info(() -> "Initiating New Mobile Session..."); + startAppiumService(); + Capabilities capabilities = DesktopOptions.getUserOptions(); + if (capabilities == null) { + String app = FileHelper.loadThreadResource(ConfigFactory.getConfig() + .getMobile().get("app")).getAbsolutePath(); + capabilities = DesktopOptions.getAndroidOptions(app); + } + driver = new AndroidDriver(service.getUrl(), capabilities); } catch (Exception e) { throw new DriverSetupException("Driver was not setup properly.", e); } @@ -60,15 +58,22 @@ public void destroyDriver() { if (driver != null) { driver.quit(); } - if (service != null) { - service.stop(); - } + stopAppiumService(); } - @SneakyThrows - @Override - public URL getServiceUrl() { - String serviceUrl = ConfigFactory.getConfig().getMobile().get("serviceUrl"); - return new URL(serviceUrl); + public void startAppiumService() { + service = new AppiumServiceBuilder() + .withIPAddress("127.0.0.1") + .usingAnyFreePort() + .withArgument(GeneralServerFlag.SESSION_OVERRIDE) + .withArgument(GeneralServerFlag.BASEPATH, "/wd/") + .build(); + logger.info(() -> "Starting Appium server..."); + service.start(); + } + + public void stopAppiumService() { + if (service != null) + service.stop(); } } diff --git a/selcukes-core/src/main/java/io/github/selcukes/core/driver/BrowserOptions.java b/selcukes-core/src/main/java/io/github/selcukes/core/driver/BrowserOptions.java index de8eb8d23..e09b5704b 100644 --- a/selcukes-core/src/main/java/io/github/selcukes/core/driver/BrowserOptions.java +++ b/selcukes-core/src/main/java/io/github/selcukes/core/driver/BrowserOptions.java @@ -16,7 +16,6 @@ package io.github.selcukes.core.driver; -import io.github.selcukes.commons.config.ConfigFactory; import io.github.selcukes.core.enums.DriverType; import io.github.selcukes.wdb.WebDriverBinary; import org.openqa.selenium.Capabilities; diff --git a/selcukes-core/src/main/java/io/github/selcukes/core/driver/DesktopManager.java b/selcukes-core/src/main/java/io/github/selcukes/core/driver/DesktopManager.java index d2bd57f76..02e7e2fd9 100644 --- a/selcukes-core/src/main/java/io/github/selcukes/core/driver/DesktopManager.java +++ b/selcukes-core/src/main/java/io/github/selcukes/core/driver/DesktopManager.java @@ -19,23 +19,22 @@ import io.appium.java_client.windows.WindowsDriver; import io.github.selcukes.commons.config.ConfigFactory; import lombok.CustomLog; -import lombok.SneakyThrows; import java.net.URL; import java.util.Objects; @CustomLog -public class DesktopManager implements RemoteManager { - +public class DesktopManager extends AppiumManager { private WindowsDriver windowsDriver; - private Process winProcess; + @Override public synchronized WindowsDriver createDriver() { if (null == windowsDriver) { - startWinAppDriver(); + startAppiumService(); String app = ConfigFactory.getConfig().getWindows().get("app"); - windowsDriver = new WindowsDriver(Objects.requireNonNull(getServiceUrl()), - DesktopOptions.setCapabilities(app)); + URL serviceUrl = Objects.requireNonNull(service.getUrl()); + DesktopOptions.setServiceUrl(serviceUrl); + windowsDriver = new WindowsDriver(serviceUrl, DesktopOptions.getWinAppOptions(app)); } return windowsDriver; } @@ -44,26 +43,7 @@ public void destroyDriver() { if (windowsDriver != null) { windowsDriver.closeApp(); } - killWinAppDriver(); - } - - @SneakyThrows - private void startWinAppDriver() { - ProcessBuilder processBuilder = new ProcessBuilder(ConfigFactory.getConfig().getWindows().get("winApp-path")); - processBuilder.inheritIO(); - winProcess = processBuilder.start(); - logger.info(() -> "WinAppDriver started..."); + stopAppiumService(); } - private void killWinAppDriver() { - winProcess.destroy(); - logger.info(() -> "WinAppDriver killed..."); - } - - @SneakyThrows - @Override - public URL getServiceUrl() { - String serviceUrl = ConfigFactory.getConfig().getWindows().get("serviceUrl"); - return new URL(serviceUrl); - } } diff --git a/selcukes-core/src/main/java/io/github/selcukes/core/driver/DesktopOptions.java b/selcukes-core/src/main/java/io/github/selcukes/core/driver/DesktopOptions.java index 12f80964f..5490b289a 100644 --- a/selcukes-core/src/main/java/io/github/selcukes/core/driver/DesktopOptions.java +++ b/selcukes-core/src/main/java/io/github/selcukes/core/driver/DesktopOptions.java @@ -16,37 +16,51 @@ package io.github.selcukes.core.driver; -import io.github.selcukes.commons.config.ConfigFactory; -import lombok.SneakyThrows; import lombok.experimental.UtilityClass; import org.openqa.selenium.Capabilities; import org.openqa.selenium.MutableCapabilities; import java.net.URL; - -import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME; +import java.util.Map; @UtilityClass public class DesktopOptions { + URL serviceUrl; + Capabilities caps; - @SneakyThrows - public static URL getServiceUrl() { - String serviceUrl = ConfigFactory.getConfig().getWindows().get("serviceUrl"); - return new URL(serviceUrl); + public URL getServiceUrl() { + return serviceUrl; } - public static Capabilities setAppTopLevelWindow(String windowId) { - MutableCapabilities capabilities = new MutableCapabilities(); - capabilities.setCapability("appTopLevelWindow", windowId); - return capabilities; + public void setServiceUrl(URL url) { + serviceUrl = url; + } + + public Capabilities setAppTopLevelWindow(String windowId) { + return setCapability("appTopLevelWindow", windowId); + } + + public MutableCapabilities getWinAppOptions(String app) { + return new MutableCapabilities(Map.of("platformName", "Windows", + "deviceName", "WindowsPC", "app", app)); } - public static MutableCapabilities setCapabilities(String app) { + public MutableCapabilities getAndroidOptions(String app) { + return setCapability("app", app); + } + + public MutableCapabilities setCapability(String capabilityName, String value) { MutableCapabilities capabilities = new MutableCapabilities(); - capabilities.setCapability(PLATFORM_NAME, "Windows"); - capabilities.setCapability("deviceName", "WindowsPC"); - capabilities.setCapability("app", app); + capabilities.setCapability(capabilityName, value); return capabilities; } + public void setUserOptions(Capabilities capabilities) { + caps = capabilities; + } + + public Capabilities getUserOptions() { + return caps; + } + } diff --git a/selcukes-core/src/main/java/io/github/selcukes/core/driver/DriverFactory.java b/selcukes-core/src/main/java/io/github/selcukes/core/driver/DriverFactory.java index 1865cfa2a..9dd34b04f 100644 --- a/selcukes-core/src/main/java/io/github/selcukes/core/driver/DriverFactory.java +++ b/selcukes-core/src/main/java/io/github/selcukes/core/driver/DriverFactory.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; public final class DriverFactory { @@ -28,7 +29,8 @@ public final class DriverFactory { private static final List STORED_DRIVER = new ArrayList<>(); static { - Runtime.getRuntime().addShutdownHook(new Thread(() -> STORED_DRIVER.forEach(d -> ((RemoteWebDriver) d).quit()))); + Runtime.getRuntime().addShutdownHook(new Thread(() -> STORED_DRIVER.stream() + .filter(Objects::nonNull).forEach(d -> ((RemoteWebDriver) d).quit()))); } private DriverFactory() { 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 e1c8ed7a2..91e9471bb 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 @@ -20,17 +20,20 @@ import io.github.selcukes.commons.logging.Logger; import io.github.selcukes.commons.logging.LoggerFactory; import io.github.selcukes.core.enums.DeviceType; +import org.openqa.selenium.Capabilities; import org.openqa.selenium.remote.RemoteWebDriver; +import java.util.Arrays; + public class DriverManager { private final Logger logger = LoggerFactory.getLogger(DriverManager.class); private RemoteManager remoteManager; - public D createDriver(DeviceType deviceType) { - + public D createDriver(DeviceType deviceType, Capabilities... capabilities) { + Arrays.stream(capabilities).findAny().ifPresent(DesktopOptions::setUserOptions); if (DriverFactory.getDriver() == null) { - logger.info(() -> "Creating new session..." + deviceType); + logger.info(() -> String.format("Creating new %s session...", deviceType)); switch (deviceType) { case BROWSER: remoteManager = new WebManager(); @@ -41,7 +44,7 @@ public D createDriver(DeviceType deviceType) { DriverFactory.setDriver(remoteManager.createDriver()); break; case MOBILE: - remoteManager = new MobileManager(); + remoteManager = new AppiumManager(); DriverFactory.setDriver(remoteManager.createDriver()); break; default: diff --git a/selcukes-core/src/main/java/io/github/selcukes/core/driver/RemoteManager.java b/selcukes-core/src/main/java/io/github/selcukes/core/driver/RemoteManager.java index d7b7adeaa..07c015d5b 100644 --- a/selcukes-core/src/main/java/io/github/selcukes/core/driver/RemoteManager.java +++ b/selcukes-core/src/main/java/io/github/selcukes/core/driver/RemoteManager.java @@ -16,12 +16,8 @@ package io.github.selcukes.core.driver; -import java.net.URL; - public interface RemoteManager { Object createDriver(); - void destroyDriver(); - URL getServiceUrl(); } diff --git a/selcukes-core/src/main/java/io/github/selcukes/core/driver/WebManager.java b/selcukes-core/src/main/java/io/github/selcukes/core/driver/WebManager.java index 8e5ca7c39..e106bdeab 100644 --- a/selcukes-core/src/main/java/io/github/selcukes/core/driver/WebManager.java +++ b/selcukes-core/src/main/java/io/github/selcukes/core/driver/WebManager.java @@ -39,10 +39,11 @@ public synchronized WebDriver createDriver() { if (null == driver) { try { logger.info(() -> "Initiating New Browser Session..."); - - BrowserOptions browserOptions = new BrowserOptions(); - Capabilities capabilities = browserOptions.getBrowserOptions(DriverType.valueOf(browser)); - + Capabilities capabilities = DesktopOptions.getUserOptions(); + if (capabilities == null) { + BrowserOptions browserOptions = new BrowserOptions(); + capabilities = browserOptions.getBrowserOptions(DriverType.valueOf(browser)); + } RemoteWebDriverBuilder webDriverBuilder = RemoteWebDriver.builder().oneOf(capabilities); if (ConfigFactory.getConfig().getWeb().get("remote").equalsIgnoreCase("true")) { Main.main(new String[]{"standalone", "--port", "4444"}); @@ -63,7 +64,6 @@ public void destroyDriver() { } @SneakyThrows - @Override public URL getServiceUrl() { String serviceUrl = ConfigFactory.getConfig().getWeb().get("serviceUrl"); return new URL(serviceUrl); 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 c748cf5e2..ddc8aeefc 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 @@ -16,17 +16,29 @@ package io.github.selcukes.core.page; +import io.github.selcukes.core.listener.EventCapture; +import io.github.selcukes.core.wait.WaitCondition; import org.openqa.selenium.*; import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.events.EventFiringDecorator; +import org.openqa.selenium.support.events.WebDriverListener; import org.openqa.selenium.support.ui.WebDriverWait; import java.time.Duration; import java.util.ArrayList; import java.util.List; +import java.util.function.Function; public interface Page { + int TIMEOUT = 2; + WebDriver getDriver(); + default WebDriver enableDriverEvents() { + WebDriverListener eventCapture = new EventCapture(); + return new EventFiringDecorator(eventCapture).decorate(getDriver()); + } + default Page open(String url) { getDriver().get(url); return this; @@ -46,12 +58,17 @@ default String read(By by) { } default Page write(By by, CharSequence text) { - find(by).sendKeys(text); + find(by, WaitCondition.VISIBLE).sendKeys(text); return this; } default Page click(By by) { - find(by).click(); + click(by, WaitCondition.CLICKABLE); + return this; + } + + default Page click(By by, final WaitCondition condition) { + find(by, condition).click(); return this; } @@ -83,9 +100,11 @@ default Page switchWindow(int index) { getDriver().switchTo().window(getWindows().get(index)); return this; } + default void openNewBrowserWindow() { getDriver().switchTo().newWindow(WindowType.WINDOW); } + default void openNewBrowserTab() { getDriver().switchTo().newWindow(WindowType.TAB); } @@ -117,12 +136,32 @@ default List findAll(By by) { return getDriver().findElements(by); } + default WebElement find(By by, final WaitCondition condition) { + return waitFor(by, "", condition); + } + + default List findAll(By by, final WaitCondition condition) { + return waitFor(by, "", condition); + } + default Object executeScript(String script, Object... args) { JavascriptExecutor exe = (JavascriptExecutor) getDriver(); return exe.executeScript(script, args); } default WebDriverWait getWait() { - return new WebDriverWait(getDriver(), Duration.ofSeconds(5)); + return getWait(TIMEOUT); + } + + default WebDriverWait getWait(int seconds) { + return new WebDriverWait(getDriver(), Duration.ofSeconds(seconds)); + } + + @SuppressWarnings("unchecked") + default R waitFor(final T locator, final V arg, final WaitCondition condition) { + return (R) getWait() + .pollingEvery(Duration.ofMillis(100)) + .ignoreAll(List.of(StaleElementReferenceException.class, NoSuchElementException.class)) + .until((Function) condition.getType().apply(locator, arg)); } } diff --git a/selcukes-core/src/main/java/io/github/selcukes/core/page/WebPage.java b/selcukes-core/src/main/java/io/github/selcukes/core/page/WebPage.java index 5a0e9d09b..8a7094e59 100644 --- a/selcukes-core/src/main/java/io/github/selcukes/core/page/WebPage.java +++ b/selcukes-core/src/main/java/io/github/selcukes/core/page/WebPage.java @@ -17,13 +17,10 @@ package io.github.selcukes.core.page; import io.github.selcukes.commons.helper.FileHelper; -import io.github.selcukes.core.listener.EventCapture; import org.openqa.selenium.Pdf; import org.openqa.selenium.PrintsPage; import org.openqa.selenium.WebDriver; import org.openqa.selenium.print.PrintOptions; -import org.openqa.selenium.support.events.EventFiringDecorator; -import org.openqa.selenium.support.events.WebDriverListener; import org.testng.Assert; public class WebPage extends WebAuthenticator implements Page { @@ -39,11 +36,6 @@ public WebDriver getDriver() { return driver; } - public void enableDriverEvents() { - WebDriverListener eventCapture = new EventCapture(); - driver = new EventFiringDecorator(eventCapture).decorate(driver); - } - public void printPage(String filePath) { PrintsPage pg = (PrintsPage) driver; PrintOptions printOptions = new PrintOptions(); diff --git a/selcukes-core/src/main/java/io/github/selcukes/core/page/WinPage.java b/selcukes-core/src/main/java/io/github/selcukes/core/page/WinPage.java index 9b0b5f412..db6104fdc 100644 --- a/selcukes-core/src/main/java/io/github/selcukes/core/page/WinPage.java +++ b/selcukes-core/src/main/java/io/github/selcukes/core/page/WinPage.java @@ -18,14 +18,12 @@ import io.appium.java_client.AppiumBy; import io.appium.java_client.windows.WindowsDriver; +import io.github.selcukes.core.driver.DesktopOptions; import lombok.CustomLog; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -import static io.github.selcukes.core.driver.DesktopOptions.getServiceUrl; -import static io.github.selcukes.core.driver.DesktopOptions.setAppTopLevelWindow; - @CustomLog public class WinPage implements Page { private WindowsDriver driver; @@ -52,7 +50,7 @@ public Page switchWindow(String name) { String windowId = newWindowElement.getAttribute("NativeWindowHandle"); String windowIdToHex = Integer.toHexString(Integer.parseInt(windowId)); logger.info(() -> "Window Id: " + windowId + "After: " + windowIdToHex); - driver = new WindowsDriver(getServiceUrl(), setAppTopLevelWindow(windowIdToHex)); + driver = new WindowsDriver(DesktopOptions.getServiceUrl(), DesktopOptions.setAppTopLevelWindow(windowIdToHex)); driver.switchTo().activeElement(); return this; } diff --git a/selcukes-core/src/main/java/io/github/selcukes/core/wait/WaitCondition.java b/selcukes-core/src/main/java/io/github/selcukes/core/wait/WaitCondition.java new file mode 100644 index 000000000..9d48c3c80 --- /dev/null +++ b/selcukes-core/src/main/java/io/github/selcukes/core/wait/WaitCondition.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) Ramesh Babu Prudhvi. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.github.selcukes.core.wait; + +import lombok.RequiredArgsConstructor; +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import java.util.function.BiFunction; +import java.util.function.Function; + +@RequiredArgsConstructor +public enum WaitCondition { + VISIBLE(ExpectedConditions::visibilityOfElementLocated), + INVISIBLE(ExpectedConditions::invisibilityOfElementLocated), + CLICKABLE((Function>) ExpectedConditions::elementToBeClickable), + PRESENT(ExpectedConditions::presenceOfElementLocated), + ALL_VISIBLE(ExpectedConditions::visibilityOfAllElementsLocatedBy), + ALL_PRESENT(ExpectedConditions::presenceOfAllElementsLocatedBy), + TEXT_TO_BE((BiFunction>) ExpectedConditions::textToBe); + private final BiFunction> type; + + WaitCondition(final Function> type) { + this((T arg1, V arg2) -> type.apply(arg1)); + } + + @SuppressWarnings("unchecked") + public BiFunction getType() { + return (BiFunction) type; + } +} \ No newline at end of file diff --git a/selcukes-core/src/main/resources/ApiDemos-debug.apk b/selcukes-core/src/main/resources/ApiDemos-debug.apk new file mode 100644 index 000000000..b9be619f3 Binary files /dev/null and b/selcukes-core/src/main/resources/ApiDemos-debug.apk differ diff --git a/selcukes-core/src/main/resources/selcukes.yaml b/selcukes-core/src/main/resources/selcukes.yaml index f9ee92c95..d9a0f9c38 100644 --- a/selcukes-core/src/main/resources/selcukes.yaml +++ b/selcukes-core/src/main/resources/selcukes.yaml @@ -15,6 +15,7 @@ windows: app: "C:\\Windows\\System32\\notepad.exe" mobile: serviceUrl: "http://127.0.0.1:4723" + app: "ApiDemos-debug.apk" video: recording: false recorderType: FFMPEG diff --git a/selcukes-core/src/test/java/io/github/selcukes/core/tests/EventDriverTest.java b/selcukes-core/src/test/java/io/github/selcukes/core/tests/EventDriverTest.java index b831b5fcb..4806e6b00 100644 --- a/selcukes-core/src/test/java/io/github/selcukes/core/tests/EventDriverTest.java +++ b/selcukes-core/src/test/java/io/github/selcukes/core/tests/EventDriverTest.java @@ -16,20 +16,18 @@ package io.github.selcukes.core.tests; -import io.github.selcukes.commons.Await; import io.github.selcukes.commons.helper.DateHelper; import io.github.selcukes.commons.helper.FileHelper; import lombok.CustomLog; +import lombok.SneakyThrows; import org.apache.commons.io.FileUtils; import org.openqa.selenium.By; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; -import org.openqa.selenium.support.ui.ExpectedConditions; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; import java.io.File; -import java.io.IOException; import java.nio.file.Paths; @CustomLog @@ -41,16 +39,13 @@ public void eventDriverTest() { page.open("https://techyworks.blogspot.com/"); By search = By.xpath("//span[@class='show-search' or @class='show-mobile-search']"); - page.getWait().until( - ExpectedConditions.elementToBeClickable(search) - ); page.click(search); - Await.until(2); page.write(By.xpath("//input[@class='search-input' or @class='mobile-search-input']"), "selenium"); } + @SneakyThrows @AfterMethod - public void afterTest() throws IOException { + public void afterTest() { File srcFile = ((TakesScreenshot) page.getDriver()).getScreenshotAs(OutputType.FILE); File reportDirectory = new File("target/screenshots"); FileHelper.createDirectory(reportDirectory); diff --git a/selcukes-core/src/test/java/io/github/selcukes/core/tests/MobileTest.java b/selcukes-core/src/test/java/io/github/selcukes/core/tests/MobileTest.java index 82cddb491..f110af8f1 100644 --- a/selcukes-core/src/test/java/io/github/selcukes/core/tests/MobileTest.java +++ b/selcukes-core/src/test/java/io/github/selcukes/core/tests/MobileTest.java @@ -20,7 +20,7 @@ import io.github.selcukes.core.driver.DriverManager; import io.github.selcukes.core.enums.DeviceType; import io.github.selcukes.core.page.MobilePage; -import org.testng.Assert; +import org.openqa.selenium.By; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -37,8 +37,8 @@ void beforeTest() { public void remoteTest() { AppiumDriver driver = driverManager.createDriver(DeviceType.MOBILE); MobilePage page = new MobilePage(driver); - page.open("https://www.google.com/"); - Assert.assertEquals(page.title(), "Google"); + page.enableDriverEvents(); + page.click(By.xpath("//android.widget.TextView[contains(@text,'Views')]")); } @AfterTest diff --git a/selcukes-core/src/test/java/io/github/selcukes/core/tests/NotepadTest.java b/selcukes-core/src/test/java/io/github/selcukes/core/tests/NotepadTest.java index b8cb84132..98a29333a 100644 --- a/selcukes-core/src/test/java/io/github/selcukes/core/tests/NotepadTest.java +++ b/selcukes-core/src/test/java/io/github/selcukes/core/tests/NotepadTest.java @@ -37,6 +37,7 @@ public void beforeTest() { public void notepadTest() { WindowsDriver driver = driverManager.createDriver(DeviceType.DESKTOP); WinPage page = new WinPage(driver); + page.enableDriverEvents(); page.write(By.className("Edit"), "This is sample"); } diff --git a/selcukes-core/src/test/java/io/github/selcukes/core/tests/WebAuthTest.java b/selcukes-core/src/test/java/io/github/selcukes/core/tests/WebAuthTest.java index 4827319e0..d534bcbbf 100644 --- a/selcukes-core/src/test/java/io/github/selcukes/core/tests/WebAuthTest.java +++ b/selcukes-core/src/test/java/io/github/selcukes/core/tests/WebAuthTest.java @@ -16,13 +16,13 @@ package io.github.selcukes.core.tests; +import io.github.selcukes.core.wait.WaitCondition; import lombok.CustomLog; import org.openqa.selenium.By; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.annotations.Test; -import java.time.Duration; import java.util.UUID; @CustomLog @@ -34,16 +34,15 @@ public void testVirtualAuth() { page.addVirtualAuthenticator(); String randomId = UUID.randomUUID().toString(); - logger.info(() -> "Username:" + randomId); - page.write(By.id("input-email"),randomId); + logger.info(() -> "Username: " + randomId); + page.write(By.id("input-email"), randomId); page.click(By.id("register-button")); - WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20)); + WebDriverWait wait = page.getWait(20); wait.until(ExpectedConditions.textToBePresentInElementLocated( By.className("popover-body"), "Success! Now try logging in")); page.click(By.id("login-button")); - wait.until(ExpectedConditions.textToBePresentInElementLocated( - By.className("main-content"), "You're logged in!")); + page.waitFor(By.xpath("//*[contains(@class,'main-content')]//h3"), "You're logged in!", WaitCondition.TEXT_TO_BE); page.removeVirtualAuthenticator(); }