How to use Rainbow4J class of com.galenframework.rainbow4j package

Best Galen code snippet using com.galenframework.rainbow4j.Rainbow4J

Source:ImageCompareFixture.java Github

copy

Full Screen

1package nl.praegus.fitnesse.slim.fixtures;2import com.galenframework.rainbow4j.ComparisonOptions;3import com.galenframework.rainbow4j.ImageCompareResult;4import com.galenframework.rainbow4j.Rainbow4J;5import javax.imageio.ImageIO;6import java.awt.Rectangle;7import java.awt.image.BufferedImage;8import java.io.File;9import java.io.IOException;10import java.text.SimpleDateFormat;11import java.util.ArrayList;12import java.util.List;13import nl.hsac.fitnesse.fixture.slim.SlimFixture;14import nl.hsac.fitnesse.fixture.slim.SlimFixtureException;15/**16 * Fixture to compare two images. Accepted file types: PNG, BMP, JPEG, GIF. Extends Slim fixture from17 * nl.hsac.fitnesse.fixture.slim package. Uses the rainbow4j library from the Galen project to perform image compare.18 */19public class ImageCompareFixture extends SlimFixture {20 private final ComparisonOptions comparisonOptions = new ComparisonOptions();21 private double acceptedDifferencePercentage = 0.0;22 private String comparisonMapFileFormat = "png";23 private List<Rectangle> ignoreRegions = new ArrayList<>();24 public void setAcceptedDifferencePercentage(double acceptedDifferencePercentage) {25 this.acceptedDifferencePercentage = acceptedDifferencePercentage;26 }27 public void setTolerance(int tolerance) {28 comparisonOptions.setTolerance(tolerance);29 }30 public void setComparisonMapFileFormat(String comparisonMapFileFormat) {31 this.comparisonMapFileFormat = comparisonMapFileFormat;32 }33 /**34 * Returns an image showing a heatmap of differences between two given images. Images given can be of PNG, BMP, JPEG35 * or GIF file format. The file format of the compared images might differ.36 *37 * @param baselineImagePath path of the image to be used as baseline to test an image against. Format is38 * url: http://files/example.png or39 * relative path: files/example.png or40 * absolute path : C:\Projects\someProject\wiki\FitNesseRoot\files\example.png41 * @param testImagePath the image to test against the given baseline42 * @return HTML link to the generate heatmap43 * @throws IOException when image can not be saved44 */45 public String differencesBetweenAnd(String baselineImagePath, String testImagePath) throws IOException {46 ImageCompareResult compareResult = compareImages(baselineImagePath, testImagePath);47 return getImageLink(saveComparisonMap(compareResult));48 }49 /**50 * Boolean indicating if two given images are visually equal (depending on set tolerance and accepted51 * difference percentage)52 *53 * @param baselineImagePath path of the image to be used as baseline to test an image against. Format is54 * url: http://files/example.png or55 * relative path: files/example.png or56 * absolute path : C:\Projects\someProject\wiki\FitNesseRoot\files\example.png57 * @param testImagePath the image to test against the given baseline58 * @return true when the two given images are visually equal59 * @throws IOException60 */61 public boolean imageIsEqualTo(String baselineImagePath, String testImagePath) throws IOException {62 boolean result = false;63 ImageCompareResult compareResult = compareImages(baselineImagePath, testImagePath);64 if (compareResult.getPercentage() <= acceptedDifferencePercentage) {65 result = true;66 }67 return result;68 }69 /**70 * Add a region to ignore.71 * A region is formatted as x, y, width, height in pixels. So 0,0,20,100 will ignore a region of 20x100px in the top left corner of the image72 * @param region a comma separated list of integers (x,y,width,height)73 */74 public void addExcludeRegion(String region) {75 String[] regionInfo = region.split(",");76 if(regionInfo.length != 4) {77 throw new SlimFixtureException(false, "A region consists of exactly 4 integers: x, y, width, height");78 }79 try {80 Rectangle newRegion = new Rectangle(Integer.parseInt(regionInfo[0].trim()),81 Integer.parseInt(regionInfo[1].trim()),82 Integer.parseInt(regionInfo[2].trim()),83 Integer.parseInt(regionInfo[3].trim()));84 ignoreRegions.add(newRegion);85 comparisonOptions.setIgnoreRegions(ignoreRegions);86 } catch (NumberFormatException e) {87 throw new SlimFixtureException(false, "A region consists of exactly 4 integers: x, y, width, height", e);88 }89 }90 /**91 * Compares two given images.92 *93 * @param baselineImagePath image to use as baseline for comparison94 * @param testImagePath image to test against baseline95 * @return comparison result object96 * @throws IOException if images can not be read97 */98 private ImageCompareResult compareImages(String baselineImagePath, String testImagePath) throws IOException {99 return Rainbow4J.compare(loadImageFromPath(baselineImagePath), loadImageFromPath(testImagePath), comparisonOptions);100 }101 /**102 * Creates BufferedImage from given path103 *104 * @param imagePath the path to the image to load105 * @return BufferedImage from image found on path106 * @throws IOException if image can not be read107 */108 private BufferedImage loadImageFromPath(String imagePath) throws IOException {109 String baselineImagePath = getFilePathFromWikiUrl(imagePath);110 BufferedImage image = Rainbow4J.loadImage(baselineImagePath);111 return image;112 }113 /**114 * Saves comparison map of a given image compare result to disk115 *116 * @param compareResult image compare result object117 * @return path of the saved comparison map118 * @throws IOException when saving fails119 */120 private String saveComparisonMap(ImageCompareResult compareResult) throws IOException {121 BufferedImage diffMap = compareResult.getComparisonMap();122 String imageName = getComparisonMapName();123 ImageIO.write(diffMap, "png", new File(imageName));124 return imageName;...

Full Screen

Full Screen

Source:Report.java Github

copy

Full Screen

...19import com.cognizant.cognizantits.engine.core.CommandControl;20import com.cognizant.cognizantits.engine.support.Status;21import com.fasterxml.jackson.core.JsonProcessingException;22import com.fasterxml.jackson.databind.ObjectMapper;23import com.galenframework.rainbow4j.Rainbow4J;24import com.galenframework.specs.Spec;25import com.galenframework.validation.ImageComparison;26import com.galenframework.validation.ValidationErrorException;27import com.galenframework.validation.ValidationObject;28import com.galenframework.validation.ValidationResult;29import java.awt.image.BufferedImage;30import java.io.File;31import java.io.IOException;32import java.util.ArrayList;33import java.util.Arrays;34import java.util.HashMap;35import java.util.List;36import java.util.Map;37import java.util.logging.Level;38import java.util.logging.Logger;39/**40 *41 * 42 */43public class Report extends Command {44 ObjectMapper obMapper = new ObjectMapper();45 public Report(CommandControl cc) {46 super(cc);47 }48 public void onSuccess(Spec spec, ValidationResult result) {49 ValidationErrorException exception = new ValidationErrorException().withValidationObjects(result.getValidationObjects()).withMessage(spec.toText());50 onResult(exception.asValidationResult(spec), Status.PASS);51 }52 public void onError(Spec spec, ValidationResult result) {53 if (result.getError().getImageComparison() != null) {54 onResult(result, Status.FAIL, saveImageComparison(result.getError().getImageComparison()));55 } else {56 onResult(result, Status.FAIL);57 }58 }59 public void onError(Exception ex) {60 Report.updateTestLog(Action, ex.getMessage(), Status.DEBUG);61 }62 private void onResult(ValidationResult result, Status status) {63 if (result.getError().getMessages() != null) {64 for (String message : result.getError().getMessages()) {65 Report.updateTestLog(Action, message, status, getObjectAreas(result.getValidationObjects()));66 }67 }68 }69 private void onResult(ValidationResult result, Status status, List<String> imageList) {70 if (result.getError().getMessages() != null) {71 for (String message : result.getError().getMessages()) {72 Report.updateTestLog(Action, message, status, imageList);73 }74 }75 }76 private List<String> getObjectAreas(List<ValidationObject> vObjects) {77 ArrayList<Map<String, String>> objectList = new ArrayList<>();78 if (vObjects != null) {79 for (ValidationObject vobject : vObjects) {80 if (vobject.getArea() != null) {81 Map<String, String> obMap = new HashMap<>();82 obMap.put("name", vobject.getName());83 obMap.put("area", "["84 + vobject.getArea().getLeft() + ","85 + vobject.getArea().getTop() + ","86 + vobject.getArea().getWidth() + ","87 + vobject.getArea().getHeight() + "]");88 objectList.add(obMap);89 }90 }91 }92 try {93 if (!objectList.isEmpty()) {94 return Arrays.asList(obMapper.writeValueAsString(objectList));95 }96 } catch (JsonProcessingException ex) {97 Logger.getLogger(Report.class.getName()).log(Level.SEVERE, null, ex);98 }99 return null;100 }101 private ArrayList<String> saveImageComparison(ImageComparison imageComparison) {102 ArrayList<String> imageList = new ArrayList<>();103 try {104 imageList.add(saveImageComparison(ObjectName + "-expected", Rainbow4J.loadImage(imageComparison.getSampleFilteredImage().getAbsolutePath())));105 imageList.add(saveImageComparison(ObjectName + "-actual", Rainbow4J.loadImage(imageComparison.getOriginalFilteredImage().getAbsolutePath())));106 imageList.add(saveImageComparison(ObjectName + "-map", Rainbow4J.loadImage(imageComparison.getComparisonMap().getAbsolutePath())));107 } catch (IOException e) {108 Logger.getLogger(Report.class.getName()).log(Level.SEVERE, null, e);109 }110 return imageList;111 }112 private String saveImageComparison(String name, BufferedImage image) {113 try {114 File file = new File(getImageName(name, 0));115 file.mkdirs();116 Rainbow4J.saveImage(image, file);117 return "./img" + File.separator + file.getName();118 } catch (IOException ex) {119 Logger.getLogger(Report.class.getName()).log(Level.SEVERE, null, ex);120 }121 return null;122 }123 private String getImageName(String name, int count) {124 String imageName = FilePath.getCurrentResultsPath() + File.separator + "img" + File.separator + name + count + ".png";125 File file = new File(imageName);126 if (file.exists()) {127 return getImageName(name, count++);128 }129 return imageName;130 }...

Full Screen

Full Screen

Rainbow4J

Using AI Code Generation

copy

Full Screen

1import com.galenframework.rainbow4j.Rainbow4J;2import org.openqa.selenium.chrome.ChromeDriver;3import org.openqa.selenium.chrome.ChromeOptions;4import org.openqa.selenium.remote.RemoteWebDriver;5import org.testng.annotations.Test;6import java.io.IOException;7import java.net.MalformedURLException;8import java.net.URL;9import java.util.HashMap;10import java.util.Map;11public class 1 {12 public static RemoteWebDriver driver;13 public void test1() throws IOException {14 ChromeOptions options = new ChromeOptions();15 options.addArguments("--headless");16 driver = new ChromeDriver(options);17 Rainbow4J rainbow4J = new Rainbow4J(driver);18 String specPath = "C:\\Users\\user\\Desktop\\Galen\\specfile.spec";19 String layoutPath = "C:\\Users\\user\\Desktop\\Galen\\layoutfile.layout";20 String pagePath = "C:\\Users\\user\\Desktop\\Galen\\pagefile.page";21 String javaScriptPath = "C:\\Users\\user\\Desktop\\Galen\\javascriptfile.js";22 String reportPath = "C:\\Users\\user\\Desktop\\Galen\\reportfile.html";23 String screenshotPath = "C:\\Users\\user\\Desktop\\Galen\\screenshotfile.png";24 String errorPath = "C:\\Users\\user\\Desktop\\Galen\\errorfile.html";25 String errorScreenshotPath = "C:\\Users\\user\\Desktop\\Galen\\errorScreenshotfile.png";26 String errorJavaScriptPath = "C:\\Users\\user\\Desktop\\Galen\\errorJavaScriptfile.js";

Full Screen

Full Screen

Rainbow4J

Using AI Code Generation

copy

Full Screen

1import com.galenframework.rainbow4j.Rainbow4J;2public class Rainbow4JTest {3public static void main(String[] args) throws Exception {4Rainbow4J rainbow4j = new Rainbow4J();5rainbow4j.setDriver("firefox");6rainbow4j.checkLayout("specs/homepage.spec", "desktop");7}8}9import com.galenframework.rainbow4j.Rainbow4J;10public class Rainbow4JTest {11public static void main(String[] args) throws Exception {12Rainbow4J rainbow4j = new Rainbow4J();13rainbow4j.setDriver("firefox");14rainbow4j.checkLayout("specs/homepage.spec", "desktop");15}16}17import com.galenframework.rainbow4j.Rainbow4J;18public class Rainbow4JTest {19public static void main(String[] args) throws Exception {20Rainbow4J rainbow4j = new Rainbow4J();21rainbow4j.setDriver("firefox");22rainbow4j.checkLayout("specs/homepage.spec", "desktop");23}24}25import com.galenframework.rainbow4j.Rainbow4J;26public class Rainbow4JTest {27public static void main(String[] args) throws Exception {

Full Screen

Full Screen

Rainbow4J

Using AI Code Generation

copy

Full Screen

1package com.galenframework.rainbow4j;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.chrome.ChromeDriver;4import org.openqa.selenium.chrome.ChromeOptions;5import org.testng.annotations.AfterTest;6import org.testng.annotations.BeforeTest;7import org.testng.annotations.Test;8import com.galenframework.rainbow4j.Rainbow4J;9import com.galenframework.rainbow4j.Rainbow4JTestBase;10import com.galenframework.rainbow4j.filters.*;11import com.galenframework.rainbow4j.layout.LayoutReport;12import com.galenframework.rainbow4j.layout.LayoutReportBuilder;13import com.galenframework.rainbow4j.layout.LayoutRepor

Full Screen

Full Screen

Rainbow4J

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.chrome.ChromeDriver;3import org.testng.annotations.AfterMethod;4import org.testng.annotations.BeforeMethod;5import org.testng.annotations.Test;6import java.io.IOException;7import java.net.MalformedURLException;8import java.net.URL;9import com.galenframework.rainbow4j.Rainbow4J;10import com.galenframework.rainbow4j.Rainbow4J;11import org.openqa.selenium.WebDriver;12import org.openqa.selenium.chrome.ChromeDriver;13import org.testng.annotations.AfterMethod;14import org.testng.annotations.BeforeMethod;15import org.testng.annotations.Test;16import java.io.IOException;17import java.net.MalformedURLException;18import java.net.URL;19import com.galenframework.rainbow4j.Rainbow4J;20import com.galenframework.rainbow4j.Rainbow4J;21import org.openqa.selenium.WebDriver;22import org.openqa.selenium.chrome.ChromeDriver;23import org.testng.annotations.AfterMethod;24import org.testng.annotations.BeforeMethod;25import org.testng.annotations.Test;26import java.io.IOException;27import java.net.MalformedURLException;28import java.net.URL;29import com.galenframework.rainbow4j.Rainbow4J;30import com.galenframework.rainbow4j.Rainbow4J;31import org.openqa.selenium.WebDriver;32import org.openqa.selenium.chrome.ChromeDriver;33import org.testng.annotations.AfterMethod;34import org.testng.annotations.BeforeMethod;35import org.testng.annotations.Test;36import java.io.IOException;37import java.net.MalformedURLException;38import java.net.URL;39import com.galenframework.rainbow4j.Rainbow4J;40import com.galenframework.rainbow4j.Rainbow4J;41import org.openqa.selenium.WebDriver;42import org.openqa.selenium.chrome.ChromeDriver;43import org.testng.annotations.AfterMethod;44import org.testng.annotations.BeforeMethod;45import org.testng.annotations.Test;46import java.io.IOException;47import java.net.MalformedURLException;48import java.net.URL;49import com.galenframework.rainbow4j.Rainbow4J;50import com.galenframework.rainbow4j.Rainbow4J;51import org.openqa.selenium.WebDriver;52import org.openqa.selenium.chrome.ChromeDriver;53import org.testng.annotations.AfterMethod;54import org.testng.annotations.BeforeMethod;55import org.testng.annotations.Test;56import java.io.IOException;57import java.net.MalformedURLException;58import java.net

Full Screen

Full Screen

Rainbow4J

Using AI Code Generation

copy

Full Screen

1package com.galenframework.rainbow4j;2import java.util.List;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;5public class Rainbow4JTest {6public static void main(String[] args) throws Exception {7 System.setProperty("webdriver.chrome.driver","C:\\Users\\Vishal\\Downloads\\chromedriver_win32\\chromedriver.exe");8 WebDriver driver = new ChromeDriver();9 List<SpecReport> specReports = Rainbow4J.checkLayout(driver, "specs\\sample.gspec", null, null, null);10 System.out.println("The number of spec reports are: "+specReports.size());11 driver.close();12}13}14In the above code, we have created a new object of the Rainbow4J class and called the checkLayout() method to run the test on the given page. The checkLayout() method has the following parameters:15The checkLayout() method returns a list of SpecReport objects. Each SpecReport object contains the information about the test case that was run. The following is the list of methods that can be used to get the information from the SpecReport object:16getBrowserSize(): This

Full Screen

Full Screen

Rainbow4J

Using AI Code Generation

copy

Full Screen

1import com.galenframework.rainbow4j.Rainbow4J;2public class 1 {3 public static void main(String[] args) {4 Rainbow4J rainbow4j = new Rainbow4J("rainbow4j");5 rainbow4j.setSpecPath("path of the Galen spec file");6 rainbow4j.setHtmlPath("path of the HTML file");7 rainbow4j.runTest();8 }9}10import com.galenframework.rainbow4j.Rainbow4J;11public class 2 {12 public static void main(String[] args) {13 Rainbow4J rainbow4j = new Rainbow4J("rainbow4j");14 rainbow4j.setSpecPath("path of the Galen spec file");15 rainbow4j.setHtmlPath("path of the HTML file");16 rainbow4j.setScreenshotPath("path of the screenshot file");17 rainbow4j.runTest();18 }19}20import com.galenframework.rainbow4j.Rainbow4J;21public class 3 {22 public static void main(String[] args) {23 Rainbow4J rainbow4j = new Rainbow4J("rainbow4j");24 rainbow4j.setSpecPath("path of the Galen spec file");25 rainbow4j.setHtmlPath("path of the HTML file");26 rainbow4j.setScreenshotPath("path of the screenshot file");

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.

Run Galen automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful