diff --git a/.github/workflows/e2eTests.yml b/.github/workflows/e2eTests.yml index f00dfc20844..7d39bad7be3 100644 --- a/.github/workflows/e2eTests.yml +++ b/.github/workflows/e2eTests.yml @@ -73,7 +73,7 @@ jobs: maven-version: 3.9.5 - name: Run tests continue-on-error: true - run: mvn -e test "-DdefaultElementIdentificationTimeout=5" "-DretryMaximumNumberOfAttempts=2" "-DexecutionAddress=local" "-DtargetOperatingSystem=MAC" "-DtargetBrowserName=SAFARI" "-DgenerateAllureReportArchive=true" "-Dtest=${GLOBAL_TESTING_SCOPE}" + run: mvn -e test "-DdefaultElementIdentificationTimeout=5" "-DretryMaximumNumberOfAttempts=2" "-DexecutionAddress=local" "-DtargetOperatingSystem=MAC" "-DtargetBrowserName=safari" "-DgenerateAllureReportArchive=true" "-Dtest=${GLOBAL_TESTING_SCOPE}" - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 with: @@ -378,7 +378,7 @@ jobs: maven-version: 3.9.5 - name: Run tests continue-on-error: true - run: mvn -e test "-DdefaultElementIdentificationTimeout=60" "-DretryMaximumNumberOfAttempts=2" "-DexecutionAddress=browserstack" "-DtargetOperatingSystem=ANDROID" "-Dmobile_automationName=UIAutomator2" "-DbrowserStack.platformVersion=13.0" "-DbrowserStack.deviceName=Google Pixel 7" "-DbrowserStack.appName=ApiDemos-debug.apk" "-DbrowserStack.appRelativeFilePath=src/test/resources/testDataFiles/apps/ApiDemos-debug.apk" "-DbrowserStack.appUrl=" "-DgenerateAllureReportArchive=true" "-Dtest=%regex[.*ndroidBasic.*]" + run: mvn -e test "-DdefaultElementIdentificationTimeout=60" "-DretryMaximumNumberOfAttempts=2" "-DexecutionAddress=browserstack" "-DtargetOperatingSystem=android" "-Dmobile_automationName=UIAutomator2" "-DbrowserStack.platformVersion=13.0" "-DbrowserStack.deviceName=Google Pixel 7" "-DbrowserStack.appName=ApiDemos-debug.apk" "-DbrowserStack.appRelativeFilePath=src/test/resources/testDataFiles/apps/ApiDemos-debug.apk" "-DbrowserStack.appUrl=" "-DgenerateAllureReportArchive=true" "-Dtest=%regex[.*ndroidBasic.*]" - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 with: @@ -415,7 +415,7 @@ jobs: maven-version: 3.9.5 - name: Run tests continue-on-error: true - run: mvn -e test "-DdefaultElementIdentificationTimeout=5" "-DretryMaximumNumberOfAttempts=1" "-DexecutionAddress=browserstack" "-DtargetOperatingSystem=IOS" "-Dmobile_automationName=XCuiTest" "-DbrowserStack.osVersion=16" "-DbrowserStack.deviceName=iPhone 14" "-Dmobile_browserName=SAFARI" "-DbrowserStack.appName=" "-DbrowserStack.appRelativeFilePath=" "-DbrowserStack.appUrl=" "-DgenerateAllureReportArchive=true" "-Dtest=%regex[.*MobileWebTest.*]" + run: mvn -e test "-DdefaultElementIdentificationTimeout=5" "-DretryMaximumNumberOfAttempts=1" "-DexecutionAddress=browserstack" "-DtargetOperatingSystem=iOS" "-Dmobile_automationName=XCuiTest" "-DbrowserStack.osVersion=16" "-DbrowserStack.deviceName=iPhone 14" "-Dmobile_browserName=safari" "-DbrowserStack.appName=" "-DbrowserStack.appRelativeFilePath=" "-DbrowserStack.appUrl=" "-DgenerateAllureReportArchive=true" "-Dtest=%regex[.*MobileWebTest.*]" - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 with: @@ -452,7 +452,7 @@ jobs: maven-version: 3.9.5 - name: Run tests continue-on-error: true - run: mvn -e test "-DdefaultElementIdentificationTimeout=5" "-DretryMaximumNumberOfAttempts=1" "-DexecutionAddress=browserstack" "-DtargetOperatingSystem=ANDROID" "-Dmobile_automationName=UIAutomator2" "-DbrowserStack.osVersion=13.0" "-DbrowserStack.deviceName=Samsung Galaxy S23" "-Dmobile_browserName=CHROME" "-DbrowserStack.appName=" "-DbrowserStack.appRelativeFilePath=" "-DbrowserStack.appUrl=" "-DgenerateAllureReportArchive=true" "-Dtest=%regex[.*MobileWebTest.*]" + run: mvn -e test "-DdefaultElementIdentificationTimeout=5" "-DretryMaximumNumberOfAttempts=1" "-DexecutionAddress=browserstack" "-DtargetOperatingSystem=android" "-Dmobile_automationName=UIAutomator2" "-DbrowserStack.osVersion=13.0" "-DbrowserStack.deviceName=Samsung Galaxy S23" "-Dmobile_browserName=chrome" "-DbrowserStack.appName=" "-DbrowserStack.appRelativeFilePath=" "-DbrowserStack.appUrl=" "-DgenerateAllureReportArchive=true" "-Dtest=%regex[.*MobileWebTest.*]" - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 with: @@ -489,7 +489,7 @@ jobs: maven-version: 3.9.5 - name: Run tests continue-on-error: true - run: mvn -e test "-DdefaultElementIdentificationTimeout=5" "-DretryMaximumNumberOfAttempts=1" "-DexecutionAddress=browserstack" "-DtargetOperatingSystem=ANDROID" "-Dmobile_automationName=UIAutomator2" "-DbrowserStack.osVersion=13.0" "-DbrowserStack.deviceName=Samsung Galaxy S23" "-Dmobile_browserName=samsung" "-DbrowserStack.appName=" "-DbrowserStack.appRelativeFilePath=" "-DbrowserStack.appUrl=" "-DgenerateAllureReportArchive=true" "-Dtest=%regex[.*MobileWebTest.*]" + run: mvn -e test "-DdefaultElementIdentificationTimeout=5" "-DretryMaximumNumberOfAttempts=1" "-DexecutionAddress=browserstack" "-DtargetOperatingSystem=android" "-Dmobile_automationName=UIAutomator2" "-DbrowserStack.osVersion=13.0" "-DbrowserStack.deviceName=Samsung Galaxy S23" "-Dmobile_browserName=samsung" "-DbrowserStack.appName=" "-DbrowserStack.appRelativeFilePath=" "-DbrowserStack.appUrl=" "-DgenerateAllureReportArchive=true" "-Dtest=%regex[.*MobileWebTest.*]" - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 with: diff --git a/pom.xml b/pom.xml index cc44a337053..3390288041f 100644 --- a/pom.xml +++ b/pom.xml @@ -107,7 +107,7 @@ org.seleniumhq.selenium selenium-java - 4.22.0 + 4.23.0 diff --git a/src/main/java/com/shaft/driver/internal/DriverFactory/SynchronizationManager.java b/src/main/java/com/shaft/driver/internal/DriverFactory/SynchronizationManager.java index 382ea51727c..5a720abc074 100644 --- a/src/main/java/com/shaft/driver/internal/DriverFactory/SynchronizationManager.java +++ b/src/main/java/com/shaft/driver/internal/DriverFactory/SynchronizationManager.java @@ -4,7 +4,6 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.Browser; import org.openqa.selenium.support.ui.FluentWait; -import org.openqa.selenium.support.ui.Wait; import java.time.Duration; import java.util.ArrayList; @@ -18,11 +17,11 @@ public SynchronizationManager(WebDriver driver) { this.driver = driver; } - public Wait fluentWait() { + public FluentWait fluentWait() { return fluentWait(false); } - public Wait fluentWait(boolean isValidToCheckForVisibility) { + public FluentWait fluentWait(boolean isValidToCheckForVisibility) { return new FluentWait<>(driver) .withTimeout(Duration.ofSeconds((long) (SHAFT.Properties.timeouts.defaultElementIdentificationTimeout()))) .pollingEvery(Duration.ofMillis(ELEMENT_IDENTIFICATION_POLLING_DELAY)) diff --git a/src/main/java/com/shaft/gui/element/TouchActions.java b/src/main/java/com/shaft/gui/element/TouchActions.java index 4a18e762971..6e61679e190 100644 --- a/src/main/java/com/shaft/gui/element/TouchActions.java +++ b/src/main/java/com/shaft/gui/element/TouchActions.java @@ -546,6 +546,8 @@ public TouchActions swipeElementIntoView(By scrollableElementLocator, By targetE } } elementActionsHelper.passAction(driverFactoryHelper.getDriver(), targetElementLocator, Thread.currentThread().getStackTrace()[1].getMethodName(), null, null, null); + } catch (UnsupportedCommandException unsupportedCommandException) { + throw unsupportedCommandException; } catch (Exception e) { elementActionsHelper.failAction(driverFactoryHelper.getDriver(), targetElementLocator, e); } @@ -735,13 +737,13 @@ private boolean attemptW3cCompliantActionsScroll(SwipeDirection swipeDirection, scrollParameters.putAll(ImmutableMap.of( "direction", swipeDirection.toString() )); - canScrollMore = (Boolean) ((JavascriptExecutor) androidDriver).executeScript("scrollGesture", scrollParameters); + canScrollMore = (Boolean) androidDriver.executeScript("mobile:scrollGesture", scrollParameters); } else if (driverFactoryHelper.getDriver() instanceof IOSDriver iosDriver) { scrollParameters.putAll(ImmutableMap.of( "direction", swipeDirection.toString() )); //http://appium.github.io/appium-xcuitest-driver/4.16/execute-methods/#mobile-scroll - var ret = ((JavascriptExecutor) iosDriver).executeScript("scroll", scrollParameters); + var ret = iosDriver.executeScript("mobile:scroll", scrollParameters); canScrollMore = ret == null || (Boolean) ret; } var logMessageAfter = "Attempted to scroll using these parameters: \"" + scrollParameters + "\""; diff --git a/src/main/java/com/shaft/gui/element/internal/ElementActionsHelper.java b/src/main/java/com/shaft/gui/element/internal/ElementActionsHelper.java index b1be8bd7424..7741b8e21c6 100644 --- a/src/main/java/com/shaft/gui/element/internal/ElementActionsHelper.java +++ b/src/main/java/com/shaft/gui/element/internal/ElementActionsHelper.java @@ -38,6 +38,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicInteger; @SuppressWarnings({"UnusedReturnValue"}) public class ElementActionsHelper { @@ -51,18 +52,18 @@ public ElementActionsHelper(boolean isSilent) { } public int waitForElementPresenceWithReducedTimeout(WebDriver driver, By elementLocator) { - var defaultElementIdentificationTimeout = SHAFT.Properties.timeouts.defaultElementIdentificationTimeout(); - SHAFT.Properties.timeouts.set().defaultElementIdentificationTimeout(0.3); //this is used for faster mobile native scrolling. default for ios is 200 and for android is 250, this covers both - List numberOfFoundElements; + AtomicInteger numberOfFoundElements = new AtomicInteger(); try { - numberOfFoundElements = waitForElementPresence(driver, elementLocator); - } catch (Throwable throwable) { - // in case the element was not found, reset the timeouts - SHAFT.Properties.timeouts.set().defaultElementIdentificationTimeout(defaultElementIdentificationTimeout); - throw throwable; + new SynchronizationManager(driver).fluentWait(true) + .withTimeout(Duration.ofMillis(300)) //this is used for faster mobile native scrolling. default for ios is 200 and for android is 250, this covers both + .until(f -> { + numberOfFoundElements.set(driver.findElements(elementLocator).size()); + return numberOfFoundElements.get() > 0; + }); + } catch (TimeoutException timeoutException) { + return 0; } - SHAFT.Properties.timeouts.set().defaultElementIdentificationTimeout(defaultElementIdentificationTimeout); - return Integer.parseInt(numberOfFoundElements.getFirst().toString()); + return numberOfFoundElements.get(); } public List waitForElementPresence(WebDriver driver, By elementLocator) { diff --git a/src/main/java/com/shaft/validation/internal/ValidationsExecutor.java b/src/main/java/com/shaft/validation/internal/ValidationsExecutor.java index 8b686b433a9..bd2021bd6c0 100644 --- a/src/main/java/com/shaft/validation/internal/ValidationsExecutor.java +++ b/src/main/java/com/shaft/validation/internal/ValidationsExecutor.java @@ -22,7 +22,7 @@ public class ValidationsExecutor { private final String validationMethod; @SuppressWarnings({"FieldCanBeLocal", "unused"}) private String validationCategoryString; - private WebDriver driver; + private final ThreadLocal driver = new ThreadLocal<>(); private By locator; private String customReportMessage = ""; private ValidationEnums.VisualValidationEngine visualValidationEngine; @@ -34,7 +34,7 @@ public class ValidationsExecutor { private boolean condition; private Object actualValue; private ValidationEnums.NumbersComparativeRelation numbersComparativeRelation; - private Object response; + private final ThreadLocal response = new ThreadLocal<>(); private String fileAbsolutePath; private RestActions.ComparisonType restComparisonType; private String jsonPath; @@ -43,7 +43,7 @@ public class ValidationsExecutor { public ValidationsExecutor(WebDriverElementValidationsBuilder webDriverElementValidationsBuilder) { this.validationCategory = webDriverElementValidationsBuilder.validationCategory; - this.driver = webDriverElementValidationsBuilder.driver; + this.driver.set(webDriverElementValidationsBuilder.driver); this.locator = webDriverElementValidationsBuilder.locator; this.validationType = webDriverElementValidationsBuilder.validationType; this.validationMethod = webDriverElementValidationsBuilder.validationMethod; @@ -53,7 +53,7 @@ public ValidationsExecutor(WebDriverElementValidationsBuilder webDriverElementVa public ValidationsExecutor(NativeValidationsBuilder nativeValidationsBuilder) { this.validationCategory = nativeValidationsBuilder.validationCategory; - this.driver = nativeValidationsBuilder.driver; + this.driver.set(nativeValidationsBuilder.driver); this.locator = nativeValidationsBuilder.locator; this.validationType = nativeValidationsBuilder.validationType; this.validationMethod = nativeValidationsBuilder.validationMethod; @@ -64,7 +64,7 @@ public ValidationsExecutor(NativeValidationsBuilder nativeValidationsBuilder) { this.elementCssProperty = nativeValidationsBuilder.elementCssProperty; this.browserAttribute = nativeValidationsBuilder.browserAttribute; - this.response = nativeValidationsBuilder.response; + this.response.set(nativeValidationsBuilder.response); this.jsonPath = nativeValidationsBuilder.jsonPath; this.folderRelativePath = nativeValidationsBuilder.folderRelativePath; @@ -94,7 +94,7 @@ public ValidationsExecutor(NumberValidationsBuilder numberValidationsBuilder) { this.numbersComparativeRelation = numberValidationsBuilder.numbersComparativeRelation; - this.response = numberValidationsBuilder.response; + this.response.set(numberValidationsBuilder.response); this.jsonPath = numberValidationsBuilder.jsonPath; this.reportMessageBuilder = numberValidationsBuilder.reportMessageBuilder; @@ -105,7 +105,7 @@ public ValidationsExecutor(RestValidationsBuilder restValidationsBuilder) { this.validationCategory = restValidationsBuilder.validationCategory; this.validationMethod = restValidationsBuilder.validationMethod; this.validationType = restValidationsBuilder.validationType; - this.response = restValidationsBuilder.response; + this.response.set(restValidationsBuilder.response); this.fileAbsolutePath = restValidationsBuilder.fileAbsolutePath; this.restComparisonType = restValidationsBuilder.restComparisonType; @@ -141,7 +141,7 @@ public void perform() { } protected void internalPerform() { - JavaScriptWaitManager.waitForLazyLoading(driver); + JavaScriptWaitManager.waitForLazyLoading(driver.get()); boolean clearCustomReportMessage = false; if (customReportMessage.isBlank()) { customReportMessage = reportMessageBuilder.toString(); @@ -155,6 +155,8 @@ protected void internalPerform() { } if (Boolean.TRUE.equals(clearCustomReportMessage)) customReportMessage = ""; + driver.remove(); + response.remove(); } @Step(" {this.validationCategoryString} that {this.customReportMessage}") @@ -166,34 +168,34 @@ private void performValidation() { case "conditionIsTrue" -> new ValidationsHelper().validateTrue(validationCategory, condition, validationType, customReportMessage); case "elementExists" -> - new ValidationsHelper2(validationCategory).validateElementExists(driver, locator, validationType); + new ValidationsHelper2(validationCategory).validateElementExists(driver.get(), locator, validationType); case "elementMatches" -> - new ValidationsHelper().validateElementMatches(validationCategory, driver, locator, visualValidationEngine, validationType, customReportMessage); + new ValidationsHelper().validateElementMatches(validationCategory, driver.get(), locator, visualValidationEngine, validationType, customReportMessage); case "elementAttributeEquals" -> - new ValidationsHelper2(validationCategory).validateElementAttribute(driver, locator, elementAttribute, String.valueOf(expectedValue), validationComparisonType, validationType); + new ValidationsHelper2(validationCategory).validateElementAttribute(driver.get(), locator, elementAttribute, String.valueOf(expectedValue), validationComparisonType, validationType); case "elementCssPropertyEquals" -> - new ValidationsHelper2(validationCategory).validateElementCSSProperty(driver, locator, elementCssProperty, String.valueOf(expectedValue), validationComparisonType, validationType); + new ValidationsHelper2(validationCategory).validateElementCSSProperty(driver.get(), locator, elementCssProperty, String.valueOf(expectedValue), validationComparisonType, validationType); case "browserAttributeEquals" -> - new ValidationsHelper2(validationCategory).validateBrowserAttribute(driver, browserAttribute, String.valueOf(expectedValue), validationComparisonType, validationType); + new ValidationsHelper2(validationCategory).validateBrowserAttribute(driver.get(), browserAttribute, String.valueOf(expectedValue), validationComparisonType, validationType); case "comparativeRelationBetweenNumbers" -> new ValidationsHelper2(validationCategory).validateNumber((Number) expectedValue, (Number) actualValue, numbersComparativeRelation, validationType); case "fileExists" -> new ValidationsHelper().validateFileExists(validationCategory, folderRelativePath, fileName, 5, validationType, customReportMessage); case "responseEqualsFileContent" -> - new ValidationsHelper().validateJSONFileContent(validationCategory, (Response) response, fileAbsolutePath, restComparisonType, "", validationType, customReportMessage); + new ValidationsHelper().validateJSONFileContent(validationCategory, (Response) response.get(), fileAbsolutePath, restComparisonType, "", validationType, customReportMessage); case "jsonPathValueEquals" -> - new ValidationsHelper2(validationCategory).validateEquals(expectedValue, RestActions.getResponseJSONValue(response, jsonPath), validationComparisonType, validationType); + new ValidationsHelper2(validationCategory).validateEquals(expectedValue, RestActions.getResponseJSONValue(response.get(), jsonPath), validationComparisonType, validationType); case "jsonPathValueAsListEquals" -> { - for (Object value : Objects.requireNonNull(RestActions.getResponseJSONValueAsList((Response) response, jsonPath))) { + for (Object value : Objects.requireNonNull(RestActions.getResponseJSONValueAsList((Response) response.get(), jsonPath))) { new ValidationsHelper2(validationCategory).validateEquals(expectedValue, value.toString(), validationComparisonType, validationType); } } case "responseBody" -> - new ValidationsHelper2(validationCategory).validateEquals(expectedValue, RestActions.getResponseBody((Response) response), validationComparisonType, validationType); + new ValidationsHelper2(validationCategory).validateEquals(expectedValue, RestActions.getResponseBody((Response) response.get()), validationComparisonType, validationType); case "responseTime" -> - new ValidationsHelper2(validationCategory).validateNumber((Number) expectedValue, RestActions.getResponseTime((Response) response), numbersComparativeRelation, validationType); + new ValidationsHelper2(validationCategory).validateNumber((Number) expectedValue, RestActions.getResponseTime((Response) response.get()), numbersComparativeRelation, validationType); case "checkResponseSchema" -> - new ValidationsHelper().validateResponseFileSchema(validationCategory, (Response) response, fileAbsolutePath, restComparisonType, "", validationType, customReportMessage); + new ValidationsHelper().validateResponseFileSchema(validationCategory, (Response) response.get(), fileAbsolutePath, restComparisonType, "", validationType, customReportMessage); case "fileContent" -> { String fileContent; if (fileName.contains(".pdf")) { diff --git a/src/test/java/testPackage/LambdaTest/Test_LTDesktopWebMac.java b/src/test/java/testPackage/LambdaTest/Test_LTDesktopWebMac.java index 8579c5463b3..0497c101493 100644 --- a/src/test/java/testPackage/LambdaTest/Test_LTDesktopWebMac.java +++ b/src/test/java/testPackage/LambdaTest/Test_LTDesktopWebMac.java @@ -2,6 +2,7 @@ import com.shaft.driver.SHAFT; import org.openqa.selenium.By; +import org.openqa.selenium.Platform; import org.openqa.selenium.remote.Browser; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -28,7 +29,7 @@ public void test_ClickUsingJavaScript() { public void beforeMethod() { testData = new SHAFT.TestData.JSON("credentials.json"); SHAFT.Properties.lambdaTest.set().browserVersion("16.0"); - SHAFT.Properties.platform.set().targetPlatform("MAC"); + SHAFT.Properties.platform.set().targetPlatform(Platform.MAC.name()); SHAFT.Properties.platform.set().executionAddress("lambdatest"); SHAFT.Properties.web.set().targetBrowserName(Browser.SAFARI.browserName()); SHAFT.Properties.mobile.set().browserName(""); diff --git a/src/test/java/testPackage/LambdaTest/Test_LTDesktopWebWindows.java b/src/test/java/testPackage/LambdaTest/Test_LTDesktopWebWindows.java index ed135847d95..5b6b93eded5 100644 --- a/src/test/java/testPackage/LambdaTest/Test_LTDesktopWebWindows.java +++ b/src/test/java/testPackage/LambdaTest/Test_LTDesktopWebWindows.java @@ -2,6 +2,7 @@ import com.shaft.driver.SHAFT; import org.openqa.selenium.By; +import org.openqa.selenium.Platform; import org.openqa.selenium.remote.Browser; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -33,7 +34,7 @@ public void test_ClickUsingJavaScript() { public void beforeMethod() { testData = new SHAFT.TestData.JSON("credentials.json"); SHAFT.Properties.lambdaTest.set().browserVersion("114.0"); - SHAFT.Properties.platform.set().targetPlatform("WINDOWS"); + SHAFT.Properties.platform.set().targetPlatform(Platform.WINDOWS.name()); SHAFT.Properties.platform.set().executionAddress("lambdatest"); SHAFT.Properties.web.set().targetBrowserName(Browser.CHROME.browserName()); SHAFT.Properties.mobile.set().browserName(""); diff --git a/src/test/java/testPackage/LambdaTest/Test_LTWebAppIOS.java b/src/test/java/testPackage/LambdaTest/Test_LTWebAppIOS.java index d00c26cc452..52c9123f9eb 100644 --- a/src/test/java/testPackage/LambdaTest/Test_LTWebAppIOS.java +++ b/src/test/java/testPackage/LambdaTest/Test_LTWebAppIOS.java @@ -2,6 +2,8 @@ import com.shaft.driver.SHAFT; import org.openqa.selenium.By; +import org.openqa.selenium.Platform; +import org.openqa.selenium.remote.Browser; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -32,10 +34,10 @@ public void beforeMethod() { // common attributes SHAFT.Properties.lambdaTest.set().deviceName("iPhone 13 Pro Max"); SHAFT.Properties.lambdaTest.set().platformVersion("15"); - SHAFT.Properties.platform.set().targetPlatform("ios"); + SHAFT.Properties.platform.set().targetPlatform(Platform.IOS.name()); SHAFT.Properties.platform.set().executionAddress("lambdatest"); - SHAFT.Properties.web.set().targetBrowserName("safari"); - SHAFT.Properties.mobile.set().browserName("safari"); + SHAFT.Properties.web.set().targetBrowserName(Browser.SAFARI.browserName()); + SHAFT.Properties.mobile.set().browserName(Browser.SAFARI.browserName()); SHAFT.Properties.lambdaTest.set().selenium_version("4.8.0"); SHAFT.Properties.lambdaTest.set().isRealMobile(true); SHAFT.Properties.lambdaTest.set().username(testData.getTestData("LambdaTestUserName")); diff --git a/src/test/java/testPackage/LambdaTest/Test_LTWebAppRealme.java b/src/test/java/testPackage/LambdaTest/Test_LTWebAppRealme.java index 95beaaa6821..4961ad0fc2e 100644 --- a/src/test/java/testPackage/LambdaTest/Test_LTWebAppRealme.java +++ b/src/test/java/testPackage/LambdaTest/Test_LTWebAppRealme.java @@ -2,6 +2,8 @@ import com.shaft.driver.SHAFT; import org.openqa.selenium.By; +import org.openqa.selenium.Platform; +import org.openqa.selenium.remote.Browser; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -54,10 +56,10 @@ public void beforeMethod() { // common attributes SHAFT.Properties.lambdaTest.set().deviceName("Pixel 7"); SHAFT.Properties.lambdaTest.set().platformVersion("13"); - SHAFT.Properties.platform.set().targetPlatform("Android"); + SHAFT.Properties.platform.set().targetPlatform(Platform.ANDROID.name()); SHAFT.Properties.platform.set().executionAddress("lambdatest"); - SHAFT.Properties.web.set().targetBrowserName("chrome"); - SHAFT.Properties.mobile.set().browserName("chrome"); + SHAFT.Properties.web.set().targetBrowserName(Browser.CHROME.browserName()); + SHAFT.Properties.mobile.set().browserName(Browser.CHROME.browserName()); SHAFT.Properties.lambdaTest.set().selenium_version("4.8.0"); SHAFT.Properties.lambdaTest.set().osVersion("11"); SHAFT.Properties.lambdaTest.set().username(testData.getTestData("LambdaTestUserName")); diff --git a/src/test/java/testPackage/appium/MobileWebTest.java b/src/test/java/testPackage/appium/MobileWebTest.java index 9507aa3d002..a05865afede 100644 --- a/src/test/java/testPackage/appium/MobileWebTest.java +++ b/src/test/java/testPackage/appium/MobileWebTest.java @@ -1,7 +1,10 @@ package testPackage.appium; import com.shaft.driver.SHAFT; +import io.appium.java_client.remote.AutomationName; import org.openqa.selenium.By; +import org.openqa.selenium.Platform; +import org.openqa.selenium.remote.Browser; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; @@ -51,11 +54,11 @@ public void afterMethod() { @BeforeClass public void beforeClass() { // common attributes android -// SHAFT.Properties.platform.set().targetPlatform(Platform.ANDROID.name()); -// SHAFT.Properties.mobile.set().automationName(AutomationName.ANDROID_UIAUTOMATOR2); + SHAFT.Properties.platform.set().targetPlatform(Platform.ANDROID.name()); + SHAFT.Properties.mobile.set().automationName(AutomationName.ANDROID_UIAUTOMATOR2); // common attributes ios -// SHAFT.Properties.platform.set().targetPlatform(Platform.IOS.name()); + SHAFT.Properties.platform.set().targetPlatform(Platform.IOS.name()); // SHAFT.Properties.mobile.set().automationName(AutomationName.IOS_XCUI_TEST); // self-managed execution (android only) [WARNING: WORK IN PROGRESS] @@ -71,15 +74,15 @@ public void beforeClass() { // SHAFT.Properties.mobile.set().app(""); // remote browserstack server (common for web execution) -// SHAFT.Properties.platform.set().executionAddress("browserstack"); -// SHAFT.Properties.browserStack.set().appName(""); -// SHAFT.Properties.browserStack.set().appRelativeFilePath(""); -// SHAFT.Properties.browserStack.set().appUrl(""); + SHAFT.Properties.platform.set().executionAddress("browserstack"); + SHAFT.Properties.browserStack.set().appName(""); + SHAFT.Properties.browserStack.set().appRelativeFilePath(""); + SHAFT.Properties.browserStack.set().appUrl(""); // remote browserstack server (android) [NATIVE SAMSUNG BROWSER] || [CHROME] -// SHAFT.Properties.browserStack.set().osVersion("13.0"); -// SHAFT.Properties.browserStack.set().deviceName("Samsung Galaxy S23"); -// SHAFT.Properties.mobile.set().browserName(Browser.CHROME.browserName()); + SHAFT.Properties.browserStack.set().osVersion("13.0"); + SHAFT.Properties.browserStack.set().deviceName("Samsung Galaxy S23"); + SHAFT.Properties.mobile.set().browserName(Browser.CHROME.browserName()); // SHAFT.Properties.mobile.set().browserName("samsung"); // remote browserstack server (ios) [SAFARI BROWSER] diff --git a/src/test/java/testPackage/appium/androidBasicInteractionsTest.java b/src/test/java/testPackage/appium/androidBasicInteractionsTests.java similarity index 98% rename from src/test/java/testPackage/appium/androidBasicInteractionsTest.java rename to src/test/java/testPackage/appium/androidBasicInteractionsTests.java index 09cd541e626..80c1df668ba 100644 --- a/src/test/java/testPackage/appium/androidBasicInteractionsTest.java +++ b/src/test/java/testPackage/appium/androidBasicInteractionsTests.java @@ -14,7 +14,7 @@ import java.time.Duration; -public class androidBasicInteractionsTest { +public class androidBasicInteractionsTests { private static final ThreadLocal driver = new ThreadLocal<>(); private final String PACKAGE = "io.appium.android.apis"; @@ -124,7 +124,7 @@ public void visualElementIdentification_requiresProcessing() { public void testSendKeys() { String SEARCH_ACTIVITY = ".app.SearchInvoke"; - ((AndroidDriver) driver.get().getDriver()).executeScript("mobile: startActivity", ImmutableMap.of("intent", PACKAGE + "/" + SEARCH_ACTIVITY)); + ((AndroidDriver) driver.get().getDriver()).executeScript("mobile:startActivity", ImmutableMap.of("intent", PACKAGE + "/" + SEARCH_ACTIVITY)); // ((AndroidDriver) driver.get().getDriver()).startActivity(new Activity(PACKAGE, SEARCH_ACTIVITY)); driver.get().element().type(By.id("txt_query_prefill"), "Hello world!") @@ -137,7 +137,7 @@ public void testOpensAlert() { // Open the "Alert Dialog" activity of the android app String ALERT_DIALOG_ACTIVITY = ".app.AlertDialogSamples"; - ((AndroidDriver) driver.get().getDriver()).executeScript("mobile: startActivity", ImmutableMap.of("intent", PACKAGE + "/" + ALERT_DIALOG_ACTIVITY)); + ((AndroidDriver) driver.get().getDriver()).executeScript("mobile:startActivity", ImmutableMap.of("intent", PACKAGE + "/" + ALERT_DIALOG_ACTIVITY)); // ((AndroidDriver) driver.get().getDriver()).startActivity(new Activity(PACKAGE, ALERT_DIALOG_ACTIVITY)); // Click button that opens a dialog diff --git a/src/test/java/testPackage/legacy/SelectedValueTests.java b/src/test/java/testPackage/legacy/SelectedValueTests.java deleted file mode 100644 index 0f55a9f3e2a..00000000000 --- a/src/test/java/testPackage/legacy/SelectedValueTests.java +++ /dev/null @@ -1,40 +0,0 @@ -package testPackage.legacy; - -import com.shaft.driver.SHAFT; -import org.openqa.selenium.By; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -public class SelectedValueTests { - private static final ThreadLocal driver = new ThreadLocal<>(); - String baseURL = "https://yari-demos.prod.mdn.mozit.cloud/en-US/docs/Web/HTML/Element/select/_sample_."; - By select = By.tagName("select"); - - @Test - public void simpleSelect() { - String textToSelect = "Third Value"; - driver.get().browser().navigateToURL(baseURL + "Basic_select.html") - .performElementAction().select(select, textToSelect); - driver.get().assertThat().element(select).attribute("selectedText").isEqualTo(textToSelect).perform(); - } - - @Test - public void multipleSelect() { - driver.get().browser().navigateToURL(baseURL + "Advanced_select_with_multiple_features.html") - .performElementAction().select(select, "Dog") - .select(select, "Cat"); - driver.get().assertThat().element(select).attribute("selectedText").isEqualTo("DogCat").perform(); - } - - @BeforeMethod - public void beforeMethod() { - driver.set(new SHAFT.GUI.WebDriver()); - } - - @AfterMethod(alwaysRun = true) - public void afterMethod() { - driver.get().quit(); - } - -} diff --git a/src/test/java/testPackage/mockedTests/SelectMethodTests.java b/src/test/java/testPackage/mockedTests/SelectMethodTests.java index 205685f2386..507aae2442c 100644 --- a/src/test/java/testPackage/mockedTests/SelectMethodTests.java +++ b/src/test/java/testPackage/mockedTests/SelectMethodTests.java @@ -49,7 +49,7 @@ protected void setUp() { @AfterMethod(alwaysRun = true) protected void tearDown() { - if (driver != null) { + if (driver.get() != null) { driver.get().quit(); } } diff --git a/src/test/java/testPackage/mockedTests/SelectedValueTests.java b/src/test/java/testPackage/mockedTests/SelectedValueTests.java new file mode 100644 index 00000000000..dd6d36ab0e5 --- /dev/null +++ b/src/test/java/testPackage/mockedTests/SelectedValueTests.java @@ -0,0 +1,49 @@ +package testPackage.mockedTests; + +import com.shaft.driver.SHAFT; +import org.openqa.selenium.By; +import org.openqa.selenium.remote.Browser; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class SelectedValueTests { + private static final ThreadLocal driver = new ThreadLocal<>(); + String baseURL = SHAFT.Properties.paths.testData() + "selectedValueTests/"; + By select = By.tagName("select"); + + @Test + public void simpleSelect() { + if (SHAFT.Properties.platform.executionAddress().equals("local") + && !SHAFT.Properties.web.targetBrowserName().equalsIgnoreCase(Browser.SAFARI.browserName())) { + String textToSelect = "Third Value"; + driver.get().browser().navigateToURL(baseURL + "Basic_select.html") + .performElementAction().select(select, textToSelect); + driver.get().assertThat().element(select).attribute("selectedText").isEqualTo(textToSelect).perform(); + } + } + + @Test + public void multipleSelect() { + if (SHAFT.Properties.platform.executionAddress().equals("local") + && !SHAFT.Properties.web.targetBrowserName().equalsIgnoreCase(Browser.SAFARI.browserName())) { + driver.get().browser().navigateToURL(baseURL + "Advanced_select_with_multiple_features.html") + .performElementAction().select(select, "Dog") + .select(select, "Cat"); + driver.get().assertThat().element(select).attribute("selectedText").isEqualTo("DogCat").perform(); + } + } + + @BeforeMethod + public void beforeMethod() { + driver.set(new SHAFT.GUI.WebDriver()); + } + + @AfterMethod(alwaysRun = true) + public void afterMethod() { + if (driver.get() != null) { + driver.get().quit(); + } + } + +} diff --git a/src/test/resources/testDataFiles/selectedValueTests/Advanced_select_with_multiple_features.html b/src/test/resources/testDataFiles/selectedValueTests/Advanced_select_with_multiple_features.html new file mode 100644 index 00000000000..bc835cddb5e --- /dev/null +++ b/src/test/resources/testDataFiles/selectedValueTests/Advanced_select_with_multiple_features.html @@ -0,0 +1,15 @@ + diff --git a/src/test/resources/testDataFiles/selectedValueTests/Basic_select.html b/src/test/resources/testDataFiles/selectedValueTests/Basic_select.html new file mode 100644 index 00000000000..367c6799422 --- /dev/null +++ b/src/test/resources/testDataFiles/selectedValueTests/Basic_select.html @@ -0,0 +1,6 @@ + + \ No newline at end of file