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

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

Source:ExtendedWebElement.java Github

copy

Full Screen

...1357 String textLog = (!decryptedText.equals(filePath) ? "********" : filePath);1358 DriverListener.setMessages(Messager.FILE_ATTACHED.getMessage(textLog, getName()),1359 Messager.FILE_NOT_ATTACHED.getMessage(textLog, getNameWithLocator()));1360 ((JavascriptExecutor) getDriver()).executeScript("arguments[0].style.display = 'block';", element);1361 ((RemoteWebDriver) castDriver(getDriver())).setFileDetector(new LocalFileDetector());1362 element.sendKeys(decryptedText);1363 }1364 @Override1365 public String doGetText() {1366 String text = element.getText();1367 LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage("Text", text, getName()));1368 return text;1369 }1370 @Override1371 public Point doGetLocation() {1372 Point point = element.getLocation();1373 LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage("Location", point.toString(), getName()));1374 return point;1375 }1376 @Override1377 public Dimension doGetSize() {1378 Dimension dim = element.getSize();1379 LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage("Size", dim.toString(), getName()));1380 return dim;1381 }1382 @Override1383 public String doGetAttribute(String name) {1384 String attribute = element.getAttribute(name);1385 LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage(name, attribute, getName()));1386 return attribute;1387 }1388 @Override1389 public void doRightClick() {1390 DriverListener.setMessages(Messager.ELEMENT_RIGHT_CLICKED.getMessage(getName()),1391 Messager.ELEMENT_NOT_RIGHT_CLICKED.getMessage(getNameWithLocator()));1392 1393 WebDriver drv = getDriver();1394 Actions action = new Actions(drv);1395 action.moveToElement(element).contextClick(element).build().perform();1396 }1397 @Override1398 public void doCheck() {1399 DriverListener.setMessages(Messager.CHECKBOX_CHECKED.getMessage(getName()), null);1400 1401 boolean isSelected = element.isSelected();1402 if (element.getAttribute("checked") != null) {1403 isSelected |= element.getAttribute("checked").equalsIgnoreCase("true");1404 }1405 1406 if (!isSelected) {1407 click();1408 }1409 }1410 @Override1411 public void doUncheck() {1412 DriverListener.setMessages(Messager.CHECKBOX_UNCHECKED.getMessage(getName()), null);1413 1414 boolean isSelected = element.isSelected();1415 if (element.getAttribute("checked") != null) {1416 isSelected |= element.getAttribute("checked").equalsIgnoreCase("true");1417 }1418 1419 if (isSelected) {1420 click();1421 }1422 }1423 1424 @Override1425 public boolean doIsChecked() {1426 1427 boolean res = element.isSelected();1428 if (element.getAttribute("checked") != null) {1429 res |= element.getAttribute("checked").equalsIgnoreCase("true");1430 }1431 1432 return res;1433 }1434 1435 @Override1436 public boolean doSelect(String text) {1437 final String decryptedSelectText = cryptoTool.decryptByPattern(text, CRYPTO_PATTERN);1438 1439 String textLog = (!decryptedSelectText.equals(text) ? "********" : text);1440 1441 DriverListener.setMessages(Messager.SELECT_BY_TEXT_PERFORMED.getMessage(textLog, getName()),1442 Messager.SELECT_BY_TEXT_NOT_PERFORMED.getMessage(textLog, getNameWithLocator()));1443 1444 final Select s = new Select(getElement());1445 // [VD] do not use selectByValue as modern controls could have only visible value without value1446 s.selectByVisibleText(decryptedSelectText);1447 return true;1448 }1449 @Override1450 public boolean doSelectValues(String[] values) {1451 boolean result = true;1452 for (String value : values) {1453 if (!select(value)) {1454 result = false;1455 }1456 }1457 return result;1458 }1459 @Override1460 public boolean doSelectByMatcher(BaseMatcher<String> matcher) {1461 1462 DriverListener.setMessages(Messager.SELECT_BY_MATCHER_TEXT_PERFORMED.getMessage(matcher.toString(), getName()),1463 Messager.SELECT_BY_MATCHER_TEXT_NOT_PERFORMED.getMessage(matcher.toString(), getNameWithLocator()));1464 1465 final Select s = new Select(getElement());1466 String fullTextValue = null;1467 for (WebElement option : s.getOptions()) {1468 if (matcher.matches(option.getText())) {1469 fullTextValue = option.getText();1470 break;1471 }1472 }1473 s.selectByVisibleText(fullTextValue);1474 return true;1475 }1476 @Override1477 public boolean doSelectByPartialText(String partialSelectText) {1478 1479 DriverListener.setMessages(1480 Messager.SELECT_BY_TEXT_PERFORMED.getMessage(partialSelectText, getName()),1481 Messager.SELECT_BY_TEXT_NOT_PERFORMED.getMessage(partialSelectText, getNameWithLocator()));1482 1483 final Select s = new Select(getElement());1484 String fullTextValue = null;1485 for (WebElement option : s.getOptions()) {1486 if (option.getText().contains(partialSelectText)) {1487 fullTextValue = option.getText();1488 break;1489 }1490 }1491 s.selectByVisibleText(fullTextValue);1492 return true;1493 }1494 @Override1495 public boolean doSelectByIndex(int index) {1496 DriverListener.setMessages(1497 Messager.SELECT_BY_INDEX_PERFORMED.getMessage(String.valueOf(index), getName()),1498 Messager.SELECT_BY_INDEX_NOT_PERFORMED.getMessage(String.valueOf(index), getNameWithLocator()));1499 1500 1501 final Select s = new Select(getElement());1502 s.selectByIndex(index);1503 return true;1504 }1505 @Override1506 public String doGetSelectedValue() {1507 final Select s = new Select(getElement());1508 return s.getAllSelectedOptions().get(0).getText();1509 }1510 @Override1511 public List<String> doGetSelectedValues() {1512 final Select s = new Select(getElement());1513 List<String> values = new ArrayList<String>();1514 for (WebElement we : s.getAllSelectedOptions()) {1515 values.add(we.getText());1516 }1517 return values;1518 }1519 1520 }, inputArgs);1521 return output;1522 }1523 public WebDriver getDriver() {1524 if (driver == null) {1525 LOGGER.error("There is no any initialized driver for ExtendedWebElement: " + getNameWithLocator());1526 throw new RuntimeException(1527 "Driver isn't initialized. Review stacktrace to analyze why driver is not populated correctly via reflection!");1528 }1529 return driver;1530 }1531 1532 private WebDriver castDriver(WebDriver drv) {1533 if (drv instanceof EventFiringWebDriver) {1534 drv = ((EventFiringWebDriver) drv).getWrappedDriver();1535 }1536 return drv;1537 }1538 1539 //TODO: investigate how can we merge the similar functionality in ExtendedWebElement, DriverHelper and LocalizedAnnotations1540 public By generateByForList(By by, int index) {1541 String locator = by.toString();1542 By resBy = null;1543 if (locator.startsWith(LocatorType.ID.getStartsWith())) {1544 resBy = By.id(StringUtils.remove(locator, LocatorType.ID.getStartsWith()) + "[" + index + "]");1545 }1546 if (locator.startsWith(LocatorType.NAME.getStartsWith())) {...

Full Screen

Full Screen

Source:IDriverPool.java Github

copy

Full Screen

...278 private void quitDriver(CarinaDriver carinaDriver, boolean keepProxyDuring) {279 try {280 carinaDriver.getDevice().disconnectRemote();281 282 // castDriver to disable DriverListener operations on quit283 WebDriver drv = castDriver(carinaDriver.getDriver());284 POOL_LOGGER.debug("start driver quit: " + carinaDriver.getName());285 286 Future<?> future = Executors.newSingleThreadExecutor().submit(new Callable<Void>() {287 public Void call() throws Exception {288 if (Configuration.getBoolean(Parameter.CHROME_CLOSURE)) {289 // workaround to not cleaned chrome profiles on hard drive290 POOL_LOGGER.debug("Starting drv.close()");291 drv.close();292 POOL_LOGGER.debug("Finished drv.close()");293 }294 POOL_LOGGER.debug("Starting drv.quit()");295 drv.quit();296 POOL_LOGGER.debug("Finished drv.quit()");297 return null;298 }299 });300 301 // default timeout for driver quit 1/2 of explicit302 long timeout = Configuration.getInt(Parameter.EXPLICIT_TIMEOUT) / 2;303 try {304 future.get(timeout, TimeUnit.SECONDS);305 } catch (InterruptedException e) {306 POOL_LOGGER.error("InterruptedException: Unable to quit driver!", e);307 Thread.currentThread().interrupt();308 } catch (ExecutionException e) {309 if (e.getMessage() != null && e.getMessage().contains("not found in active sessions")) {310 POOL_LOGGER.warn("Skip driver quit for already disconnected session!");311 } else {312 POOL_LOGGER.error("ExecutionException: Unable to quit driver!", e);313 }314 } catch (java.util.concurrent.TimeoutException e) {315 POOL_LOGGER.error("Unable to quit driver for " + timeout + "sec!", e);316 }317 } catch (WebDriverException e) {318 POOL_LOGGER.debug("Error message detected during driver quit!", e);319 // do nothing320 } catch (Exception e) {321 POOL_LOGGER.error("Error discovered during driver quit!", e);322 } finally {323 POOL_LOGGER.debug("finished driver quit: " + carinaDriver.getName());324 if (!keepProxyDuring) {325 ProxyPool.stopProxy();326 }327 }328 }329 330 private WebDriver castDriver(WebDriver drv) {331 if (drv instanceof EventFiringWebDriver) {332 drv = ((EventFiringWebDriver) drv).getWrappedDriver();333 }334 return drv; 335 } 336 337 /**338 * Create driver with custom capabilities339 * 340 * @param name341 * String driver name342 * @param capabilities343 * DesiredCapabilities344 * @param seleniumHost...

Full Screen

Full Screen

Source:DriverListener.java Github

copy

Full Screen

...156 // TODO: investigate if we run @AfterMethod etc system events after this crash157 if (thr.getMessage().contains("is not running, possibly crashed")) {158 throw new RuntimeException(thr);159 }160 // hopefully castDriver below resolve root cause of the recursive onException calls but keep below to ensure161 if (thr.getStackTrace() != null162 && (Arrays.toString(thr.getStackTrace())163 .contains("com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener.onException")164 || Arrays.toString(thr.getStackTrace()).contains("Unable to capture screenshot due to the WebDriverException"))) {165 LOGGER.error("Do not generate screenshot for invalid driver!");166 // prevent recursive crash for onException167 return;168 }169 LOGGER.debug("DriverListener->onException starting..." + thr.getMessage());170 driver = castDriver(driver);171 try {172 // 1. if you see mess with afterTest carina actions and Timer startup failure you should follow steps #2+ to determine root cause.173 // Driver initialization 'default' FAILED! Retry 1 of 1 time - Operation already started: mobile_driverdefault174 // 2. carefully track all preliminary exception for the same thread to detect 1st problematic exception175 // 3. 99% those root exception means that we should prohibit screenshot generation for such use-case176 // 4. if 3rd one is true just update Screenshot.isCaptured() adding part of the exception to the list177 // handle cases which should't be captured178 if (Screenshot.isCaptured(thr.getMessage())) {179 captureScreenshot(thr.getMessage(), driver, null, true);180 }181 } catch (Exception e) {182 if (!e.getMessage().isEmpty()183 && (e.getMessage().contains("Method has not yet been implemented") || (e.getMessage().contains("Method is not implemented")))) {184 LOGGER.debug("Unrecognized exception detected in DriverListener->onException!", e);185 } else {186 LOGGER.error("Unrecognized exception detected in DriverListener->onException!", e);187 }188 } catch (Throwable e) {189 LOGGER.error("Take a look to the logs above for current thread and add exception into the exclusion for Screenshot.isCaptured().", e);190 }191 LOGGER.debug("DriverListener->onException finished.");192 }193 /**194 * Converts char sequence to string.195 * 196 * @param csa - char sequence array197 * @return string representation198 */199 private String charArrayToString(CharSequence[] csa) {200 String s = StringUtils.EMPTY;201 if (csa != null) {202 StringBuilder sb = new StringBuilder();203 for (CharSequence cs : csa) {204 sb.append(String.valueOf(cs));205 }206 s = sb.toString();207 }208 return s;209 }210 @Override211 public void afterSwitchToWindow(String arg0, WebDriver driver) {212 // do nothing213 }214 @Override215 public void beforeSwitchToWindow(String arg0, WebDriver driver) {216 // Do nothing217 }218 @Override219 public <X> void afterGetScreenshotAs(OutputType<X> arg0, X arg1) {220 // do nothing221 }222 @Override223 public <X> void beforeGetScreenshotAs(OutputType<X> arg0) {224 // Do nothing225 }226 @Override227 public void afterGetText(WebElement element, WebDriver driver, String arg2) {228 // do nothing229 }230 @Override231 public void beforeGetText(WebElement element, WebDriver driver) {232 // do nothing233 }234 private void captureScreenshot(String comment, WebDriver driver, WebElement element, boolean errorMessage) {235 driver = castDriver(driver);236 if (getMessage(errorMessage) != null) {237 comment = getMessage(errorMessage);238 }239 try {240 if (errorMessage) {241 LOGGER.error(comment);242 String screenName = Screenshot.captureByRule(driver, comment, true); // in case of failure try full size if allowed243 // do not generate UI dump if no screenshot244 if (!screenName.isEmpty()) {245 generateDump(driver, screenName);246 }247 } else {248 LOGGER.info(comment);249 Screenshot.captureByRule(driver, comment);250 }251 } catch (Exception e) {252 LOGGER.debug("Unrecognized failure detected in DriverListener->captureScreenshot!", e);253 } finally {254 resetMessages();255 }256 }257 private void generateDump(WebDriver driver, String screenName) {258 // XML layout extraction259 File uiDumpFile = getDevice(driver).generateUiDump(screenName);260 if (uiDumpFile != null) {261 // use the same naming but with zip extension. Put into the test artifacts folder262 String dumpArtifact = ReportContext.getArtifactsFolder().getAbsolutePath() + "/" + screenName.replace(".png", ".zip");263 LOGGER.debug("UI Dump artifact: " + dumpArtifact);264 // build path to screenshot using name265 File screenFile = new File(ReportContext.getTestDir().getAbsolutePath() + "/" + screenName);266 // archive page source dump and screenshot both together267 FileManager.zipFiles(dumpArtifact, uiDumpFile, screenFile);268 Artifact.attachToTest("UI Dump artifact", new File(dumpArtifact));269 } else {270 LOGGER.debug("Dump file is empty.");271 }272 }273 private void onAfterAction(String comment, WebDriver driver) {274 captureScreenshot(comment, driver, null, false);275 }276 public static String getMessage(boolean errorMessage) {277 if (errorMessage) {278 return currentNegativeMessage.get();279 } else {280 return currentPositiveMessage.get();281 }282 }283 public static void setMessages(String positiveMessage, String negativeMessage) {284 currentPositiveMessage.set(positiveMessage);285 currentNegativeMessage.set(negativeMessage);286 }287 private void resetMessages() {288 currentPositiveMessage.remove();289 currentNegativeMessage.remove();290 }291 /**292 * Cast Carina driver to WebDriver removing all extra listeners (try to avoid direct operations via WebDriver as it doesn't support logging etc)293 *294 * @param drv WebDriver295 *296 * @return WebDriver297 */298 private WebDriver castDriver(WebDriver drv) {299 if (drv instanceof EventFiringWebDriver) {300 drv = ((EventFiringWebDriver) drv).getWrappedDriver();301 }302 return drv;303 }304}...

Full Screen

Full Screen

castDriver

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener;2import com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener;3import org.openqa.selenium.WebDriver;4public class castDriver {5 public static void main(String[] args) {6 DriverListener driverListener = new DriverListener();7 WebDriver driver = driverListener.castDriver();8 System.out.println(driver);9 }10}

Full Screen

Full Screen

castDriver

Using AI Code Generation

copy

Full Screen

1public class CastDriver {2 public static void main(String[] args) {3 WebDriver driver = new FirefoxDriver();4 DriverListener listener = new DriverListener();5 listener.castDriver(driver);6 }7}8public class CastDriver {9 public static void main(String[] args) {10 WebDriver driver = new FirefoxDriver();11 DriverListener listener = new DriverListener();12 listener.castDriver(driver);13 }14}15public class CastDriver {16 public static void main(String[] args) {17 WebDriver driver = new FirefoxDriver();18 DriverListener listener = new DriverListener();19 listener.castDriver(driver);20 }21}22public class CastDriver {23 public static void main(String[] args) {24 WebDriver driver = new FirefoxDriver();25 DriverListener listener = new DriverListener();26 listener.castDriver(driver);27 }28}29public class CastDriver {30 public static void main(String[] args) {31 WebDriver driver = new FirefoxDriver();32 DriverListener listener = new DriverListener();33 listener.castDriver(driver);34 }35}36public class CastDriver {37 public static void main(String[] args) {38 WebDriver driver = new FirefoxDriver();39 DriverListener listener = new DriverListener();40 listener.castDriver(driver);41 }42}43public class CastDriver {44 public static void main(String[] args) {45 WebDriver driver = new FirefoxDriver();46 DriverListener listener = new DriverListener();47 listener.castDriver(driver);48 }49}50public class CastDriver {

Full Screen

Full Screen

castDriver

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import org.testng.Assert;3import org.testng.annotations.Test;4import com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener;5import com.qaprosoft.carina.core.foundation.webdriver.listener.EventFiringAppiumDriver;6import com.qaprosoft.carina.core.foundation.webdriver.listener.EventFiringWebDriver;7import com.qaprosoft.carina.core.foundation.webdriver.listener.EventFiringWebDriverWrapper;8import com.qaprosoft.carina.core.foundation.webdriver.listener.EventFiringAppiumDriverWrapper;9import com.qaprosoft.carina.core.foundation.webdriver.listener.EventFiringSeleniumDriverWrapper;10import com.qaprosoft.carina.core.foundation.webdriver.listener.EventFiringSeleniumDriver;11import com.qaprosoft.carina.core.foundation.webdriver.listener.EventFiringAppiumDriverWrapper;12import com.qaprosoft.carina.core.foundation.webdriver.listener.EventFiringAppiumDriver;13import com.qaprosoft.carina.demo.gui.pages.HomePage

Full Screen

Full Screen

castDriver

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener;2import com.qaprosoft.carina.core.foundation.webdriver.DriverHelper;3import com.qaprosoft.carina.core.foundation.webdriver.DriverType;4WebDriver driver = DriverHelper.getWebDriver(DriverType.CHROME);5DriverListener.castDriver(driver);6import com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener;7import com.qaprosoft.carina.core.foundation.webdriver.DriverHelper;8import com.qaprosoft.carina.core.foundation.webdriver.DriverType;9WebDriver driver = DriverHelper.getWebDriver(DriverType.CHROME);10DriverListener.castDriver(driver);11import com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener;12import com.qaprosoft.carina.core.foundation

Full Screen

Full Screen

castDriver

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener;2public class 1 {3 public static void main(String[] args) {4 RemoteWebDriver driver = DriverListener.castDriver();5 }6}7import com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener;8public class 2 {9 public static void main(String[] args) {10 RemoteWebDriver driver = DriverListener.castDriver();11 }12}13import com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener;14public class 3 {15 public static void main(String[] args) {16 RemoteWebDriver driver = DriverListener.castDriver();17 }18}

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