From 71703f47b11f7b59e3f67698b7fd7cc6fad3bd4c Mon Sep 17 00:00:00 2001 From: Ismail Elshafeiy Date: Fri, 5 Jan 2024 13:57:36 +0200 Subject: [PATCH] Update Signed-off-by: Ismail Elshafeiy --- .github/workflows/e2eTests.yml | 1 + pom.xml | 2 +- .../properties/ExecutionPlatform.properties | 2 + .../properties/Performance.properties | 1 - .../properties/PlatformFlags.properties | 6 +++ .../resources/properties/Reporting.properties | 5 ++- .../resources/properties/TestNG.properties | 1 + .../resources/properties/Timeouts.properties | 6 ++- .../properties/VisualValidations.properties | 7 +-- .../properties/WebCapabilities.properties | 10 ++--- .../properties/browserStack.properties | 5 ++- .../properties/default/TestNG.properties | 2 + src/main/resources/properties/path.properties | 4 +- src/test/java/Test2/test.java | 4 -- .../gui/web/Test_NewValidationHelper.java | 39 ++++++++--------- .../gui/web/validations/DownloadFile.java | 43 +++++++++++++++++++ src/test/java/nopCommerce/tests/BaseTest.java | 11 +++-- .../tests/CheckoutProduct_test.java | 4 +- 18 files changed, 108 insertions(+), 45 deletions(-) delete mode 100644 src/test/java/Test2/test.java create mode 100644 src/test/java/examples/gui/web/validations/DownloadFile.java diff --git a/.github/workflows/e2eTests.yml b/.github/workflows/e2eTests.yml index ecb9e0a..a53ea24 100644 --- a/.github/workflows/e2eTests.yml +++ b/.github/workflows/e2eTests.yml @@ -27,6 +27,7 @@ jobs: - name: Set up Native Selenium Grid if: runner.os == 'Linux' run: docker-compose -f src/main/resources/docker-compose/selenium4.yml up --scale chrome=4 --scale edge=0 --scale firefox=0 -d + - name: Set up JDK 17 uses: actions/setup-java@v3 with: diff --git a/pom.xml b/pom.xml index 7edc059..46be555 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ - 7.4.20231015 + 8.1.20240102 1.9.20.1 3.11.0 3.3.1 diff --git a/src/main/resources/properties/ExecutionPlatform.properties b/src/main/resources/properties/ExecutionPlatform.properties index 514def3..acef57a 100644 --- a/src/main/resources/properties/ExecutionPlatform.properties +++ b/src/main/resources/properties/ExecutionPlatform.properties @@ -8,6 +8,8 @@ executionAddress=local # Windows , Linux , Mac , Android , iOS targetOperatingSystem=Mac com.SHAFT.proxySettings= +driverProxySettings=true +jvmProxySettings=true ################################################### ##### END of Properties File ################################################### \ No newline at end of file diff --git a/src/main/resources/properties/Performance.properties b/src/main/resources/properties/Performance.properties index 52685df..9f9cc1e 100644 --- a/src/main/resources/properties/Performance.properties +++ b/src/main/resources/properties/Performance.properties @@ -3,7 +3,6 @@ ################################################### lightHouseExecution=true lightHouseExecution.port=8888 -openLighthouseReportWhileExecution=true ################################################### ##### END of Properties File ################################################### \ No newline at end of file diff --git a/src/main/resources/properties/PlatformFlags.properties b/src/main/resources/properties/PlatformFlags.properties index d669749..4b597c1 100644 --- a/src/main/resources/properties/PlatformFlags.properties +++ b/src/main/resources/properties/PlatformFlags.properties @@ -7,6 +7,10 @@ retryMaximumNumberOfAttempts=0 # 0 = disabled , 1 = Without Headless Execution , 2 =With Headless Execution maximumPerformanceMode=0 skipTestsWithLinkedIssues=false +disableCache=false +enableTrueNativeMode=false +handleNonSelectDropDown=true +validateSwipeToElement=true # Automatic Behaviors autoMaximizeBrowserWindow=true automaticallyAssertResponseStatusCode=true @@ -17,7 +21,9 @@ forceCheckForElementVisibility=true forceCheckElementLocatorIsUnique=false forceCheckTextWasTypedCorrectly=true forceCheckNavigationWasSuccessful=true +forceCheckStatusOfRemoteServer=false attemptClearBeforeTypingUsingBackspace=false +attemptClearBeforeTyping=true respectBuiltInWaitsInNativeMode=true ################################################### ##### END of Properties File diff --git a/src/main/resources/properties/Reporting.properties b/src/main/resources/properties/Reporting.properties index 71cf647..5b70a6d 100644 --- a/src/main/resources/properties/Reporting.properties +++ b/src/main/resources/properties/Reporting.properties @@ -5,19 +5,22 @@ captureElementName=true captureWebDriverLogs=false debugMode=false +disableLogging=true alwaysLogDiscreetly=false # Allure report properties openAllureReportAfterExecution=true cleanAllureResultsDirectoryBeforeExecution=true generateAllureReportArchive=false # extent report properties +openExtentReportAfterExecution=false generateExtentReports=true cleanExtentReportsDirectoryBeforeExecution=true attachExtentReportToAllureReport=false # summary report +cleanSummaryReportsDirectoryBeforeExecution=true openExecutionSummaryReportAfterExecution=false ## lighthouse report -#openLighthouseReportWhileExecution=true +openLighthouseReportWhileExecution=true ################################################### ##### END of Properties File ################################################### \ No newline at end of file diff --git a/src/main/resources/properties/TestNG.properties b/src/main/resources/properties/TestNG.properties index f78d65b..14d8efe 100644 --- a/src/main/resources/properties/TestNG.properties +++ b/src/main/resources/properties/TestNG.properties @@ -8,6 +8,7 @@ setVerbose=1 setPreserveOrder=true setGroupByInstances=true setDataProviderThreadCount=1 +testSuiteTimeout=1440 ################################################### ##### END of Properties File ################################################### \ No newline at end of file diff --git a/src/main/resources/properties/Timeouts.properties b/src/main/resources/properties/Timeouts.properties index 2815d1d..f6e4248 100644 --- a/src/main/resources/properties/Timeouts.properties +++ b/src/main/resources/properties/Timeouts.properties @@ -1,7 +1,7 @@ ################################################### ##### SHAFT_Engine: Timeouts.properties ################################################### -waitForLazyLoading=false +waitForLazyLoading=true lazyLoadingTimeout=30 browserNavigationTimeout=30 pageLoadTimeout=30 @@ -15,6 +15,10 @@ dockerCommandTimeout=30 databaseLoginTimeout=30 databaseNetworkTimeout=30 databaseQueryTimeout=30 +waitForRemoteServerToBeUp=false +timeoutForRemoteServerToBeUp=10 +remoteServerInstanceCreationTimeout=10 +waitUntilTimeout=60 ################################################### ##### END of Properties File ################################################### \ No newline at end of file diff --git a/src/main/resources/properties/VisualValidations.properties b/src/main/resources/properties/VisualValidations.properties index 70f4676..3b160ad 100644 --- a/src/main/resources/properties/VisualValidations.properties +++ b/src/main/resources/properties/VisualValidations.properties @@ -1,14 +1,15 @@ ################################################### #### VisualValidations.properties ################################################### -screenshotParams_scalingFactor=1 +visualMatchingThreshold=0.90 +screenshotParams_scalingFactor=1.0 # Always, Never , FailuresOnly, ValidationPointsOnly screenshotParams_whenToTakeAScreenshot=ValidationPointsOnly # Always, Never , FailuresOnly, ValidationPointsOnly whenToTakePageSourceSnapshot=ValidationPointsOnly # Element, Regular, FullPage, screenshotParams_screenshotType=Regular -screenshotParams_highlightElements=true +screenshotParams_highlightElements=ture # JavaScript, AI screenshotParams_highlightMethod=AI screenshotParams_skippedElementsFromScreenshot= @@ -18,7 +19,7 @@ screenshotParams_watermarkOpacity=0.0 createAnimatedGif=true animatedGif_frameDelay=500 # Video -videoParams_recordVideo=true +videoParams_recordVideo=false # DriverSession, testMethod videoParams_scope=DriverSession ################################################### diff --git a/src/main/resources/properties/WebCapabilities.properties b/src/main/resources/properties/WebCapabilities.properties index 4ad12d6..d2b7259 100644 --- a/src/main/resources/properties/WebCapabilities.properties +++ b/src/main/resources/properties/WebCapabilities.properties @@ -1,20 +1,20 @@ ################################################### ##### SHAFT_Engine: WebCapabilities.properties ################################################### -# GoogleChrome , MozillaFirefox, InternetExplorer, Safari, -targetBrowserName=GoogleChrome +# chrome , MozillaFirefox, InternetExplorer, Safari,edge +targetBrowserName=chrome headlessExecution=false +browserWindowWidth=1920 +browserWindowHeight=1080 isMobileEmulation=false mobileEmulation.isCustomDevice=false # blackberryZ30, BlackberryPlayBook, galaxyNote3, galaxyNoteII, galaxySIII, galaxyS5, galaxyS8, samsungGalaxyS8+, galaxyS9+, galaxyTabS4, galaxyFold, samsungGalaxyS20Ultra, samsungGalaxyA51/71, kindleFireHDX, lgOptimusL70, microsoftLumia550, microsoftLumia950, motoG4, nexus10, nexus4, nexus5, nexus5X, nexus6, nexus6P, nexus7, nokiaLumia520, nokiaN9, nestHub, nestHubMax, pixel2, pixel2XL, pixel3, pixel3XL, pixel4, pixel5, jioPhone2, iPhone4, iPhone5/SE, iPhone6/7/8, iPhone6/7/8Plus, iPhoneSE, iPhoneX, iPhoneXR, iPhone12Pro, iPad, iPadPro, iPadAir, iPadMini, surfacePro7, surfaceDuo mobileEmulation.deviceName= mobileEmulation.width= mobileEmulation.height= -mobileEmulation.pixelRatio= +mobileEmulation.pixelRatio=1.0 mobileEmulation.userAgent= baseURL= -lightHouseExecution=true -lightHouseExecution.port=8080 ################################################### ##### END of Properties File ################################################### \ No newline at end of file diff --git a/src/main/resources/properties/browserStack.properties b/src/main/resources/properties/browserStack.properties index c2ecca5..d442adc 100644 --- a/src/main/resources/properties/browserStack.properties +++ b/src/main/resources/properties/browserStack.properties @@ -13,6 +13,7 @@ browserStack.platformVersion= browserStack.deviceName= #Use appUrl to test a previously uploaded app file browserStack.appUrl= +browserStack.customID= #Use appName and appRelativeFilePath to upload a new app file and test it browserStack.appName= browserStack.appRelativeFilePath= @@ -25,8 +26,8 @@ browserStack.osVersion= browserStack.browserVersion= #Do not change these unless you know what you're doing browserStack.local=false -browserStack.seleniumVersion=4.1.2 -browserStack.appiumVersion=1.22.0 +browserStack.seleniumVersion=4.15.2 +browserStack.appiumVersion=2.0.1 browserStack.acceptInsecureCerts=true browserStack.debug=true browserStack.networkLogs=true diff --git a/src/main/resources/properties/default/TestNG.properties b/src/main/resources/properties/default/TestNG.properties index cd0608c..68d5040 100644 --- a/src/main/resources/properties/default/TestNG.properties +++ b/src/main/resources/properties/default/TestNG.properties @@ -7,6 +7,8 @@ setVerbose=1 setPreserveOrder=true setGroupByInstances=true setDataProviderThreadCount=1 +#Test Suite Timeout in minutes +testSuiteTimeout=1440 ################################################### ##### END of PropertiesHelper File ################################################### \ No newline at end of file diff --git a/src/main/resources/properties/path.properties b/src/main/resources/properties/path.properties index 26f3292..4c5ba9c 100644 --- a/src/main/resources/properties/path.properties +++ b/src/main/resources/properties/path.properties @@ -5,10 +5,12 @@ propertiesFolderPath_CI= propertiesFolderPath=src/main/resources/properties/ dynamicObjectRepositoryPath=src/main/resources/dynamicObjectRepository/ testDataFolderPath=src/test/resources/testDataFiles/ -downloadsFolderPath=target/downloadedFiles/ +downloadsFolderPath=src/test/resources/downloadFiles/ allureResultsFolderPath=allure-results extentReportsFolderPath=extent-reports/ +executionSummaryReportFolderPath=execution-summary/ video.folder=allure-results/videos +servicesFolderPath=src/test/resources/META-INF/services/ applitoolsApiKey= ########################## Environment ######################## homeUrl=https://demo.nopcommerce.com/ diff --git a/src/test/java/Test2/test.java b/src/test/java/Test2/test.java deleted file mode 100644 index 7d8e874..0000000 --- a/src/test/java/Test2/test.java +++ /dev/null @@ -1,4 +0,0 @@ -package Test2; - -public class test { -} diff --git a/src/test/java/examples/gui/web/Test_NewValidationHelper.java b/src/test/java/examples/gui/web/Test_NewValidationHelper.java index 727cde1..0470359 100644 --- a/src/test/java/examples/gui/web/Test_NewValidationHelper.java +++ b/src/test/java/examples/gui/web/Test_NewValidationHelper.java @@ -1,15 +1,14 @@ package examples.gui.web; -import com.shaft.driver.DriverFactory; import com.shaft.driver.SHAFT; import com.shaft.gui.browser.BrowserActions; import com.shaft.validation.Validations; import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; + import org.testng.annotations.*; public class Test_NewValidationHelper { - WebDriver driver; + SHAFT.GUI.WebDriver driver; double elementIdentificationTimeout = SHAFT.Properties.timeouts.defaultElementIdentificationTimeout(); @Test @@ -105,13 +104,13 @@ public void f7() { @Test(groups = {"browserBasedTests"}) public void f8() { - Validations.assertThat().element(driver, By.tagName("h1")).exists().perform(); + Validations.assertThat().element(driver.getDriver(), By.tagName("h1")).exists().perform(); } @Test(groups = {"browserBasedTests"}) public void f9() throws Exception { try { - Validations.assertThat().element(driver, By.tagName("h3")).exists().perform(); + Validations.assertThat().element(driver.getDriver(), By.tagName("h3")).exists().perform(); throw new Exception("Expected to fail but passed."); } catch (AssertionError e) { // pass @@ -121,7 +120,7 @@ public void f9() throws Exception { @Test(groups = {"browserBasedTests"}) public void f10() throws Exception { try { - Validations.assertThat().element(driver, By.tagName("div")).exists().perform(); + Validations.assertThat().element(driver.getDriver(), By.tagName("div")).exists().perform(); throw new Exception("Expected to fail but passed."); } catch (AssertionError e) { // pass @@ -130,14 +129,14 @@ public void f10() throws Exception { @Test(groups = {"browserBasedTests"}) public void f11() { - Validations.assertThat().element(driver, By.tagName("h3")).doesNotExist() + Validations.assertThat().element(driver.getDriver(), By.tagName("h3")).doesNotExist() .withCustomReportMessage("Checking that false tag doesn't exist").perform(); } @Test(groups = {"browserBasedTests"}) public void f12() throws Exception { try { - Validations.assertThat().element(driver, By.tagName("h1")).doesNotExist().perform(); + Validations.assertThat().element(driver.getDriver(), By.tagName("h1")).doesNotExist().perform(); throw new Exception("Expected to fail but passed."); } catch (AssertionError e) { // pass @@ -147,7 +146,7 @@ public void f12() throws Exception { @Test(groups = {"browserBasedTests"}) public void f13() throws Exception { try { - Validations.assertThat().element(driver, By.tagName("div")).doesNotExist().perform(); + Validations.assertThat().element(driver.getDriver(), By.tagName("div")).doesNotExist().perform(); throw new Exception("Expected to fail but passed."); } catch (AssertionError e) { // pass @@ -156,14 +155,14 @@ public void f13() throws Exception { @Test(groups = {"browserBasedTests"}) public void f14() { - Validations.assertThat().element(driver, By.tagName("h1")).text().isEqualTo("Welcome to the-internet") + Validations.assertThat().element(driver.getDriver(), By.tagName("h1")).text().isEqualTo("Welcome to the-internet") .withCustomReportMessage("Asserting that the header text is correct").perform(); } @Test(groups = {"browserBasedTests"}) public void f15() throws Exception { try { - Validations.assertThat().element(driver, By.tagName("h1")).text().doesNotContain("Welcome").perform(); + Validations.assertThat().element(driver.getDriver(), By.tagName("h1")).text().doesNotContain("Welcome").perform(); throw new Exception("Expected to fail but passed."); } catch (AssertionError e) { // pass @@ -173,7 +172,7 @@ public void f15() throws Exception { @Test(groups = {"browserBasedTests"}) public void f16() throws Exception { try { - Validations.assertThat().element(driver, By.tagName("h3")).text().doesNotContain("Welcome").perform(); + Validations.assertThat().element(driver.getDriver(), By.tagName("h3")).text().doesNotContain("Welcome").perform(); throw new Exception("Expected to fail but passed."); } catch (AssertionError e) { // pass @@ -182,23 +181,23 @@ public void f16() throws Exception { @Test(groups = {"browserBasedTests"}) public void f17() { - Validations.assertThat().element(driver, By.tagName("h1")).attribute("text2").doesNotContain("Welcome").perform(); + Validations.assertThat().element(driver.getDriver(), By.tagName("h1")).attribute("text2").doesNotContain("Welcome").perform(); } @Test(groups = {"browserBasedTests"}) public void f18() { - Validations.assertThat().element(driver, By.tagName("h1")).attribute("text").doesNotContain("no").perform(); + Validations.assertThat().element(driver.getDriver(), By.tagName("h1")).attribute("text").doesNotContain("no").perform(); } @Test(groups = {"browserBasedTests"}) public void f20() { - Validations.assertThat().element(driver, By.tagName("h1")).attribute("size").doesNotContain("a").perform(); + Validations.assertThat().element(driver.getDriver(), By.tagName("h1")).attribute("size").doesNotContain("a").perform(); } @Test(groups = {"browserBasedTests"}) public void f21() throws Exception { try { - Validations.assertThat().element(driver, By.tagName("h3")).attribute("text").contains("Welcome").perform(); + Validations.assertThat().element(driver.getDriver(), By.tagName("h3")).attribute("text").contains("Welcome").perform(); throw new Exception("Expected to fail but passed."); } catch (AssertionError e) { // pass @@ -208,7 +207,7 @@ public void f21() throws Exception { @Test(groups = {"browserBasedTests"}) public void f22() throws Exception { try { - Validations.assertThat().element(driver, By.tagName("h1")).attribute("text").contains("yyy").perform(); + Validations.assertThat().element(driver.getDriver(), By.tagName("h1")).attribute("text").contains("yyy").perform(); throw new Exception("Expected to fail but passed."); } catch (AssertionError e) { // pass @@ -312,13 +311,13 @@ public void f37() throws Exception { @BeforeMethod(onlyForGroups = {"browserBasedTests"}) public void openBrowser() { - driver = DriverFactory.getDriver(); - BrowserActions.getInstance().navigateToURL("https://the-internet.herokuapp.com/"); + driver = new SHAFT.GUI.WebDriver(); + driver.browser().navigateToURL("https://the-internet.herokuapp.com/"); } @AfterMethod(onlyForGroups = {"browserBasedTests"}, alwaysRun = true) public void closeBrowser() { - DriverFactory.closeAllDrivers(); + driver.quit(); } @BeforeClass diff --git a/src/test/java/examples/gui/web/validations/DownloadFile.java b/src/test/java/examples/gui/web/validations/DownloadFile.java new file mode 100644 index 0000000..f9c6644 --- /dev/null +++ b/src/test/java/examples/gui/web/validations/DownloadFile.java @@ -0,0 +1,43 @@ +package examples.gui.web.validations; + +import com.shaft.cli.FileActions; +import com.shaft.driver.DriverFactory; +import com.shaft.driver.SHAFT; +import org.openqa.selenium.By; +import org.openqa.selenium.chrome.ChromeOptions; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.HashMap; +import java.util.Map; + +public class DownloadFile { + public SHAFT.GUI.WebDriver driver; + private static Map getStringObjectMap() { + Map prefs = new HashMap<>(); + //prefs.put("download.default_directory", downloadFilepath); + //prefs.put("download.prompt_for_download", false); + return prefs; + } + @BeforeMethod + public void setUp() { + ChromeOptions options = new ChromeOptions(); + Map prefs = getStringObjectMap(); + options.setExperimentalOption("prefs", prefs); + driver = new SHAFT.GUI.WebDriver(DriverFactory.DriverType.CHROME, options); + } + + @AfterMethod + public void tearDown() { + driver.quit(); + } + + @Test + public void downloadFile() throws InterruptedException { + driver.browser().navigateToURL("https://the-internet.herokuapp.com/download"); + driver.element().click(By.linkText("upload.txt")); + Thread.sleep(10000); + FileActions.getInstance().doesFileExist("src/test/resources/downloadFiles/" + "upload.txt"); + } +} diff --git a/src/test/java/nopCommerce/tests/BaseTest.java b/src/test/java/nopCommerce/tests/BaseTest.java index ccac9ac..bfc9885 100644 --- a/src/test/java/nopCommerce/tests/BaseTest.java +++ b/src/test/java/nopCommerce/tests/BaseTest.java @@ -1,6 +1,8 @@ package nopCommerce.tests; +import com.shaft.cli.FileActions; import com.shaft.cli.TerminalActions; +import com.shaft.driver.DriverFactory; import com.shaft.driver.SHAFT; import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterSuite; @@ -19,18 +21,19 @@ public class BaseTest { @BeforeClass(description = "Before Suite - Setup test data") public void readTestBaseData() { + FileActions.getInstance().deleteFolder("allure-report"); home_TD = new SHAFT.TestData.JSON(System.getProperty("homeJson")); register_TD = new SHAFT.TestData.JSON(System.getProperty("registerUserJson")); login_TD = new SHAFT.TestData.JSON(System.getProperty("loginJson")); myAccount_TD = new SHAFT.TestData.JSON(System.getProperty("myAccountJson")); - contactUs_TD=new SHAFT.TestData.JSON(System.getProperty("contactUsJson")); - productDetails_TD=new SHAFT.TestData.JSON(System.getProperty("productDetailsJson")); - checkout_TD=new SHAFT.TestData.JSON(System.getProperty("checkoutJson")); + contactUs_TD = new SHAFT.TestData.JSON(System.getProperty("contactUsJson")); + productDetails_TD = new SHAFT.TestData.JSON(System.getProperty("productDetailsJson")); + checkout_TD = new SHAFT.TestData.JSON(System.getProperty("checkoutJson")); + } @BeforeMethod(description = "Before Method - Initialize browser") public void setUp() { - SHAFT.Properties.performance.set().isEnabled(true); driver = new SHAFT.GUI.WebDriver(); } diff --git a/src/test/java/nopCommerce/tests/CheckoutProduct_test.java b/src/test/java/nopCommerce/tests/CheckoutProduct_test.java index 8721d10..c334726 100644 --- a/src/test/java/nopCommerce/tests/CheckoutProduct_test.java +++ b/src/test/java/nopCommerce/tests/CheckoutProduct_test.java @@ -32,11 +32,11 @@ public void RE_001_GuestRegister_viaValidEmail() { .enterPassword_TxtFd(newPassword) .enterConfirmPassword_TxtFd(newPassword) .clickOn_RegisterButton(); - driver.verifyThat() - .element(RegisterPage.register_SuccessMessage()).text() + driver.verifyThat().element( RegisterPage.register_SuccessMessage()).text() .contains(expectedResult_RegisterProcess) .withCustomReportMessage("Assert that the new account created By Get Success Message text of 'Register' process") .perform(); + } @Story("S3_As a guest, I want to Add Product to cart")