How to use onAfterAction method of com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener class

Best Carina code snippet using com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener.onAfterAction

Source:DriverListener.java Github

copy

Full Screen

...46 private final static ThreadLocal<String> currentPositiveMessage = new ThreadLocal<String>();47 private final static ThreadLocal<String> currentNegativeMessage = new ThreadLocal<String>();48 @Override49 public void afterAlertAccept(WebDriver driver) {50 onAfterAction("Alert accepted", driver);51 }52 @Override53 public void afterAlertDismiss(WebDriver driver) {54 onAfterAction("Alert dismissed", driver);55 }56 @Override57 public void afterChangeValueOf(WebElement element, WebDriver driver, CharSequence[] value) {58 String comment = String.format("Text '%s' typed", charArrayToString(value));59 captureScreenshot(comment, driver, element, false);60 }61 @Override62 public void afterClickOn(WebElement element, WebDriver driver) {63 String comment = "Element clicked";64 captureScreenshot(comment, driver, element, false);65 }66 @Override67 public void afterFindBy(By by, WebElement element, WebDriver driver) {68 // Do nothing69 }70 @Override71 public void afterNavigateBack(WebDriver driver) {72 onAfterAction("Navigated back", driver);73 }74 @Override75 public void afterNavigateForward(WebDriver driver) {76 onAfterAction("Navigated forward", driver);77 }78 @Override79 public void afterNavigateRefresh(WebDriver driver) {80 onAfterAction("Page refreshed", driver);81 }82 @Override83 public void afterNavigateTo(String url, WebDriver driver) {84 String comment = String.format("URL '%s' opened", url);85 onAfterAction(comment, driver);86 }87 @Override88 public void afterScript(String script, WebDriver driver) {89 // Do nothing90 }91 @Override92 public void beforeAlertAccept(WebDriver driver) {93 onBeforeAction();94 }95 @Override96 public void beforeAlertDismiss(WebDriver driver) {97 onBeforeAction();98 }99 @Override100 public void beforeChangeValueOf(WebElement element, WebDriver driver, CharSequence[] value) {101 onBeforeAction();102 }103 @Override104 public void beforeClickOn(WebElement element, WebDriver driver) {105 onBeforeAction();106 }107 @Override108 public void beforeFindBy(By by, WebElement element, WebDriver driver) {109 onBeforeAction();110 }111 @Override112 public void beforeNavigateBack(WebDriver driver) {113 onBeforeAction();114 }115 @Override116 public void beforeNavigateForward(WebDriver driver) {117 onBeforeAction();118 }119 @Override120 public void beforeNavigateRefresh(WebDriver driver) {121 onBeforeAction();122 }123 @Override124 public void beforeNavigateTo(String script, WebDriver driver) {125 onBeforeAction();126 }127 @Override128 public void beforeScript(String script, WebDriver driver) {129 onBeforeAction();130 }131 @Override132 public void onException(Throwable thr, WebDriver driver) {133 if (thr.getMessage() != null) {134 if (thr.getStackTrace().toString().contains("com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener.onException")) {135 LOGGER.error("Do not generate screenshot for invalid driver!");136 //prevent recursive crash for onException137 return;138 }139 140 // handle use-case when application crashed on iOS but tests continue to execute something because doesn't raise valid exception141 // Example:142 // 10:25:20 2018-09-14 10:29:39 DriverListener [TestNG-31] [ERROR]143 // [iPhone_6s] An unknown server-side error occurred while144 // processing the command. Original error: The application under145 // test with bundle id 'Q5AWL8WCY6.iMapMyRun' is not running,146 // possibly crashed (WARNING: The server did not provide any147 // stacktrace information)148 149 //TODO: investigate if we run @AfterMethod etc system events after this crash150 if (thr.getMessage().contains("is not running, possibly crashed")) {151 throw new RuntimeException(thr);152 }153 154 String urlPrefix = "";155 try {156 urlPrefix = "url: " + driver.getCurrentUrl() + "\n";157 } catch (Exception e) {158 //do nothing159 }160 161 // handle cases which should't be captured162 if (Screenshot.isCaptured(thr.getMessage())) {163 captureScreenshot(urlPrefix + thr.getMessage(), driver, null, true);164 }165 }166 }167 /**168 * Converts char sequence to string.169 * 170 * @param csa - char sequence array171 * @return string representation172 */173 private String charArrayToString(CharSequence[] csa) {174 String s = StringUtils.EMPTY;175 if (csa != null) {176 StringBuilder sb = new StringBuilder();177 for (CharSequence cs : csa) {178 sb.append(String.valueOf(cs));179 }180 s = sb.toString();181 }182 return s;183 }184 @Override185 public void afterSwitchToWindow(String arg0, WebDriver arg1) {186 // do nothing187 }188 @Override189 public void beforeSwitchToWindow(String arg0, WebDriver arg1) {190 onBeforeAction();191 }192 private void captureScreenshot(String comment, WebDriver driver, WebElement element, boolean errorMessage) {193 if (getMessage(errorMessage) != null) {194 comment = getMessage(errorMessage);195 }196 if (errorMessage) {197 LOGGER.error(comment);198 Screenshot.captureFailure(driver, comment); // in case of failure199 } else {200 LOGGER.info(comment);201 Screenshot.capture(driver, comment);202 }203 204 resetMessages();205 }206 private void onAfterAction(String comment, WebDriver driver) {207 captureScreenshot(comment, driver, null, false);208 }209 210 private void onBeforeAction() {211 // 4a. if "tzid" not exist inside vncArtifact and exists in Reporter -> register new vncArtifact in Zafira.212 // 4b. if "tzid" already exists in current artifact but in Reporter there is another value. Then this is use case for class/suite mode when we share the same213 // driver across different tests214 ITestResult res = Reporter.getCurrentTestResult();215 if (res != null && res.getAttribute("ztid") != null) {216 Long ztid = (Long) res.getAttribute("ztid");217 if (ztid != vncArtifact.getTestId() && vncArtifact != null && ! StringUtils.isBlank(vncArtifact.getName())) {218 vncArtifact.setTestId(ztid);219 LOGGER.debug("Registered live video artifact " + vncArtifact.getName() + " into zafira");220 ZafiraSingleton.INSTANCE.getClient().addTestArtifact(vncArtifact);...

Full Screen

Full Screen

onAfterAction

Using AI Code Generation

copy

Full Screen

1import org.testng.Assert;2import com.qaprosoft.carina.core.foundation.report.ReportContext;3import com.qaprosoft.carina.core.foundation.report.TestResultItem;4import com.qaprosoft.carina.core.foundation.utils.Configuration;5import com.qaprosoft.carina.core.foundation.utils.R;6public class CustomMessage {7 public static void addMessage(String message) {8 TestResultItem testResultItem = ReportContext.getTestResultItem();9 testResultItem.setMessage(message);10 }11 public static void addMessage(String message, Object... args) {12 TestResultItem testResultItem = ReportContext.getTestResultItem();13 testResultItem.setMessage(R.CONFIG.get(message, args));14 }15 public static void addScreenshot(String screenshotName) {16 TestResultItem testResultItem = ReportContext.getTestResultItem();17 testResultItem.setScreenshot(screenshotName);18 }19 public static void addAttachment(String attachmentName) {20 TestResultItem testResultItem = ReportContext.getTestResultItem();21 testResultItem.setAttachment(attachmentName);22 }23 public static void addLink(String linkName, String linkUrl) {24 TestResultItem testResultItem = ReportContext.getTestResultItem();25 testResultItem.setLink(linkName, linkUrl);26 }27 public static void addLink(String linkName, String linkUrl, String linkType) {28 TestResultItem testResultItem = ReportContext.getTestResultItem();29 testResultItem.setLink(linkName, linkUrl, linkType);30 }31 public static void addLog(String message) {32 TestResultItem testResultItem = ReportContext.getTestResultItem();33 testResultItem.addLog(message);34 }35 public static void addLog(String message, Object... args) {36 TestResultItem testResultItem = ReportContext.getTestResultItem();37 testResultItem.addLog(R.CONFIG.get(message, args));38 }39 public static void addLog(String message, String logType) {40 TestResultItem testResultItem = ReportContext.getTestResultItem();41 testResultItem.addLog(message, logType);42 }43 public static void addLog(String message, String logType, Object... args) {44 TestResultItem testResultItem = ReportContext.getTestResultItem();45 testResultItem.addLog(R.CONFIG.get(message, args), logType);46 }47 public static void addLog(String message

Full Screen

Full Screen

onAfterAction

Using AI Code Generation

copy

Full Screen

1if (TestContext.getTestStatus() == TestStatus.FAILED) {2 String screenshotPath = takeScreenshot();3 attachScreenshot(screenshotPath);4}5if (TestContext.getTestStatus() == TestStatus.FAILED) {6 String screenshotPath = takeScreenshot();7 attachScreenshot(screenshotPath);8}9if (TestContext.getTestStatus() == TestStatus.FAILED) {10 String screenshotPath = takeScreenshot();11 attachScreenshot(screenshotPath);12}13if (TestContext.getTestStatus() == TestStatus.FAILED) {14 String screenshotPath = takeScreenshot();15 attachScreenshot(screenshotPath);16}17if (TestContext.getTestStatus() == TestStatus.FAILED) {18 String screenshotPath = takeScreenshot();19 attachScreenshot(screenshotPath);20}21if (TestContext.getTestStatus() == TestStatus.FAILED) {22 String screenshotPath = takeScreenshot();23 attachScreenshot(screenshotPath);24}

Full Screen

Full Screen

onAfterAction

Using AI Code Generation

copy

Full Screen

1public void onAfterAction(WebDriver driver, String name, long duration) {2 LOG.info("Page action: " + name + " took " + duration + " ms");3}4public void onAfterNavigate(WebDriver driver, String url, long duration) {5 LOG.info("Page navigation to: " + url + " took " + duration + " ms");6}7public void onAfterNavigateBack(WebDriver driver, String url, long duration) {8 LOG.info("Page navigation back to: " + url + " took " + duration + " ms");9}10public void onAfterNavigateForward(WebDriver driver, String url, long duration) {11 LOG.info("Page navigation forward to: " + url + " took " + duration + " ms");12}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful