diff --git a/.github/workflows/e2eTests.yml b/.github/workflows/e2eTests.yml index 4086d93df4b..3d4cf302cc1 100644 --- a/.github/workflows/e2eTests.yml +++ b/.github/workflows/e2eTests.yml @@ -8,7 +8,7 @@ on: workflow_dispatch: env: - GLOBAL_TESTING_SCOPE: "!%regex[.*Tests_Api.*], !%regex[.*NetworkInterceptionTest.*], !%regex[.*DatabaseTests.*], !%regex[.*MobileEmulation.*], !%regex[.*Healenium.*], !%regex[.*Release.*], !%regex[.*checksum.*], !%regex[.*cucumber.*], !%regex[.*ikuli.*], !%regex[.*Comparison.*], !%regex[.*FileActions.*], !%regex[.*TerminalActions.*], !%regex[.*Shell.*], !%regex[.*fullPageScreenshotWithHeader.*], !%regex[.*dbConnection.*], !%regex[.*appium.*], !%regex[.*ndroid.*],!%regex[.*obile.*], !%regex[.*ios.*], !%regex[.*IOS.*], !%regex[.*BasicAuthentication.*], !%regex[.*Test_LT*.*], !%regex[.*Tests_Api.*], !%regex[.*tests_restActions.*], !%regex[.*Test_AssertApiResponseEquals.*], !%regex[.*MatchJsonSchemaTests.*]" + GLOBAL_TESTING_SCOPE: "!%regex[.*MultipleBrowserInstancesTest.*], !%regex[.*Tests_Api.*], !%regex[.*NetworkInterceptionTest.*], !%regex[.*DatabaseTests.*], !%regex[.*MobileEmulation.*], !%regex[.*Healenium.*], !%regex[.*Release.*], !%regex[.*checksum.*], !%regex[.*cucumber.*], !%regex[.*ikuli.*], !%regex[.*Comparison.*], !%regex[.*FileActions.*], !%regex[.*TerminalActions.*], !%regex[.*Shell.*], !%regex[.*fullPageScreenshotWithHeader.*], !%regex[.*dbConnection.*], !%regex[.*appium.*], !%regex[.*ndroid.*],!%regex[.*obile.*], !%regex[.*ios.*], !%regex[.*IOS.*], !%regex[.*BasicAuthentication.*], !%regex[.*Test_LT*.*], !%regex[.*Tests_Api.*], !%regex[.*tests_restActions.*], !%regex[.*Test_AssertApiResponseEquals.*], !%regex[.*MatchJsonSchemaTests.*]" jobs: # Ubuntu_Database: @@ -1019,4 +1019,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: LambdaTestDesktopWeb_Summary - path: "execution-summary/ExecutionSummaryReport_*.html" \ No newline at end of file + path: "execution-summary/ExecutionSummaryReport_*.html" diff --git a/src/main/java/com/shaft/driver/internal/DriverFactory/DriverFactoryHelper.java b/src/main/java/com/shaft/driver/internal/DriverFactory/DriverFactoryHelper.java index b9c54041325..5d71aa52e8e 100644 --- a/src/main/java/com/shaft/driver/internal/DriverFactory/DriverFactoryHelper.java +++ b/src/main/java/com/shaft/driver/internal/DriverFactory/DriverFactoryHelper.java @@ -383,8 +383,8 @@ private static int attemptRemoteServerPing() { } @SneakyThrows({java.net.MalformedURLException.class, InterruptedException.class}) - private static RemoteWebDriver attemptRemoteServerConnection(Capabilities capabilities) { - RemoteWebDriver driver = null; + private static WebDriver attemptRemoteServerConnection(Capabilities capabilities) { + WebDriver driver = null; boolean isRemoteConnectionEstablished = false; var startTime = System.currentTimeMillis(); var exception = ""; @@ -416,7 +416,7 @@ private static RemoteWebDriver attemptRemoteServerConnection(Capabilities capabi return driver; } - private static RemoteWebDriver connectToRemoteServer(Capabilities capabilities, boolean isLegacy) throws MalformedURLException, URISyntaxException { + private static WebDriver connectToRemoteServer(Capabilities capabilities, boolean isLegacy) throws MalformedURLException, URISyntaxException { var targetHubUrl = isLegacy ? TARGET_HUB_URL + "wd/hub" : TARGET_HUB_URL; var targetLambdaTestHubURL = targetHubUrl.replace("http", "https"); var targetPlatform = Properties.platform.targetPlatform(); @@ -444,9 +444,15 @@ private static RemoteWebDriver connectToRemoteServer(Capabilities capabilities, } } else { if (SHAFT.Properties.platform.executionAddress().contains("lambdatest")) { - return new RemoteWebDriver(new URI(targetLambdaTestHubURL).toURL(), capabilities); + return new RemoteWebDriver(new URI(targetLambdaTestHubURL).toURL(), capabilities, false); } else { - return new RemoteWebDriver(new URI(targetHubUrl).toURL(), capabilities); + // ToDo: Upgrade to using Augmenter and RemoteWebDriver builder instead of old native implementation +// return RemoteWebDriver.builder().address(new URI(targetHubUrl).toURL()) +// .augmentUsing(new Augmenter()) +// .addAlternative(capabilities) +// .config(ClientConfig.defaultConfig()) +// .build(); + return new RemoteWebDriver(new URI(targetHubUrl).toURL(), capabilities, false); } } } @@ -533,7 +539,6 @@ public void initializeDriver(@NonNull DriverType driverType, MutableCapabilities initializeSystemProperties(); try { var isMobileExecution = Platform.ANDROID.toString().equalsIgnoreCase(SHAFT.Properties.platform.targetPlatform()) || Platform.IOS.toString().equalsIgnoreCase(SHAFT.Properties.platform.targetPlatform()); - if (isMobileExecution) { //mobile execution if (isMobileWebExecution()) { diff --git a/src/main/java/com/shaft/driver/internal/DriverFactory/OptionsManager.java b/src/main/java/com/shaft/driver/internal/DriverFactory/OptionsManager.java index 92452f74f26..81b9d9743d7 100644 --- a/src/main/java/com/shaft/driver/internal/DriverFactory/OptionsManager.java +++ b/src/main/java/com/shaft/driver/internal/DriverFactory/OptionsManager.java @@ -85,7 +85,7 @@ protected void setDriverOptions(DriverFactory.DriverType driverType, MutableCapa ffOptions.setProxy(proxy); } // Enable BiDi - ffOptions.setCapability("webSocketUrl", true); + ffOptions.setCapability("webSocketUrl", SHAFT.Properties.platform.enableBiDi()); //merge customWebDriverCapabilities.properties ffOptions = ffOptions.merge(PropertyFileManager.getCustomWebDriverDesiredCapabilities()); //merge hardcoded custom options @@ -237,7 +237,8 @@ protected void initializeMobileDesiredCapabilities() { @SuppressWarnings("SpellCheckingInspection") private ChromiumOptions setupChromiumOptions(ChromiumOptions options, MutableCapabilities customDriverOptions) { - if (!SHAFT.Properties.platform.executionAddress().equalsIgnoreCase("local")) + String executionAddress = SHAFT.Properties.platform.executionAddress().toLowerCase(); + if (!executionAddress.equalsIgnoreCase("local")) options.setCapability(CapabilityType.PLATFORM_NAME, Properties.platform.targetPlatform()); if (SHAFT.Properties.web.headlessExecution()) { options.addArguments("--headless=new"); @@ -305,7 +306,7 @@ private ChromiumOptions setupChromiumOptions(ChromiumOptions options, Muta options.setExperimentalOption("mobileEmulation", mobileEmulation); } // Enable BiDi - options.setCapability("webSocketUrl", true); + options.setCapability("webSocketUrl", SHAFT.Properties.platform.enableBiDi()); //merge customWebdriverCapabilities.properties options = (ChromiumOptions) options.merge(PropertyFileManager.getCustomWebDriverDesiredCapabilities()); //merge hardcoded custom options diff --git a/src/main/java/com/shaft/properties/internal/Platform.java b/src/main/java/com/shaft/properties/internal/Platform.java index 16ceb8c3b39..d5b587ace83 100644 --- a/src/main/java/com/shaft/properties/internal/Platform.java +++ b/src/main/java/com/shaft/properties/internal/Platform.java @@ -34,6 +34,10 @@ public interface Platform extends EngineProperties { @DefaultValue("true") boolean jvmProxySettings(); + @Key("enableBiDi") + @DefaultValue("true") + boolean enableBiDi(); + private static void setProperty(String key, String value) { var updatedProps = new java.util.Properties(); updatedProps.setProperty(key, value); @@ -81,5 +85,10 @@ public SetProperty jvmProxySettings(boolean value) { setProperty("jvmProxySettings", String.valueOf(value)); return this; } + + public SetProperty enableBiDi(boolean value) { + setProperty("enableBiDi", String.valueOf(value)); + return this; + } } } diff --git a/src/test/java/junitTestPackage/MoonTests.java b/src/test/java/junitTestPackage/MoonTests.java new file mode 100644 index 00000000000..e339830dbda --- /dev/null +++ b/src/test/java/junitTestPackage/MoonTests.java @@ -0,0 +1,79 @@ +package junitTestPackage; + +import com.shaft.driver.SHAFT; +import com.shaft.tools.io.ReportManager; +import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.devtools.DevTools; +import org.openqa.selenium.devtools.HasDevTools; +import org.openqa.selenium.remote.Augmenter; +import poms.GoogleSearch; + +import java.util.ArrayList; +import java.util.HashMap; + +import static com.shaft.driver.DriverFactory.DriverType.CHROME; + +public class MoonTests { + private SHAFT.GUI.WebDriver driver; + + // @BeforeAll + public static void beforeAll() { + SHAFT.Properties.platform.set().executionAddress("http://moon.aerokube.local/wd/hub"); + SHAFT.Properties.web.set().headlessExecution(true); + SHAFT.Properties.timeouts.set().remoteServerInstanceCreationTimeout(1); + SHAFT.Properties.platform.set().enableBiDi(false); + } + + private static ChromeOptions getMoonCapabilities(String testName) { + var options = new ChromeOptions(); + options.setCapability("moon:options", new HashMap() {{ + /* How to add test badge */ + put("name", testName); + + /* How to set session timeout */ + put("sessionTimeout", "15m"); + + /* How to set timezone */ + put("env", new ArrayList() {{ + add("TZ=UTC"); + }}); + + /* How to add "trash" button */ + put("labels", new HashMap() {{ + put("manual", "true"); + }}); + + /* How to enable video recording */ + put("enableVideo", true); + }}); + return options; + } + + // @Test + public void regularDriver() { + var searchPage = new GoogleSearch(driver.getDriver()); + searchPage.navigateToURL(); + searchPage.assertPageIsOpen(); + } + + // @Test + public void augmentedDriver() { + var nativeDriver = driver.getDriver(); + nativeDriver = new Augmenter().augment(driver.getDriver()); + DevTools devTools = ((HasDevTools) nativeDriver).getDevTools(); + ReportManager.logDiscrete(devTools.getDomains().toString()); + var searchPage = new GoogleSearch(nativeDriver); + searchPage.navigateToURL(); + searchPage.assertPageIsOpen(); + } + + // @BeforeEach + public void beforeMethod() { + driver = new SHAFT.GUI.WebDriver(CHROME, getMoonCapabilities("test")); + } + + // @AfterEach + public void afterMethod() { + driver.quit(); + } +} diff --git a/src/test/java/testPackage/mockedTests/MultipleBrowserInstancesTest.java b/src/test/java/testPackage/mockedTests/MultipleBrowserInstancesTest.java new file mode 100644 index 00000000000..0f49f0c5ffd --- /dev/null +++ b/src/test/java/testPackage/mockedTests/MultipleBrowserInstancesTest.java @@ -0,0 +1,35 @@ +package testPackage.mockedTests; + +import com.shaft.driver.SHAFT; +import org.openqa.selenium.By; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.Test; + +import java.util.ArrayList; + +public class MultipleBrowserInstancesTest { + ArrayList drivers = new ArrayList<>(); + String testElement = "data:text/html,

"; + By locator = SHAFT.GUI.Locator.hasTagName("input").build(); + + @Test + public void multipleInstancesSwitching() { + drivers.add(new SHAFT.GUI.WebDriver()); + drivers.get(0).browser().navigateToURL(testElement) + .and().element().type(locator, "first string"); + + drivers.add(new SHAFT.GUI.WebDriver()); + drivers.get(1).browser().navigateToURL(testElement) + .and().element().type(locator, "second string"); + + drivers.get(0).element().assertThat(locator).text().isEqualTo("first string") + .perform(); + drivers.get(1).element().assertThat(locator).text().isEqualTo("second string") + .perform(); + } + + @AfterMethod(alwaysRun = true) + public void afterMethod() { + drivers.forEach(SHAFT.GUI.WebDriver::quit); + } +} diff --git a/src/test/java/testPackage/properties/PlatformTests.java b/src/test/java/testPackage/properties/PlatformTests.java index 97df881e269..8e20f1c5cd6 100644 --- a/src/test/java/testPackage/properties/PlatformTests.java +++ b/src/test/java/testPackage/properties/PlatformTests.java @@ -11,6 +11,7 @@ public class PlatformTests { String proxy; Boolean driverProxy; Boolean jvmProxy; + Boolean enableBiDi; @BeforeClass public void beforeClass() { @@ -20,6 +21,7 @@ public void beforeClass() { proxy = SHAFT.Properties.platform.proxy(); driverProxy = SHAFT.Properties.platform.driverProxySettings(); jvmProxy = SHAFT.Properties.platform.jvmProxySettings(); + enableBiDi = SHAFT.Properties.platform.enableBiDi(); } @Test @@ -30,5 +32,6 @@ public void test() { SHAFT.Properties.platform.set().proxySettings(proxy); SHAFT.Properties.platform.set().driverProxySettings(driverProxy); SHAFT.Properties.platform.set().jvmProxySettings(jvmProxy); + SHAFT.Properties.platform.set().enableBiDi(enableBiDi); } }