How to use specImage method of com.galenframework.tests.validation.ImageValidationTest class

Best Galen code snippet using com.galenframework.tests.validation.ImageValidationTest.specImage

Source:ImageValidationTest.java Github

copy

Full Screen

...43 @DataProvider44 @Override45 public Object[][] provideGoodSamples() {46 return new Object[][] {47 {specImage(asList("/imgs/button-sample-correct.png"), 1, PIXEL_UNIT, 0, 5), page(new HashMap<String, PageElement>(){{48 put("object", element(100, 90, 100, 40));49 }}, imageComparisonTestScreenshot)},50 {specImage(asList("/imgs/page-sample-correct.png"), 2, PIXEL_UNIT, 0, 5, new Rect(40, 40, 100, 40)), page(new HashMap<String, PageElement>() {{51 put("object", element(100, 90, 100, 40));52 }}, imageComparisonTestScreenshot)},53 {specImage(asList("/imgs/button-sample-incorrect.png", "/imgs/button-sample-correct.png"), 1, PIXEL_UNIT, 0, 5), page(new HashMap<String, PageElement>(){{54 put("object", element(100, 90, 100, 40));55 }}, imageComparisonTestScreenshot)},56 {specImage(asList("/imgs/button-sample-*.png"), 1, PIXEL_UNIT, 0, 5), page(new HashMap<String, PageElement>(){{57 put("object", element(100, 90, 100, 40));58 }}, imageComparisonTestScreenshot)},59 };60 }61 @DataProvider62 @Override63 public Object[][] provideBadSamples() {64 return new Object[][] {65 {validationResult(NO_AREA, messages("\"object\" is absent on page")),66 specImage(asList("/imgs/button-sample-incorrect.png"), 2.0, true, 0, 10), page(new HashMap<String, PageElement>(){{67 put("object", absentElement(10, 10, 400, 300));68 }}, testImage)},69 {validationResult(NO_AREA, messages("\"object\" is not visible on page")),70 specImage(asList("/imgs/button-sample-incorrect.png"), 2.0, true, 0, 10), page(new HashMap<String, PageElement>(){{71 put("object", invisibleElement(10, 10, 400, 300));72 }}, testImage)},73 {new ValidationResult(NO_SPEC, areas(new ValidationObject(new Rect(100, 90, 100, 40), "object")),74 new ValidationError(messages("Element does not look like \"/imgs/button-sample-incorrect.png\". " +75 "There are 3820 mismatching pixels but max allowed is 600"))),76 specImage(asList("/imgs/button-sample-incorrect.png"), 600, PIXEL_UNIT, 0, 10), page(new HashMap<String, PageElement>() {{77 put("object", element(100, 90, 100, 40));78 }}, imageComparisonTestScreenshot)},79 {new ValidationResult(NO_SPEC, areas(new ValidationObject(new Rect(100, 90, 100, 40), "object")),80 new ValidationError(messages("Element does not look like \"/imgs/button-sample-incorrect.png\". " +81 "There are 95.5% mismatching pixels but max allowed is 2%"))),82 specImage(asList("/imgs/button-sample-incorrect.png"), 2.0, PERCENTAGE_UNIT, 0, 10), page(new HashMap<String, PageElement>() {{83 put("object", element(100, 90, 100, 40));84 }}, imageComparisonTestScreenshot)},85 {new ValidationResult(NO_SPEC, areas(new ValidationObject(new Rect(100, 90, 100, 40), "object")),86 new ValidationError(messages("Couldn't load image: /imgs/undefined-image.png"))),87 specImage(asList("/imgs/undefined-image.png"), 1.452, PERCENTAGE_UNIT, 0, 10), page(new HashMap<String, PageElement>() {{88 put("object", element(100, 90, 100, 40));89 }}, imageComparisonTestScreenshot)}90 };91 }92 @Test93 public void imageSpec_shouldAlsoGenerate_imageComparisonMap() {94 MockedPage page = page(new HashMap<String, PageElement>() {{95 put("object", element(100, 90, 100, 40));96 }}, imageComparisonTestScreenshot);97 PageSpec pageSpec = createMockedPageSpec(page);98 PageValidation validation = new PageValidation(null, page, pageSpec, null, null);99 ValidationError error = validation.check("object", specImage(asList("/imgs/button-sample-incorrect.png"), 0, PIXEL_UNIT, 0, 10)).getError();100 assertThat("Comparison map should not be null", error.getImageComparison().getComparisonMap(), is(notNullValue()));101 }102 private SpecImage specImage(List<String> imagePaths, double errorValue, boolean isPixelUnit, int pixelSmooth, int tolerance) {103 return specImage(imagePaths, errorValue, isPixelUnit, pixelSmooth, tolerance, null);104 }105 private SpecImage specImage(List<String> imagePaths, double errorValue, boolean isPixelUnit, int blur, int tolerance, Rect selectedArea) {106 SpecImage spec = new SpecImage();107 if (isPixelUnit) {108 spec.setErrorRate(new SpecImage.ErrorRate(errorValue, SpecImage.ErrorRateType.PIXELS));109 }110 else {111 spec.setErrorRate(new SpecImage.ErrorRate(errorValue, SpecImage.ErrorRateType.PERCENT));112 }113 spec.setImagePaths(imagePaths);114 List<ImageFilter> filters = new LinkedList<>();115 spec.setOriginalFilters(filters);116 spec.setSampleFilters(filters);117 if (blur > 0) {118 filters.add(new BlurFilter(blur));119 }...

Full Screen

Full Screen

specImage

Using AI Code Generation

copy

Full Screen

1 public void shouldValidateImage() throws IOException {2 Object[][] specs = {3 {"specs/spec1.spec", "specs/spec1.png", "specs/spec1.result"},4 {"specs/spec2.spec", "specs/spec2.png", "specs/spec2.result"},5 {"specs/spec3.spec", "specs/spec3.png", "specs/spec3.result"},6 {"specs/spec4.spec", "specs/spec4.png", "specs/spec4.result"},7 {"specs/spec5.spec", "specs/spec5.png", "specs/spec5.result"},8 {"specs/spec6.spec", "specs/spec6.png", "specs/spec6.result"},9 {"specs/spec7.spec", "specs/spec7.png", "specs/spec7.result"},10 {"specs/spec8.spec", "specs/spec8.png", "specs/spec8.result"},11 {"specs/spec9.spec", "specs/spec9.png", "specs/spec9.result"},12 {"specs/spec10.spec", "specs/spec10.png", "specs/spec10.result"},13 {"specs/spec11.spec", "specs/spec11.png", "specs/spec11.result"},14 {"specs/spec12.spec", "specs/spec12.png", "specs/spec12.result"},15 {"specs/spec13.spec", "specs/spec13.png", "specs/spec13.result"},16 {"specs/spec14.spec", "specs/spec14.png", "specs/spec14.result"},17 {"specs/spec15.spec", "specs/spec15.png", "specs/spec15.result"},18 {"specs/spec16.spec", "specs/spec16.png", "specs/spec16.result"},19 {"specs/spec17.spec", "specs/spec17.png", "specs/spec17.result"},20 {"specs/spec18.spec", "specs/spec18.png", "specs/spec18.result"},21 {"specs/spec19.spec", "specs/spec19.png", "specs/spec19.result"},22 {"specs/spec20.spec", "specs/spec20.png", "specs/spec20.result"},23 {"specs/spec21.spec", "specs/spec21.png", "specs/spec21.result"},24 {"specs/spec22.spec", "specs/spec22.png", "specs/spec22.result"},25 {"specs/spec23.spec", "specs/spec23.png", "specs/spec23.result"},26 {"specs/spec24.spec", "specs/spec24.png", "specs/spec24.result"},27 {"specs/spec25.spec", "specs/spec25.png", "specs/spec25.result"},28 {"specs

Full Screen

Full Screen

specImage

Using AI Code Generation

copy

Full Screen

1 @Test(dataProvider = "devices")2 public void specImageTest(String deviceName) throws IOException {3 load(deviceName);4 specImage("specImageTest.spec", "image");5 }6 @DataProvider(name = "devices")7 public Object[][] devices() {8 return new Object[][]{9 {"desktop"},10 {"tablet"},11 {"mobile"}12 };13 }14 private void load(String deviceName) {15 driver = new ChromeDriver();16 driver.manage().window().maximize();17 page = new HomePage(driver);18 device = new Device(deviceName);19 }20 private void specImage(String specName, String testName) throws IOException {21 GalenPageTest pageTest = new GalenPageTest(specName);22 pageTest.getReport().setReportDir("target/galen-reports");23 pageTest.getLayout(page, device, testName);24 GalenValidationListener validationListener = new GalenValidationListener();25 pageTest.getReport().addListener(validationListener);26 pageTest.getReport().getTest(testName).get().setGroupName(deviceName);27 if (validationListener.hasErrors()) {28 throw new RuntimeException("There are some errors in layout validation");29 }30 }31}32public class HomePage {33 private WebDriver driver;34 public HomePage(WebDriver driver) {35 this.driver = driver;36 }37 public void clickOnLink(String linkName) {38 driver.findElement(By.linkText(linkName)).click();39 }40 public void fillInSearchField(String text) {41 driver.findElement(By.id("search")).sendKeys(text);42 }43 public void clickOnSearchButton() {44 driver.findElement(By.id("searchButton")).click();45 }46 public void clickOnLogo() {47 driver.findElement(By.id("logo")).click();48 }49 public void clickOnAddToCartButton() {50 driver.findElement(By.id("addToCartButton")).click();51 }52 public void clickOnBackToHomeButton() {53 driver.findElement(By.id("backToHomeButton")).click();54 }55 public void clickOnCheckoutButton() {56 driver.findElement(By.id("checkoutButton")).click();57 }58 public void clickOnDeleteButton() {59 driver.findElement(By.id("deleteButton")).click();60 }

Full Screen

Full Screen

specImage

Using AI Code Generation

copy

Full Screen

1 def "should allow to validate image with specImage method"() {2 def spec = new SpecReader().read("spec/specImage.gspec")3 def image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB)4 def graphics = image.createGraphics()5 graphics.setColor(Color.WHITE)6 graphics.fillRect(0, 0, 200, 200)7 graphics.setColor(Color.BLACK)8 graphics.drawString("Hello", 10, 10)9 graphics.dispose()10 def result = new Galen().checkLayout(image, spec, null)11 result.errors.isEmpty()12 }13 def "should allow to validate image with specImage method using spec with variables"() {14 def spec = new SpecReader().read("spec/specImageWithVariables.gspec")15 def image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB)16 def graphics = image.createGraphics()17 graphics.setColor(Color.WHITE)18 graphics.fillRect(0, 0, 200, 200)19 graphics.setColor(Color.BLACK)20 graphics.drawString("Hello", 10, 10)21 graphics.dispose()22 def result = new Galen().checkLayout(image, spec, null)23 result.errors.isEmpty()24 }25 def "should allow to validate image with specImage method using spec with variables and custom variables"() {26 def spec = new SpecReader().read("spec/specImageWithVariables.gspec")27 def image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB)28 def graphics = image.createGraphics()29 graphics.setColor(Color.WHITE)30 graphics.fillRect(0, 0, 200, 200)31 graphics.setColor(Color.BLACK)32 graphics.drawString("Hello", 10, 10)33 graphics.dispose()34 def variables = new HashMap<String, String>()35 variables.put("customVariable", "20px")36 def result = new Galen().checkLayout(image, spec, variables)37 result.errors.isEmpty()38 }39 def "should allow to validate image with specImage method using spec with variables and custom variables and custom filter"() {40 def spec = new SpecReader().read("spec/specImageWithVariables.gspec")41 def image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB)

Full Screen

Full Screen

specImage

Using AI Code Generation

copy

Full Screen

1import com.galenframework.testng.GalenTestNgTestBase;2import com.galenframework.validation.ValidationResult;3import org.testng.annotations.Test;4import java.io.IOException;5import static com.galenframework.tests.GalenTestBase.load;6import static com.galenframework.validation.ImageValidation.*;7import static org.hamcrest.MatcherAssert.assertThat;8import static org.hamcrest.Matchers.is;9public class ImageValidationTest extends GalenTestNgTestBase {10 public void shouldValidateImage() throws IOException {11 String specFilePath = "specImage.spec";12 String imageFilePath = "specImage.png";13 ValidationResult result = specImage(load(specFilePath), load(imageFilePath));14 assertThat(result.getErrorCount(), is(0));15 }16 public void shouldValidateImage_inside() throws IOException {17 String specFilePath = "specImage.spec";18 String imageFilePath = "specImage.png";19 ValidationResult result = specImage_inside(load(specFilePath

Full Screen

Full Screen

specImage

Using AI Code Generation

copy

Full Screen

1specImage("area1", "image1", 10, "Image is not matched");2specImage("area2", "image2", 10, "Image is not matched");3specImage("area3", "image3", 10, "Image is not matched");4specImage("area1", "image1", 10, "Image is not matched");5specImage("area2", "image2", 10, "Image is not matched");6specImage("area3", "image3", 10, "Image is not matched");7specImage("area1", "image1", 10, "Image is not matched");8specImage("area2", "image2", 10, "Image is not matched");9specImage("area3", "image3", 10, "Image is not matched");

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful