From db6f6d22f849a6c1a2eb0280009e63814577fb65 Mon Sep 17 00:00:00 2001 From: deepaktiwari Date: Wed, 18 Dec 2024 13:06:40 +0530 Subject: [PATCH] added parallel-support --- .../adapters/MobileDriverActionAdapter.java | 46 +++++++++++++++++++ .../prerequisite/PlatformDriverManager.java | 2 +- src/main/resources/config.properties | 2 +- .../testscripts/ios/TS_CT_UI_BaseTest.java | 17 +++---- testng.xml | 4 -- 5 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/ct/framework/contracts/adapters/MobileDriverActionAdapter.java b/src/main/java/com/ct/framework/contracts/adapters/MobileDriverActionAdapter.java index 5bc2cd7..fcca296 100644 --- a/src/main/java/com/ct/framework/contracts/adapters/MobileDriverActionAdapter.java +++ b/src/main/java/com/ct/framework/contracts/adapters/MobileDriverActionAdapter.java @@ -268,6 +268,52 @@ public boolean waitForElementVisible(WebElement element, long timeOutInSeconds, return element.isDisplayed(); } + public boolean waitForElementToBeClickable(WebElement element, long timeOutInSeconds, AppUiObjectNames elementNameForLogging) { + + try { + + if (element == null) { + return false; + } + elementNameForLogging = getElementName(elementNameForLogging); + + WebDriverWait wait = new WebDriverWait(this.driver, Duration.ofSeconds(timeOutInSeconds)); + testCase.info("Waiting for the element " + elementNameForLogging + " about " + timeOutInSeconds + " seconds.."); + + wait.until(ExpectedConditions.elementToBeClickable(element)); + } catch (Exception e) { + // testCase.error(e); + logger.severe("Not Found . "); + return false; + } + testCase.info(elementNameForLogging + " Found "); + return element.isDisplayed(); + } + + public void waitAndClick(WebElement element, long timeOutInSeconds, AppUiObjectNames elementNameForLogging) { + + try { + + if (element == null) { + logger.severe("Element is null. So Returning.."); + testCase.fail("Element is null. So Returning.."); + return; + } + elementNameForLogging = getElementName(elementNameForLogging); + + WebDriverWait wait = new WebDriverWait(this.driver, Duration.ofSeconds(timeOutInSeconds)); + testCase.info("Waiting for the element " + elementNameForLogging + " about " + timeOutInSeconds + " seconds.."); + wait.until(ExpectedConditions.elementToBeClickable(element)); + element.click(); + } catch (Exception e) { + testCase.fail(e); + logger.severe("Element Not Found");testCase.fail("Element Not found."); + + + } + } + + public boolean waitForElementInvisible(WebElement element, long timeOutInSeconds, AppUiObjectNames elementNameForLogging) { diff --git a/src/main/java/com/ct/framework/prerequisite/PlatformDriverManager.java b/src/main/java/com/ct/framework/prerequisite/PlatformDriverManager.java index 81d7206..76c7b8d 100644 --- a/src/main/java/com/ct/framework/prerequisite/PlatformDriverManager.java +++ b/src/main/java/com/ct/framework/prerequisite/PlatformDriverManager.java @@ -331,7 +331,7 @@ public WebDriver createDriverForBrowser(String browserName) throws MalformedURLE options.addArguments("--headless"); } driver=executionMode.equalsIgnoreCase("cloud")?new ChromeDriver(options):new ChromeDriver(); - System.out.println(); + // driver=new ChromeDriver(options); break; case "safari": diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index c5c49aa..24e6e6f 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -1,5 +1,5 @@ #automation Platform can be android or ios,web,api -AutomationPlatform=android +AutomationPlatform=web UiEnv=staging ApiEnv=staging #execution mode can be local or cloud diff --git a/src/test/java/com/ct/framework/testscripts/ios/TS_CT_UI_BaseTest.java b/src/test/java/com/ct/framework/testscripts/ios/TS_CT_UI_BaseTest.java index 8c1b447..ec02488 100644 --- a/src/test/java/com/ct/framework/testscripts/ios/TS_CT_UI_BaseTest.java +++ b/src/test/java/com/ct/framework/testscripts/ios/TS_CT_UI_BaseTest.java @@ -5,8 +5,6 @@ import com.aventstack.extentreports.ExtentTest; import com.aventstack.extentreports.MediaEntityBuilder; import com.aventstack.extentreports.Status; -import com.google.inject.Inject; -import com.google.inject.Injector; import com.ct.framework.aut.pojo.User; import com.ct.framework.aut.screens.BaseScreen; import com.ct.framework.aut.screens.WelcomeScreen; @@ -17,6 +15,8 @@ import com.ct.framework.contracts.adapters.MobileDriverActionAdapter; import com.ct.framework.prerequisite.ConfigurationModule; import com.ct.framework.prerequisite.PlatformDriverManager; +import com.google.inject.Inject; +import com.google.inject.Injector; import org.openqa.selenium.WebDriver; import org.testng.ITestResult; import org.testng.annotations.*; @@ -81,7 +81,7 @@ public class TS_CT_UI_BaseTest { @BeforeSuite() public void setUp() throws Exception { - // baseScreen.driver=driver; + // baseScreen.driver=driver; //add file handler to the logger. logger.info("Before Suite.."); currentTestCase = extent.createTest("Before Suite"); @@ -105,7 +105,7 @@ public void finishTest() { @BeforeClass public void setScreens() { - currentTestCase = extent.createTest("Before Class"); + currentTestCase = extent.createTest("Before Class"); // smcCoreUiCommons.setLoginScreen(loginScreen); // smcCoreUiCommons.setWelcomeScreen(welcomeScreen); // smcCoreUiCommons.setHomeScreen(homeScreen); @@ -145,14 +145,14 @@ public void afterEachTestCase(ITestResult result, XmlTest test) { break; case 2: //String screenshotPath = commonUtil.getScreenShot(driver, result.getName()); - String base64StringFail= commonUtil.getImageAsBase64(driver,result.getName()); + String base64StringFail = commonUtil.getImageAsBase64(driver, result.getName()); currentTestCase.log(Status.FAIL, "TEST FAILED.REFER SCREENSHOT", MediaEntityBuilder.createScreenCaptureFromBase64String(base64StringFail).build()); currentTestCase.fail(CommonUtil.getStringForReport(result.getThrowable().getMessage())); break; case 3: default: //String screenshotSkip = commonUtil.getScreenShot(driver, result.getName()); - String base64StringSkip= commonUtil.getImageAsBase64(driver,result.getName()); + String base64StringSkip = commonUtil.getImageAsBase64(driver, result.getName()); currentTestCase.log(Status.FAIL, "TEST FAILED.REFER SCREENSHOT", MediaEntityBuilder.createScreenCaptureFromBase64String(base64StringSkip).build()); currentTestCase.skip("TEST SKIPPED "); currentTestCase.skip(result.getThrowable()); @@ -175,8 +175,9 @@ public void cleanUp() throws Exception { if (platform.isIOS() || platform.isAndroid()) mobileDriverAction.killApp(); extent.flush(); - driver.quit(); - if ((platform.isIOS() || platform.isAndroid())&&!executionMode.equalsIgnoreCase("cloud")) + if (driver != null) + driver.quit(); + if ((platform.isIOS() || platform.isAndroid()) && !executionMode.equalsIgnoreCase("cloud")) driverHelper.stopAppiumServer(); } diff --git a/testng.xml b/testng.xml index 31a04f6..a59f294 100644 --- a/testng.xml +++ b/testng.xml @@ -11,8 +11,4 @@ - - - -