How to use getBaseDirAbsolutePath method of com.qaprosoft.carina.core.foundation.report.ReportContext class

Best Carina code snippet using com.qaprosoft.carina.core.foundation.report.ReportContext.getBaseDirAbsolutePath

Source:ReportContext.java Github

copy

Full Screen

...524 String link = "";525 if (!Configuration.get(Parameter.REPORT_URL).isEmpty()) {526 link = String.format("%s/%d/artifacts", Configuration.get(Parameter.REPORT_URL), rootID);527 } else {528 link = String.format("file://%s/artifacts", getBaseDirAbsolutePath());529 }530 return link;531 }532 /**533 * Returns URL for test screenshot folder.534 * 535 * @return - URL for test screenshot folder.536 */537 public static String getTestScreenshotsLink() {538 String link = "";539 try {540 if (FileUtils.listFiles(ReportContext.getTestDir(), new String[] { "png" }, false).isEmpty()) {541 // no png screenshot files at all542 return link;543 }544 } catch (Exception e) {545 LOGGER.error("Exception during report directory scanning", e);546 }547 548 String test = testDirectory.get().getName().replaceAll("[^a-zA-Z0-9.-]", "_");549 550 if (!Configuration.get(Parameter.REPORT_URL).isEmpty()) {551 link = String.format("%s/%d/%s/report.html", Configuration.get(Parameter.REPORT_URL), rootID, test);552 } else {553 link = String.format("file://%s/%s/report.html", getBaseDirAbsolutePath(), test);554 }555 return link;556 }557 /**558 * Returns URL for test log.559 * @return - URL to test log folder.560 */561 public static String getTestLogLink() {562 String link = "";563 File testLogFile = new File(ReportContext.getTestDir() + "/" + "test.log");564 if (!testLogFile.exists()) {565 // no test.log file at all566 return link;567 }568 String test = testDirectory.get().getName().replaceAll("[^a-zA-Z0-9.-]", "_");569 if (!Configuration.get(Parameter.REPORT_URL).isEmpty()) {570 link = String.format("%s/%d/%s/test.log", Configuration.get(Parameter.REPORT_URL), rootID, test);571 } else {572 link = String.format("file://%s/%s/test.log", getBaseDirAbsolutePath(), test);573 }574 return link;575 }576 /**577 * Returns URL for cucumber report.578 * 579 * @return - URL to test log folder.580 */581 public static String getCucumberReportLink() {582 String folder = SpecialKeywords.CUCUMBER_REPORT_FOLDER;583 String subFolder = SpecialKeywords.CUCUMBER_REPORT_SUBFOLDER;584 String fileName = SpecialKeywords.CUCUMBER_REPORT_FILE_NAME;585 String link = "";586 if (!Configuration.get(Parameter.REPORT_URL).isEmpty()) {587 // remove report url and make link relative588 // link = String.format("./%d/report.html", rootID);589 String report_url = Configuration.get(Parameter.REPORT_URL);590 if (report_url.contains("n/a")) {591 LOGGER.error("Contains n/a. Replace it.");592 report_url = report_url.replace("n/a", "");593 }594 link = String.format("%s/%d/%s/%s/%s", report_url, rootID, folder, subFolder, fileName);595 } else {596 link = String.format("file://%s/%s/%s/%s", getBaseDirAbsolutePath(), folder, subFolder, fileName);597 }598 return link;599 }600 /**601 * Saves screenshot.602 * 603 * @param screenshot - {@link BufferedImage} file to save604 * 605 * @return - screenshot name.606 */607 public static String saveScreenshot(BufferedImage screenshot) {608 long now = System.currentTimeMillis();609 executor.execute(new ImageSaverTask(screenshot, String.format("%s/%d.png", getTestDir().getAbsolutePath(), now),610 Configuration.getInt(Parameter.BIG_SCREEN_WIDTH), Configuration.getInt(Parameter.BIG_SCREEN_HEIGHT)));611 return String.format("%d.png", now);612 }613 /**614 * Asynchronous image saver task.615 */616 private static class ImageSaverTask implements Runnable {617 private BufferedImage image;618 private String path;619 private Integer width;620 private Integer height;621 public ImageSaverTask(BufferedImage image, String path, Integer width, Integer height) {622 this.image = image;623 this.path = path;624 this.width = width;625 this.height = height;626 }627 @Override628 public void run() {629 try {630 if (width > 0 && height > 0) {631 BufferedImage resizedImage = Scalr.resize(image, Scalr.Method.BALANCED, Scalr.Mode.FIT_TO_WIDTH, width, height,632 Scalr.OP_ANTIALIAS);633 if (resizedImage.getHeight() > height) {634 resizedImage = Scalr.crop(resizedImage, resizedImage.getWidth(), height);635 }636 ImageIO.write(resizedImage, "PNG", new File(path));637 } else {638 ImageIO.write(image, "PNG", new File(path));639 }640 } catch (Exception e) {641 LOGGER.error("Unable to save screenshot: " + e.getMessage());642 }643 }644 }645 private static void copyGalleryLib() {646 File reportsRootDir = new File(System.getProperty("user.dir") + "/" + Configuration.get(Parameter.PROJECT_REPORT_DIRECTORY));647 if (!new File(reportsRootDir.getAbsolutePath() + "/gallery-lib").exists()) {648 try {649 InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(GALLERY_ZIP);650 if (is == null) {651 System.out.println("Unable to find in classpath: " + GALLERY_ZIP);652 return;653 }654 ZipManager.copyInputStream(is, new BufferedOutputStream(new FileOutputStream(reportsRootDir.getAbsolutePath() + "/"655 + GALLERY_ZIP)));656 ZipManager.unzip(reportsRootDir.getAbsolutePath() + "/" + GALLERY_ZIP, reportsRootDir.getAbsolutePath());657 File zip = new File(reportsRootDir.getAbsolutePath() + "/" + GALLERY_ZIP);658 zip.delete();659 } catch (Exception e) {660 System.out.println("Unable to copyGalleryLib! " + e);661 }662 }663 }664 public static void generateTestReport() {665 File testDir = testDirectory.get();666 try {667 List<File> images = FileManager.getFilesInDir(testDir);668 List<String> imgNames = new ArrayList<String>();669 for (File image : images) {670 imgNames.add(image.getName());671 }672 imgNames.remove("test.log");673 imgNames.remove("sql.log");674 if (imgNames.size() == 0)675 return;676 Collections.sort(imgNames);677 StringBuilder report = new StringBuilder();678 for (int i = 0; i < imgNames.size(); i++) {679 // convert toString680 String image = R.REPORT.get("image");681 image = image.replace("${image}", imgNames.get(i));682 String title = getScreenshotComment(imgNames.get(i));683 if (title == null) {684 title = "";685 }686 image = image.replace("${title}", StringUtils.substring(title, 0, MAX_IMAGE_TITLE));687 report.append(image);688 }689 // String wholeReport = R.REPORT.get("container").replace("${images}", report.toString());690 String wholeReport = R.REPORT.get("container").replace("${images}", report.toString());691 wholeReport = wholeReport.replace("${title}", TITLE);692 String folder = testDir.getAbsolutePath();693 FileManager.createFileWithContent(folder + REPORT_NAME, wholeReport);694 } catch (Exception e) {695 LOGGER.error("generateTestReport failure", e);696 }697 }698 /**699 * Stores comment for screenshot.700 *701 * @param screenId screenId id702 * @param msg message703 * 704 */705 public static void addScreenshotComment(String screenId, String msg) {706 if (!StringUtils.isEmpty(screenId)) {707 screenSteps.put(screenId, msg);708 }709 }710 /**711 * Return comment for screenshot.712 * 713 * @param screenId Screen Id714 * 715 * @return screenshot comment716 */717 public static String getScreenshotComment(String screenId) {718 String comment = "";719 if (screenSteps.containsKey(screenId))720 comment = screenSteps.get(screenId);721 return comment;722 }723 private static String getBaseDirAbsolutePath() {724 if (baseDirectory != null) {725 return baseDirectory.getAbsolutePath();726 }727 return null;728 }729 730 // Converting InputStream to String731 private static String readStream(InputStream in) {732 BufferedReader reader = null;733 StringBuffer response = new StringBuffer();734 try {735 reader = new BufferedReader(new InputStreamReader(in));736 String line = "";737 while ((line = reader.readLine()) != null) {...

Full Screen

Full Screen

getBaseDirAbsolutePath

Using AI Code Generation

copy

Full Screen

1String baseDir = ReportContext.getBaseDirAbsolutePath();2String baseDir = ReportContext.getBaseDirAbsolutePath();3String baseDir = ReportContext.getBaseDirAbsolutePath();4String baseDir = ReportContext.getBaseDirAbsolutePath();5String baseDir = ReportContext.getBaseDirAbsolutePath();6String baseDir = ReportContext.getBaseDirAbsolutePath();7String baseDir = ReportContext.getBaseDirAbsolutePath();8String baseDir = ReportContext.getBaseDirAbsolutePath();9String baseDir = ReportContext.getBaseDirAbsolutePath();10String baseDir = ReportContext.getBaseDirAbsolutePath();11String baseDir = ReportContext.getBaseDirAbsolutePath();12String baseDir = ReportContext.getBaseDirAbsolutePath();13String baseDir = ReportContext.getBaseDirAbsolutePath();14String baseDir = ReportContext.getBaseDirAbsolutePath();15String baseDir = ReportContext.getBaseDirAbsolutePath();

Full Screen

Full Screen

getBaseDirAbsolutePath

Using AI Code Generation

copy

Full Screen

1String path = ReportContext.getBaseDirAbsolutePath();2String path = ReportContext.getBaseDirAbsolutePath();3String path = ReportContext.getBaseDirAbsolutePath();4String path = ReportContext.getBaseDirAbsolutePath();5String path = ReportContext.getBaseDirAbsolutePath();6String path = ReportContext.getBaseDirAbsolutePath();7String path = ReportContext.getBaseDirAbsolutePath();8String path = ReportContext.getBaseDirAbsolutePath();9String path = ReportContext.getBaseDirAbsolutePath();10String path = ReportContext.getBaseDirAbsolutePath();11String path = ReportContext.getBaseDirAbsolutePath();12String path = ReportContext.getBaseDirAbsolutePath();13String path = ReportContext.getBaseDirAbsolutePath();14String path = ReportContext.getBaseDirAbsolutePath();15String path = ReportContext.getBaseDirAbsolutePath();

Full Screen

Full Screen

getBaseDirAbsolutePath

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.report.ReportContext;2String baseDirAbsolutePath = ReportContext.getBaseDirAbsolutePath();3System.out.println("Base dir absolute path: " + baseDirAbsolutePath);4import com.qaprosoft.carina.core.foundation.report.ReportContext;5String testName = ReportContext.getTestName();6System.out.println("Test name: " + testName);7import com.qaprosoft.carina.core.foundation.report.ReportContext;8String testMethodName = ReportContext.getTestMethodName();9System.out.println("Test method name: " + testMethodName);10import com.qaprosoft.carina.core.foundation.report.ReportContext;11String testDescription = ReportContext.getTestDescription();12System.out.println("Test description: " + testDescription);13import com.qaprosoft.carina.core.foundation.report.ReportContext;14String testId = ReportContext.getTestId();15System.out.println("Test id: " + testId);

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