Best Galen code snippet using com.galenframework.reports.model.LayoutReport.getScreenshot
Source:ActionType.java
...101 ExtentTestManager.getTest().log(LogStatus.SKIP, string);102 if (prop.getProperty(Constantns.TAKE_SCREENSHOT_ON_PASS).equals("true")) {103 if (screenShotDriver() != null) {104 ExtentTestManager.getTest().log(LogStatus.INFO,105 ExtentTestManager.getTest().addScreenCapture(getScreenshot(screenShotDriver(), string)));106 }107 }108 } catch (Exception e) {109 }110 }111 /**112 * It returns value from property file based on key value113 * 114 * @param key115 * @return116 */117 public String getProperty(String key) {118 if (prop == null) {119 try {120 prop = new ReadProperties();121 } catch (Throwable e) {122 // e.printStackTrace();123 }124 }125 return prop.getProperty(key);126 }127 /**128 * It wait for element for 10 seconds if the object is not located129 * 130 * @param by131 * @return132 */133 public boolean waitForElement(By by) {134 return waitForElement(by,true);135 }136 /**137 * 138 * @param by139 * @param scrollRequired140 * @return141 */142 public boolean waitForElement(By by, boolean scrollRequired) {143 Logs.info(" Waiting for element ... " + by.toString());144 try {145 WebDriverWait wait = new WebDriverWait(getDriver(), Integer.parseInt(getProperty("waitForElementTimeOut").trim()));146 WebElement element = wait.until(147 ExpectedConditions.visibilityOfElementLocated(by));148 viewPort(by, scrollRequired);149 return element.isDisplayed();150 } catch (Exception e) {151 if (getProperty("PageLoadStrategy").toUpperCase().equals("NONE")) {152 waitForPageLoad(120);153 try {154 WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(by));155 viewPort(by, scrollRequired);156 return element.isDisplayed();157 } catch (Exception e2) {158 } 159 }160 return false;161 }162 }163 /**164 * It will wait till the object is located within the given time165 * 166 * @param by167 * :example By.xpath("//")168 * @param seconds169 * : example 5170 * @return true or false171 */172 public boolean waitForElement(By by, int seconds) {173 return waitForElement(by, seconds,true);174 }175 public boolean waitForElement(By by, int seconds, boolean scrollRequired) {176 generateInfoReport(" Waiting for element ... " + by.toString());177 try {178 WebDriverWait wait = new WebDriverWait(getDriver(), seconds);179 WebElement element = wait.until(180 ExpectedConditions.visibilityOfElementLocated(by));181 viewPort(by, scrollRequired);182 generateInfoReport(" Element located ... " + by.toString());183 return element.isDisplayed();184 } catch (Exception e) {185 generateInfoReport(" Element not located ... " + by.toString());186 return false;187 }188 189 }190 public boolean waitTillElementInVisible(By by, int seconds){191 try {192 generateInfoReport("Waiting for element to be disappeared :"+by);193 return new WebDriverWait(getDriver(), seconds).until(ExpectedConditions.invisibilityOfElementLocated(by));194 } catch (Exception e) {195 generateInfoReport("Element is appeared :"+by);196 return true;197 }198 }199 private void viewPort(By by, boolean scrollRequired) {200 try {201 if (scrollRequired) {202 if (!isVisibleInViewport(getDriver().findElement(by))) {203 JavascriptExecutor js = (JavascriptExecutor) getDriver();204 int yPosition = getDriver().findElement(by).getLocation().getY();205 js.executeScript("window.scroll(300,"206 + (yPosition - (getDriver().manage().window().getSize().getHeight() / 2)) + ")");207 StaticWait(1);208 }209 }210 211 } catch (Exception e) {212 }213 }214 /**215 * It wait for element for 10 seconds if the object is not located216 * 217 * @param by218 * @return219 */220 public boolean waitForElement(WebElement element) {221 boolean flag = false;222 int nooftimes = 0;223 while (!flag) {224 try {225 if (nooftimes >= 10) {226 return false;227 }228 getDriver().manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);229 try {230 JavascriptExecutor js = (JavascriptExecutor) getDriver();231 int yPosition = element.getLocation().getY();232 js.executeScript("window.scroll(300,"233 + (yPosition - (getDriver().manage().window().getSize().getHeight() / 2)) + ")");234 // Thread.sleep(1000);235 } catch (Exception e) {236 }237 flag = element.isDisplayed();238 if (flag) {239 return true;240 } else {241 nooftimes++;242 StaticWait(1);243 }244 } catch (Exception e) {245 nooftimes++;246 StaticWait(1);247 }248 }249 return flag;250 }251 /**252 * Generates pass or fail report based on status flag253 * 254 * @param status255 * @param passText256 * @param failText257 */258 public void generateReport(boolean status, String passText, String failText) {259 if (status) {260 generatePassReport(passText);261 } else {262 generateFailReport(failText);263 }264 }265 266 /**267 * Thread.sleep268 * 269 * @param i270 * :no of seconds like 10 for 10 seconds271 */272 public void StaticWait(int i) {273 try {274 Thread.sleep(i * 1000);275 } catch (Exception e) {276 }277 }278 /**279 * Generate info statement in reports280 * 281 * @param infoText282 */283 public void generateInfoReport(String infoText) {284 ExtentTestManager.getTest().log(LogStatus.INFO, infoText);285 Logs.info(infoText.replace(LEFTBOLDTAG, "").replace(RIGHTBOLDTAG, "").replace("<br>", "\n\t"));286 // Logs.info("Passed: " + passText);287 }288 /**289 * Generate warning statement in reports290 * 291 * @param infoText292 */293 public void generateWarningReport(String infoText) {294 ExtentTestManager.getTest().log(LogStatus.WARNING, infoText);295 Logs.error(infoText.replace(LEFTBOLDTAG, "").replace(RIGHTBOLDTAG, "").replace("<br>", "\n\t"));296 // Logs.info("Passed: " + passText);297 }298 /**299 * Generate pass statement in reports300 * 301 * @param infoText302 */303 public void generatePassReportWithNoScreenShot(String passText) {304 ExtentTestManager.getTest().log(LogStatus.PASS, passText);305 Logs.info(passText);306 }307 /**308 * Returns bold text309 * 310 * @param data311 * @return312 */313 public String getBoldText(String data) {314 return LEFTBOLDTAG + data + RIGHTBOLDTAG;315 }316 /**317 * It generates the key pair values fist row columns as keys and rest as318 * values for single row319 * 320 * @param arrary321 * @param rowNum322 * @return323 */324 public Hashtable<String, String> getHashMapData(String arrary[][], int rowNum) {325 Hashtable<String, String> ht = new Hashtable<>();326 for (int i = 0; i < arrary[0].length; i++) {327 ht.put(arrary[0][i], arrary[rowNum][i]);328 }329 return ht;330 }331 /**332 * If element not present it return true, otherwise returns false and333 * generates report334 * 335 * @param by336 * @param locatorName337 * @return338 */339 public boolean isElementNotPresent(By by, String locatorName) {340 boolean flag = false;341 try {342 getDriver().manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);343 flag = getDriver().findElement(by).isDisplayed();344 } catch (Exception e) {345 flag = false;346 } finally {347 if (flag) {348 generateFailReport(locatorName + " is present in the page but should not visible<br>Locator: "+by);349 } else {350 generatePassReport(locatorName + " is not present on the page as expected<br>Locator: "+by);351 }352 }353 return flag;354 }355 /**356 * returns true when element is displayed on screen Generates report357 * 358 * @param by359 * @param locatorName360 * @return361 * @throws Throwable362 */363 public boolean isElementPresent(By by, String locatorName) {364 boolean flag = false;365 try {366 flag = waitForElement(by);367 generateReport(flag, "Looking for element :" + locatorName + "<br>Locator :"+by+"<br>Expected:" + locatorName368 + " should be displayed<br>Actual: " + flag);369 } catch (Exception e) {370 return flag;371 }372 return flag;373 }374 /**375 * returns true when element is displayed on screen Generates report376 * 377 * @param element378 * @param locatorName379 * @return380 */381 public boolean isElementPresent(WebElement element, String locatorName) {382 boolean flag = false;383 try {384 flag = waitForElement(element);385 generateReport(flag, "Looking for element :" + locatorName + "<br>Expected:" + locatorName386 + " should be displayed<br>Actual: " + flag);387 } catch (Exception e) {388 return flag;389 }390 return flag;391 }392 /**393 * Returns text on element if exists, otherwise returns empty string394 * 395 * @param by396 * @param locator397 * @return398 */399 public String getText(By by, String locator) {400 return getText(by, locator,true);401 }402 private String getText(By by, String locator, boolean scrollRequired) {403 try {404 waitForElement(by,scrollRequired);405 String text =getDriver().findElement(by).getText().trim();406 generateInfoReport("Text on "+ locator +":"+text);407 return text;408 } catch (Exception e) {409 generateInfoReport("Text on "+locator +" :");410 return "";411 }412 }413 /**414 * Validated page title415 * 416 * @param expectedPageTitle417 * @param pageName418 * : this is sake of report419 * @return true or false420 */421 public boolean isTitleMatched(String expectedPageTitle, String pageName) {422 try {423 String text = getWindowTitle();424 generateReport(text.equals(expectedPageTitle.trim()), "Page Title verification for " + pageName425 + "<br>Actual:" + text + "<br>Expected:" + expectedPageTitle);426 return text.equals(expectedPageTitle.trim());427 } catch (Exception e) {428 return false;429 }430 431 }432 433 public String getWindowTitle(){434 String title = getDriver().getTitle().trim();435 int i=0;436 while (title.length()==0) {437 title = getDriver().getTitle().trim();438 i++;439 if(i==120){440 break;441 }else{442 StaticWait(1);443 }444 }445 generateInfoReport("Window title :"+title);446 return title;447 }448 449 450 /**451 * This method used type value in to text box or text area452 * 453 * @param locator454 * : Action to be performed on element (Get it from Object455 * repository)456 * 457 * @param testdata458 * : Value wish to type in text box / text area459 * 460 * @param locatorName461 * : Meaningful name to the element (Ex:Textbox,Text Area etc..)462 * 463 * 464 */465 public boolean type(By locator, String testdata, String locatorName) {466 String exception = "";467 boolean flag = false;468 try {469 Logs.info("Entering data " + testdata + " into " + locatorName + " ... " + locator);470 waitForElement(locator);471 getDriver().findElement(locator).clear();472 getDriver().findElement(locator).sendKeys(testdata);473 StaticWait(1);474 flag = true;475 } catch (Exception e) {476 exception = "<br>Exception:" + getException(e);477 flag = false;478 } finally {479 generateReport(flag, "Enter data :" + testdata + " into " + locatorName+"<br>Locator :"+locator + exception);480 }481 return flag;482 }483 /**484 * This method used type value in to text box or text area485 * 486 * @param locator487 * : Action to be performed on element (Get it from Object488 * repository)489 * 490 * @param Key491 * : input keyboard actions492 * 493 * @param locatorName494 * : Meaningful name to the element (Ex:Textbox,Text Area etc..)495 * 496 * 497 */498 public boolean typeKeys(By locator, Keys key, String locatorName) {499 String exception = "";500 boolean flag = false;501 try {502 Logs.info("Entering data " + key + " into " + locatorName + " ... " + locator);503 waitForElement(locator);504 getDriver().findElement(locator).clear();505 getDriver().findElement(locator).sendKeys(Keys.TAB);506 flag = true;507 } catch (Exception e) {508 exception = "<br>Exception:" + getException(e);509 flag = false;510 } finally {511 generateReport(flag, "Enter data :" + key + " into " + locatorName + exception);512 }513 return flag;514 }515 516 /**517 * 518 * @param locator : Locator of drop down519 * @param dropDownName : Drop down Name520 * @param valueToSelect : Value to select from Drop down521 * @return522 */523 public boolean selectItemFromDropDown(By locator, String dropDownName, String valueToSelect) {524 try {525 526 Select dropDown = new Select(driver.findElement(locator));527 dropDown.deselectByValue(valueToSelect);528 StaticWait(1);529 generateInfoReport(valueToSelect+" has been selected from "+dropDownName);530 return true;531 }catch(Exception e) {532 generateInfoReport("Exception while selecting the value "+valueToSelect+" from "+dropDownName);533 return false;534 }535 }536 /**537 * Performs mouse over538 * 539 * @param locator540 * @param locatorName541 * @return542 */543 public boolean mouseover(By locator, String locatorName) {544 String exception = "";545 boolean flag = false;546 try {547 WebElement mo = getDriver().findElement(locator);548 //549 new Actions(getDriver()).moveToElement(mo).build().perform();550 ExtentTestManager.getTest().log(LogStatus.PASS, "Mouse over perfomed on " + locatorName);551 flag = true;552 } catch (Exception e) {553 exception = ", Exception:" + e.getMessage();554 flag = false;555 } finally {556 generateReport(flag, "Mouse over on " + locatorName + exception);557 }558 return flag;559 }560 /**561 * Wait for an ElementPresent562 * 563 * @param locator564 * : Action to be performed on element (Get it from Object565 * repository)566 * 567 * @return Whether or not the element is displayed568 */569 public boolean waitForElementPresent(By by, String locator) throws Throwable {570 boolean flag = false;571 try {572 for (int i = 0; i < 600; i++) {573 if (getDriver().findElement(by).isDisplayed()) {574 flag = true;575 return true;576 } else {577 Thread.sleep(100);578 }579 }580 } catch (Exception e) {581 e.printStackTrace();582 return false;583 } finally {584 if (!flag) {585 Assert.fail("Falied to locate element " + locator);586 } else if (b && flag) {587 Assert.assertTrue(true, "Successfullly located element " + locator);588 }589 }590 return flag;591 }592 /**593 * Select a value from Dropdown using send keys594 * 595 * @param locator596 * : Action to be performed on element (Get it from Object597 * repository)598 * 599 * @param value600 * : Value wish type in dropdown list601 * 602 * @param locatorName603 * : Meaningful name to the element (Ex:Year Dropdown, items604 * Listbox etc..)605 * 606 */607 public boolean selectBySendkeys(By locator, String value, String locatorName) throws Throwable {608 boolean flag = false;609 try {610 getDriver().findElement(locator).sendKeys(value);611 flag = true;612 } catch (Exception e) {613 } finally {614 generateReport(flag, "Select - " + value + " in " + locatorName);615 }616 return flag;617 }618 public static int getBreakPoint(int breakPoint) {619 switch (breakPoint) {620 case 1:621 return Constantns.BREAK_POINT_1_BROWSER_WIDTH;622 case 2:623 return Constantns.BREAK_POINT_2_BROWSER_WIDTH;624 case 3:625 return Constantns.BREAK_POINT_3_BROWSER_WIDTH;626 case 4:627 return Constantns.BREAK_POINT_4_BROWSER_WIDTH;628 }629 return 4;630 }631 /**632 * Generates galen report633 * 634 * @param specFileLocation635 * : exclude src/it/resources/ in path636 * @param fieldName637 * @return638 */639 public LayoutReport call_Gallen(String specFileLocation, String fieldName) {640 641 generateInfoReport(("Galen Spec execution started ......<br>Spec :"+ReadProperties.projectLocation+specFileLocation));642 String breakPoint1 = breakPoint;643 switch (breakPoint1) {644 case "1":645 breakPoint1 = "360x700";646 break;647 case "2":648 breakPoint1 = "768x700";649 break;650 case "3":651 breakPoint1 = "1024x700";652 break;653 case "4":654 breakPoint1 = "1280x700";655 break;656 default:657 break;658 }659 LayoutReport layoutReport = null;660 generateInfoReport(" Galen info title: " + browser.toUpperCase() + "_" + fieldName + "_" + breakPoint1);661 GalenTestInfo test = GalenTestInfo.fromString(browser.toUpperCase() + "_" + fieldName + "_" + breakPoint1);662 try {663 try {664 waitForPageLoad(60);665 getDriver().manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);666 generateInfoReport(" Executing galen spec......");667 layoutReport = Galen.checkLayout(getDriver(), ReadProperties.projectLocation + specFileLocation,668 asList(breakPoint1));669 670 List<ValidationResult> list = layoutReport.getValidationErrorResults();671 String errors = "";672 try {673 Logs.info(" Checking galen failures ....");674 for (ValidationResult validationResult : list) {675 // System.out.println(validationResult);676 List<String> v = validationResult.getError().getMessages();677 for (int i = 0; i < v.size(); i++) {678 // System.out.println(v.get(i));679 errors = errors.concat(v.get(i) + ",</br>");680 }681 }682 } catch (Exception e) {683 generateInfoReport(getException(e));684 }685 if (errors.length() > 0) {686 generateInfoReport("Find below galen validations<br>" + errors);687 } 688 generateInfoReport(" Spec Erros count is : " + layoutReport.errors());689 String reportLink = "<a target='_blank' href=\"./Galen_Reports/report.html\">"690 + "<b>Click here for galen report<b>" + "</a>";691 if (!layoutReport.getObjects().isEmpty()) {692 if (layoutReport.errors() > 0) {693 ExtentTestManager.getTest().log(LogStatus.WARNING, "Galen erros count:" + layoutReport.errors()694 + "<br>Report location:" + getBoldText(reportName));695 } else {696 generatePassReportWithNoScreenShot("No Galen spec failures" + "<br>Report location:" + reportName);697 }698 }else{699 generateFailReport("No specifications are passed, please check heat map or screenshot for more details ");700 }701 702 addScreenShotToReport(true);703 generateInfoReport(reportLink);704 // Add current url to report705 String currentURl = getDriver().getCurrentUrl();706 test.getReport().layout(layoutReport, fieldName + " - Current URL - " + currentURl);707 tests.add(test);708 Logs.info(" Generating galen reports .....");709 new HtmlReportBuilder().build(tests, reportName);710 // GalenPageDump dump = new GalenPageDump("Home Page");711 // dump.dumpPage(getDriver(), ReadProperties.projectLocation712 // +specFileLocation, ReadProperties.projectLocation + "Dump/");713 Logs.info(" Galen report location : " + reportName);714 } catch (Throwable e) {715 Logs.info("<br> Report location:" + reportName + "<br>Exception:<br>" + getException(e));716 ExtentTestManager.getTest().log(LogStatus.FAIL,717 "<br> Report location:" + reportName + "<br>Exception:<br>" + getException(e));718 test.getReport().error(getException(e));719 tests.add(test);720 Logs.info(" Generating galen reports .....");721 new HtmlReportBuilder().build(tests, reportName);722 Logs.info(" Galen report location : " + reportName);723 }724 } catch (Exception e) {725 generateInfoReport(getException(e));726 }727 return layoutReport;728 }729 public String get_Content_type(String url) throws IOException, InterruptedException {730 Document doc;731 String content_type = null;732 String pageSource = Jsoup.connect(url + "?faf=1&uac=79142PK").get().html();733 doc = Jsoup.parse(pageSource);734 Thread.sleep(5000);735 // get page title736 String title = doc.title();737 Logs.info("Title : " + title);738 // get all links739 try {740 Elements links = doc.select("meta[name=xml-type]");741 for (Element link : links) {742 // get the value from href attribute743 Logs.info("\n Content Type for :" + url + " is : " + link.attr("content"));744 content_type = link.attr("content");745 // Logs.info("text : " + link.text());746 }747 } catch (Exception e) {748 Logs.info(getException(e));749 }750 return content_type;751 }752 // getDriver() and screenshotName753 public String getScreenshot(WebDriver driver, String screenshotName) {754 if(driver==null){755 return "";756 }757 screenshotName = toUTF8(screenshotName);758 // after execution, you could see a folder "FailedTestsScreenshots"759 // under src folder760 String destination = null;761 try {762 // below line is just to append the date format with the screenshot763 // name to avoid duplicate names764 String dateName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());765 destination = "Screenshots/" + screenshotName + dateName + ".png";766 TakesScreenshot ts = (TakesScreenshot) driver;767 File source = ts.getScreenshotAs(OutputType.FILE);768 File finalDestination = new File(ExtentManager.getReportLocation() + "/" + destination);769 FileUtils.copyFile(source, finalDestination);770 } catch (Exception e) {771 e.printStackTrace();772 }773 return destination;774 }775 // getDriver() and screenshotName776 public String getScreenshot(WebDriver driver, String screenshotName, boolean takeFullScreenShot) {777 // after execution, you could see a folder "FailedTestsScreenshots"778 // under src folder779 String destination = null;780 if (screenShotDriver()==null || screenShotDriver().toString().contains("null")) {781 return "";782 }783 screenshotName = toUTF8(screenshotName);784 try {785 // below line is just to append the date format with the screenshot786 // name to avoid duplicate names787 String dateName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());788 destination = "Screenshots/" + screenshotName + dateName + ".png";789 try {790 File screens = new File(ExtentManager.getReportLocation() + "/Screenshots");791 if (!(screens.exists() && screens.isDirectory())) {792 screens.mkdirs();793 }794 } catch (Exception e) {795 e.printStackTrace();796 }797 File finalDestination = new File(ExtentManager.getReportLocation() + "/" + destination);798 Screenshot fpScreenshot = null;799 if (takeFullScreenShot) {800 fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000))801 .takeScreenshot(driver);802 } else {803 fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.simple()).takeScreenshot(driver);804 }805 ImageIO.write(fpScreenshot.getImage(), "PNG", finalDestination);806 System.out.println();807 } catch (Exception e) {808 // Logs.info(getException(e));809 }810 return destination;811 }812 public void generateReport(boolean status, String text) {813 generateReport(status, text,Boolean.parseBoolean(prop.getProperty("takeFullScreenShotOnFail").toLowerCase()));814 }815 private void generateReport(boolean status, String text, boolean takeFullScreenShot) {816 if (status) {817 ExtentTestManager.getTest().log(LogStatus.PASS, "Passed: " + text);818 Logs.info("Passed: " + text);819 if (prop.getProperty("takeScreenShotOnPass").equalsIgnoreCase("true")) {820 if (screenShotDriver() != null) {821 ExtentTestManager.getTest().log(LogStatus.INFO, ExtentTestManager.getTest()822 .addScreenCapture(getScreenshot(screenShotDriver(), String.valueOf(System.nanoTime()),takeFullScreenShot)));823 }824 }825 } else {826 Logs.error("Failed: " + text);827 ExtentTestManager.getTest().log(LogStatus.FAIL, "Failed: " + text);828 if (screenShotDriver() != null && getProperty("takeScreenShotOnFail").equalsIgnoreCase("true")) {829 ExtentTestManager.getTest().log(LogStatus.INFO, ExtentTestManager.getTest()830 .addScreenCapture(getScreenshot(screenShotDriver(), String.valueOf(System.nanoTime()), takeFullScreenShot)));831 }832 }833 }834 public void generateBoldReport(String text) {835 ExtentTestManager.getTest().log(LogStatus.INFO,836 "<b style=\"background: seagreen;color: white;\">" + text + "</b>");837 Logs.info(text);838 }839 public void setDescription(String text) {840 try {841 ExtentTestManager.getTest().setDescription(text);842 } catch (Exception e) {843 // e.printStackTrace();844 }845 }846 public void generateFailReport(String text) {847 Logs.error("Failed: " + text);848 ExtentTestManager.getTest().log(LogStatus.FAIL, "Failed -" + text);849 if (screenShotDriver() != null) {850 ExtentTestManager.getTest().log(LogStatus.FAIL, ExtentTestManager.getTest()851 .addScreenCapture(getScreenshot(screenShotDriver(), String.valueOf(System.nanoTime()), Boolean.parseBoolean(prop.getProperty("takeFullScreenShotOnFail").toLowerCase()))));852 }853 }854 public void addScreenShotToReport() {855 ExtentTestManager.getTest().log(LogStatus.INFO, ExtentTestManager.getTest()856 .addScreenCapture(getScreenshot(screenShotDriver(), String.valueOf(System.nanoTime()))));857 }858 public void addScreenShotToReport(boolean isFullScreen) {859 ExtentTestManager.getTest().log(LogStatus.INFO, ExtentTestManager.getTest()860 .addScreenCapture(getScreenshot(screenShotDriver(), String.valueOf(System.nanoTime()), isFullScreen)));861 }862 /**863 * generates pass or fail report based on flag status864 * 865 * @param text866 */867 public void generatePassReport(String text) {868 Logs.info("Passed: " + text);869 ExtentTestManager.getTest().log(LogStatus.PASS, text);870 if (prop.getProperty("takeScreenShotOnPass").equalsIgnoreCase("true")) {871 if (screenShotDriver() != null) {872 ExtentTestManager.getTest().log(LogStatus.INFO, ExtentTestManager.getTest()873 .addScreenCapture(getScreenshot(screenShotDriver(), String.valueOf(System.nanoTime()))));874 }875 }876 }877 /**878 * Return true if the object is visible in viewport879 * 880 * @param element881 * @return882 */883 public boolean isVisibleInViewport(WebElement element) {884 try {885 boolean b = (Boolean) ((JavascriptExecutor) ((RemoteWebElement) element).getWrappedDriver())886 .executeScript("var elem = arguments[0], " + "box = elem.getBoundingClientRect(),"887 + "cx = box.left + box.width / 2, " + "cy = box.top + box.height / 2, "...
Source:LayoutReport.java
...55 }56 public void setSections(List<LayoutSection> sections) {57 this.sections = sections;58 }59 public String getScreenshot() {60 return screenshot;61 }62 public void setScreenshot(String screenshot) {63 this.screenshot = screenshot;64 }65 public void setValidationErrorResults(List<ValidationResult> validationErrorResults) {66 this.validationErrorResults = validationErrorResults;67 }68 public int errors() {69 int errors = 0;70 if (validationErrorResults != null) {71 for (ValidationResult validationError : validationErrorResults) {72 if (!validationError.getError().isOnlyWarn()) {73 errors++;...
getScreenshot
Using AI Code Generation
1LayoutReport layoutReport = Galen.checkLayout(driver, "specs/1.spec", Arrays.asList("mobile"));2File screenshot = layoutReport.getScreenshot();3FileUtils.copyFile(screenshot, new File("1.png"));4LayoutReport layoutReport = Galen.checkLayout(driver, "specs/1.spec", Arrays.asList("mobile"));5File screenshot = layoutReport.getScreenshot();6FileUtils.copyFile(screenshot, new File("1.png"));7LayoutReport layoutReport = Galen.checkLayout(driver, "specs/1.spec", Arrays.asList("mobile"));8File screenshot = layoutReport.getScreenshot();9FileUtils.copyFile(screenshot, new File("1.png"));10LayoutReport layoutReport = Galen.checkLayout(driver, "specs/1.spec", Arrays.asList("mobile"));11File screenshot = layoutReport.getScreenshot();12FileUtils.copyFile(screenshot, new File("1.png"));13LayoutReport layoutReport = Galen.checkLayout(driver, "specs/1.spec", Arrays.asList("mobile"));14File screenshot = layoutReport.getScreenshot();15FileUtils.copyFile(screenshot, new File("1.png"));16LayoutReport layoutReport = Galen.checkLayout(driver, "specs/1.spec", Arrays.asList("mobile"));17File screenshot = layoutReport.getScreenshot();18FileUtils.copyFile(screenshot, new File("1.png"));19LayoutReport layoutReport = Galen.checkLayout(driver, "specs/1.spec", Arrays.asList("mobile"));20File screenshot = layoutReport.getScreenshot();21FileUtils.copyFile(screenshot, new File("1.png"));22LayoutReport layoutReport = Galen.checkLayout(driver, "specs/1.spec", Arrays.asList("mobile"));23File screenshot = layoutReport.getScreenshot();24FileUtils.copyFile(screenshot, new File("1.png"));
getScreenshot
Using AI Code Generation
1import java.io.File;2import java.io.IOException;3import java.net.URL;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.chrome.ChromeOptions;7import org.openqa.selenium.remote.DesiredCapabilities;8import org.openqa.selenium.remote.RemoteWebDriver;9import com.galenframework.reports.model.LayoutReport;10import com.galenframework.reports.model.LayoutReportBuilder;11import com.galenframework.reports.model.LayoutReportBuilder.LayoutReportBuilderListener;12import com.galenframework.reports.model.LayoutReportBuilder.LayoutReportBuilderListener.LayoutReportBuilderListenerEvent;13import com.galenframework.reports.model.LayoutReportBuilder.LayoutReportBuilderListener.LayoutReportBuilderListenerEvent.LayoutReportBuilderListenerEventKind;14import com.galenframework.reports.model.LayoutReportBuilder.LayoutReportBuilderListener.LayoutReportBuilderListenerEvent.LayoutReportBuilderListenerEventState;15import com.galenframework.reports.model.LayoutReportBuilder.LayoutReportBuilderListener.LayoutReportBuilderListenerEvent.LayoutReportBuilderListenerEventState.LayoutReportBuilderListenerEventStateKind;16import com.galenframework.reports.model.LayoutReportBuilder.LayoutReportBuilderListener.LayoutReportBuilderListenerEvent.LayoutReportBuilderListenerEventState.LayoutReportBuilderListenerEventStateKind.LayoutReportBuilderListenerEventStateKindKind;17import com.galenframework.reports.model.LayoutReportBuilder.LayoutReportBuilderListener.LayoutReportBuilderListenerEvent.LayoutReportBuilderListenerEventState.LayoutReportBuilderListenerEventStateKind.LayoutReportBuilderListenerEventStateKindKind.LayoutReportBuilderListenerEventStateKindKindKind;18import com.galenframework.reports.model.LayoutReportBuilder.LayoutReportBuilderListener.LayoutReportBuilderListenerEvent.LayoutReportBuilderListenerEventState.LayoutReportBuilderListenerEventStateKind.LayoutReportBuilderListenerEventStateKindKind.LayoutReportBuilderListenerEventStateKindKindKind.LayoutReportBuilderListenerEventStateKindKindKindKind;19import com.galenframework.reports.model.LayoutReportBuilder.LayoutReportBuilderListener.LayoutReportBuilderListenerEvent.LayoutReportBuilderListenerEventState.LayoutReportBuilderListenerEventStateKind.LayoutReportBuilderListenerEventStateKindKindKind;20import com.galenframework.reports.model.LayoutReportBuilder.LayoutReportBuilderListener.LayoutReportBuilderListenerEvent.LayoutReportBuilderListenerEventState.LayoutReportBuilderListenerEventStateKindKindKind.LayoutReportBuilderListenerEventStateKindKindKindKind;21import com.galenframework.reports.model.LayoutReportBuilder.LayoutReportBuilderListener.LayoutReportBuilderListenerEvent.LayoutReportBuilderListenerEventState.LayoutReportBuilderListenerEventStateKindKindKindKind.LayoutReportBuilderListenerEventStateKindKindKind
getScreenshot
Using AI Code Generation
1LayoutReport layoutReport = Galen.checkLayout(driver, "specs/1.spec", Arrays.asList("desktop"));2File screenshot = layoutReport.getScreenshot();3FileUtils.copyFile(screenshot, new File("screenshot.png"));4LayoutReport layoutReport = Galen.checkLayout(driver, "specs/1.spec", Arrays.asList("desktop"));5File screenshot = layoutReport.getScreenshot();6byte[] screenshotBytes = FileUtils.readFileToByteArray(screenshot);7testReport.embed(screenshotBytes, "image/png");8public void testLayout() throws IOException {9 LayoutReport layoutReport = Galen.checkLayout(driver, "specs/1.spec", Arrays.asList("desktop"));10 File screenshot = layoutReport.getScreenshot();11 byte[] screenshotBytes = FileUtils.readFileToByteArray(screenshot);12 Reporter.log("Screenshot", true);13 Reporter.log("<img src='data:image/png;base64," + Base64.getEncoder().encodeToString(screenshotBytes) + "'/>", true);14}15public void testLayout() throws IOException {16 LayoutReport layoutReport = Galen.checkLayout(driver, "specs/1.spec", Arrays.asList("desktop"));17 File screenshot = layoutReport.getScreenshot();18 byte[] screenshotBytes = FileUtils.readFileToByteArray(screenshot);19 Reporter.log("Screenshot", true);20 Reporter.log("<img src='data:image/png;base64," + Base64.getEncoder().encodeToString(screenshotBytes) + "'/>", true);21}22public void testLayout() throws IOException {23 LayoutReport layoutReport = Galen.checkLayout(driver, "specs/1.spec", Arrays.asList("desktop"));24 File screenshot = layoutReport.getScreenshot();
getScreenshot
Using AI Code Generation
1package com.galenframework.reports;2import com.galenframework.reports.model.LayoutReport;3import com.galenframework.reports.model.LayoutReportBuilder;4import com.galenframework.speclang2.pagespec.SectionFilter;5import com.galenframework.speclang2.pagespec.SectionFilters;6import com.galenframework.validation.ValidationError;7import com.galenframework.validation.ValidationObject;8import com.galenframework.validation.ValidationResult;9import com.galenframework.validation.ValidationResults;10import com.galenframework.validation.ValidationError.ErrorType;11import com.galenframework.validation.ValidationObject.ValidationObjectKind;12import com.galenframework.validation.ValidationResults.ValidationResultsKind;13import com.galenframework.validation.ValidationResults.ValidationResultsStatus;14import com.galenframework.validation.ValidationErrorLevel;15import com.galenframework.validation.ValidationListener;16import com.galenframework.validation.ValidationListener.ValidationListenerType;17import com.galenframework.validation.ValidationErrorException;18import com.galenframework.browser.SeleniumBrowser;19import com.galenframework.browser.Browser;20import com.galenframework.browser.SeleniumBrowserFactory;21import com.galenframework.browser.SeleniumBrowserFactory.SeleniumBrowserType;22import com.galenframework.browser.SeleniumBrowserFactory.SeleniumDriverType;23import com.galenframework.browser.SeleniumBrowserFactory.SeleniumGridType;24import com.galenframework.browser.SeleniumBrowserFactory.SeleniumRemoteDriverType;25import com.galenframework.validation.LayoutValidation;26import com.galenframework.validation.ValidationListener;27import com.galenframework.validation.ValidationListener.ValidationListenerType;28import com.galenframework.validation.ValidationErrorLevel;29import com.galenframework.validation.ValidationError;30import com.galenframework.validation.ValidationError.ErrorType;31import com.galenframework.validation.ValidationObject;32import com.galenframework.validation.ValidationObject.ValidationObjectKind;33import com.galenframework.validation.ValidationResult;34import com.galenframework.validation.ValidationResults;35import com.galenframework.validation.ValidationResults.ValidationResultsKind;36import com.galenframework.validation.ValidationResults.ValidationResultsStatus;37import com.galenframework.validation.ValidationListener;38import com.galenframework.validation.ValidationListener.ValidationListenerType;39import com.galenframework.validation.ValidationErrorLevel;40import com.galenframework.validation.ValidationError;41import com.galenframework.validation.ValidationError.ErrorType;42import com.galenframework.validation.ValidationObject;43import com.galenframework.validation.ValidationObject.ValidationObjectKind;44import com.galenframework.validation.ValidationResult;45import com.galenframework.validation.ValidationResults;46import com.galenframework.validation.Validation
getScreenshot
Using AI Code Generation
1import java.io.File;2import java.io.IOException;3import org.openqa.selenium.OutputType;4import org.openqa.selenium.TakesScreenshot;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.firefox.FirefoxDriver;7import org.testng.annotations.Test;8import com.galenframework.reports.model.LayoutReport;9import com.google.common.io.Files;10public class GetScreenshot {11 public void test() throws IOException {12 WebDriver driver = new FirefoxDriver();13 LayoutReport layoutReport = new LayoutReport();14 File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);15 layoutReport.setScreenshotImage(Files.toByteArray(screenshot));16 Files.copy(screenshot, new File("screenshot.png"));17 }18}19import java.io.File;20import java.io.IOException;21import org.openqa.selenium.OutputType;22import org.openqa.selenium.TakesScreenshot;23import org.openqa.selenium.WebDriver;24import org.openqa.selenium.firefox.FirefoxDriver;25import org.testng.annotations.Test;26import com.galenframework.reports.model.LayoutReport;27import com.google.common.io.Files;28public class GetScreenshot {29 public void test() throws IOException {30 WebDriver driver = new FirefoxDriver();31 LayoutReport layoutReport = new LayoutReport();32 File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);33 layoutReport.setScreenshotImage(Files.toByteArray(screenshot));34 Files.copy(screenshot, new File("screenshot.png"));35 }36}37import java
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!