How to use check method of com.galenframework.validation.specs.SpecValidationOcr class

Best Galen code snippet using com.galenframework.validation.specs.SpecValidationOcr.check

Source:SpecValidationOcr.java Github

copy

Full Screen

...35 public SpecValidationOcr(OcrService ocrService) {36 this.ocrService = ocrService;37 }38 @Override39 public ValidationResult check(PageValidation pageValidation, String objectName, SpecOcr spec) throws ValidationErrorException {40 PageElement mainObject = pageValidation.findPageElement(objectName);41 42 checkAvailability(mainObject, objectName);43 44 Rect area = mainObject.getArea();45 BufferedImage img = pageValidation.getPage().getScreenshotImage();46 OcrResult ocrResult = ocrService.findOcrText(img, area);47 if (ocrResult.getText() == null) {48 ocrResult.setText("");49 }50 String realText = applyOperationsTo(ocrResult.getText().trim(), spec.getOperations());51 checkValue(spec, objectName, realText, "text", ocrResult.getRect());52 return new ValidationResult(spec, asList(new ValidationObject(ocrResult.getRect(), objectName)));53 }54 private String applyOperationsTo(String text, List<String> operations) {55 if (operations != null) {56 for (String operation : operations) {57 text = TextOperation.find(operation).apply(text);58 }59 }60 return text;61 }62 protected void checkValue(SpecOcr spec, String objectName, String realText, String checkEntity, Rect area) throws ValidationErrorException {63 if (spec.getType() == SpecOcr.Type.IS) {64 checkIs(objectName, area, realText, spec.getText(), checkEntity);65 }66 if (spec.getType() == SpecOcr.Type.CONTAINS) {67 checkContains(objectName, area, realText, spec.getText(), checkEntity);68 }69 else if (spec.getType() == SpecOcr.Type.STARTS) {70 checkStarts(objectName, area, realText, spec.getText(), checkEntity);71 }72 else if (spec.getType() == SpecOcr.Type.ENDS) {73 checkEnds(objectName, area, realText, spec.getText(), checkEntity);74 }75 else if (spec.getType() == SpecOcr.Type.MATCHES) {76 checkMatches(objectName, area, realText, spec.getText(), checkEntity);77 }78 }79 protected void checkIs(String objectName, Rect area, String realText, String text, String checkEntity) throws ValidationErrorException {80 if(realText.equals(text)){81 return;82 }83 throw new ValidationErrorException(asList(new ValidationObject(area, objectName)), asList(format("\"%s\" %s is \"%s\" but should be \"%s\"", objectName, checkEntity, realText, text)));84 }85 protected void checkStarts(String objectName, Rect area, String realText, String text, String checkEntity) throws ValidationErrorException {86 if (!realText.startsWith(text)) {87 throw new ValidationErrorException(asList(new ValidationObject(area, objectName)), asList(format("\"%s\" %s is \"%s\" but should start with \"%s\"", objectName, checkEntity, realText, text)));88 }89 }90 91 protected void checkEnds(String objectName, Rect area, String realText, String text, String checkEntity) throws ValidationErrorException {92 if (!realText.endsWith(text)) {93 throw new ValidationErrorException(asList(new ValidationObject(area, objectName)), asList(format("\"%s\" %s is \"%s\" but should end with \"%s\"", objectName, checkEntity, realText, text)));94 }95 }96 97 protected void checkMatches(String objectName, Rect area, String realText, String text, String checkEntity) throws ValidationErrorException {98 Pattern regex = Pattern.compile(text, Pattern.DOTALL);99 if (!regex.matcher(realText).matches()) {100 throw new ValidationErrorException(asList(new ValidationObject(area, objectName)), asList(format("\"%s\" %s is \"%s\" but should match \"%s\"", objectName, checkEntity, realText, text)));101 }102 }103 protected void checkContains(String objectName, Rect area, String realText, String text, String checkEntity) throws ValidationErrorException {104 if (!realText.contains(text)) {105 throw new ValidationErrorException(asList(new ValidationObject(area, objectName)), asList(format("\"%s\" %s is \"%s\" but should contain \"%s\"", objectName, checkEntity, realText, text)));106 }107 }108 109}...

Full Screen

Full Screen

Source:OcrValidationTest.java Github

copy

Full Screen

...46 private final OcrService ocrService = mock(OcrService.class);47 private final SpecValidationOcr ocrValidation = new SpecValidationOcr(ocrService);48 private BufferedImage fakeScreenshot = loadTestImage("/imgs/page-screenshot.png");49 @Test50 public void should_fail_check_when_text_is_different() throws Exception {51 when(ocrService.findOcrText(any(), any())).thenReturn(52 new OcrResult(" Real text \n ", new Rect(0,0, 100, 50))53 );54 SpecOcr spec = new SpecOcr(SpecOcr.Type.IS, "Expected text");55 MockedPage page = createMockedPage();56 PageSpec pageSpec = createMockedPageSpec(page);57 PageValidation pageValidation = new PageValidation(null, page, pageSpec, null, null);58 try {59 ocrValidation.check(pageValidation, "button", spec);60 throw new RuntimeException("It didn't throw exception but should");61 } catch(ValidationErrorException ex) {62 assertThat(ex.getErrorMessages(), is(asList("\"button\" text is \"Real text\" but should be \"Expected text\"")));63 }64 verify(ocrService).findOcrText(anyObject(), eq(new Rect(0, 0, 100, 50)));65 }66 private PageSpec createMockedPageSpec(MockedPage page) {67 PageSpec pageSpec = new PageSpec();68 for (String objectName : page.getElements().keySet()) {69 pageSpec.getObjects().put(objectName, new Locator("id", objectName));70 }71 return pageSpec;72 }73 private MockedPage createMockedPage() {...

Full Screen

Full Screen

check

Using AI Code Generation

copy

Full Screen

1package com.galenframework.validation.specs;2import com.galenframework.specs.Spec;3import com.galenframework.specs.SpecValidationOcr;4import com.galenframework.validation.ValidationObject;5import com.galenframework.validation.ValidationResult;6import com.galenframework.validation.ValidationResultListener;7import com.galenframework.validation.ValidationResultListenerFactory;8import com.galenframework.validation.Validator;9import com.galenframework.validation.ValidatorFactory;10import com.galenframework.validation.ValidationObject;11import com.galenframework.validation.ValidationResult;12import com.galenframework.validation.ValidationResultListener;13import com.galenframework.validation.ValidationResultListenerFactory;14import com.galenframework.validation.Validator;15import com.galenframework.validation.ValidatorFactory;16public class SpecValidationOcrCheck {17 public static void main(String[] args) throws Exception {18 SpecValidationOcr specValidationOcr = new SpecValidationOcr();19 specValidationOcr.setOcrText("test");20 Spec spec = specValidationOcr;21 String pageName = "test";22 String objectName = "test";23 ValidationObject validationObject = new ValidationObject(pageName, objectName, null);24 ValidationResultListenerFactory listenerFactory = new ValidationResultListenerFactory();25 ValidationResultListener listener = listenerFactory.getListener();26 ValidatorFactory validatorFactory = new ValidatorFactory();27 Validator validator = validatorFactory.getValidator(spec);28 ValidationResult validationResult = validator.check(validationObject, spec, listener);29 System.out.println(validationResult.isPassed());30 }31}32package com.galenframework.validation.specs;33import com.galenframework.specs.Spec;34import com.galenframework.specs.SpecValidationOcr;35import com.galenframework.validation.ValidationObject;36import com.galenframework.validation.ValidationResult;37import com.galenframework.validation.ValidationResultListener;38import com.galenframework.validation.ValidationResultListenerFactory;39import com.galenframework.validation.Validator;40import com.galenframework.validation.ValidatorFactory;41import com.galenframework.validation.ValidationObject;42import com.galenframework.validation.ValidationResult;43import com.galenframework.validation.ValidationResultListener;44import com.galenframework.validation.ValidationResultListenerFactory;45import com.galenframework.validation.Validator;46import com.galenframework.validation.ValidatorFactory;47public class SpecValidationOcrValidate {48 public static void main(String

Full Screen

Full Screen

check

Using AI Code Generation

copy

Full Screen

1import com.galenframework.api.Galen;2import com.galenframework.api.GalenPageDump;3import com.galenframework.browser.Browser;4import com.galenframework.browser.SeleniumBrowser;5import com.galenframework.components.validation.ValidationListener;6import com.galenframework.reports.TestReport;7import com.galenframework.reports.model.LayoutReport;8import com.galenframework.reports.model.LayoutReportBuilder;9import com.galenframework.reports.model.LayoutReportStatus;10import com.galenframework.reports.model.TestReportModel;11import com.galenframework.reports.model.TestReportStatus;12import com.galenframework.specs.Spec;13import com.galenframework.specs.SpecValidationOcr;14import com.galenframework.specs.page.Locator;15import com.galenframework.specs.page.PageSpec;16import com.galenframework.specs.page.PageSection;17import com.galenframework.specs.page.PageSectionFilter;18import com.galenframework.specs.page.PageSectionFilterType;19import com.galenframework.specs.page.PageSectionPart;20import com.galenframework.specs.page.PageSectionPartType;21import com.galenframework.specs.page.PageSectionPartType;22import com.galenframework.specs.page.PageSectionPartType;23import com.galenframework.suite.GalenPageTest;24import com.galenframework.suite.actions.GalenP

Full Screen

Full Screen

check

Using AI Code Generation

copy

Full Screen

1package galen.test;2import java.io.IOException;3import java.util.Arrays;4import java.util.List;5import com.galenframework.api.Galen;6import com.galenframework.browser.Browser;7import com.galenframework.browser.BrowserFactory;8import com.galenframework.browser.SeleniumBrowser;9import com.galenframework.reports.GalenTestInfo;10import com.galenframework.reports.model.LayoutReport;11import com.galenframework.specs.Spec;12import com.galenframework.specs.SpecValidationOcr;13import com.galenframework.specs.page.Locator;14import com.galenframework.specs.page.PageSection;15import com.galenframework.specs.reader.page.PageSectionFilter;16import com.galenframework.specs.reader.page.SectionFilter;17import com.galenframework.specs.reader.page.SectionFilterFactory;18import com.galenframework.specs.reader.page.SectionFilters;19import com.galenframework.specs.reader.page.SectionFiltersFactory;20import com.galenframework.specs.reader.page.SectionFiltersFactory.SectionFiltersFactoryBuilder;21import com.galenframework.specs.reader.page.SectionFiltersFactory.SectionFiltersFactoryBuilder.SectionFiltersFactoryBuilderLocator;22import com.galenframework.speclang2.pagespec.PageSpecReader;23import com.galenframework.speclang2.pagespec.SectionFilterReader;24import com.galenframework.validation.ValidationListener;25import com.galenframework.validation.ValidationObject;26import com.galenframework.validation.ValidationResult;27import com.galenframework.validation.ValidationResultListener;28import com.galenframework.validation.ValidationResultListener.ValidationResultListenerBuilder;29import org.openqa.selenium.WebDriver;30public class GalenTest {31 public static void main(String[] args) throws IOException {32 WebDriver driver = BrowserFactory.loadDriver("chrome");33 Browser browser = new SeleniumBrowser(driver);34 GalenTestInfo test = GalenTestInfo.fromString("Galen test");35 SectionFilterFactory sectionFilterFactory = new SectionFilterFactory();36 SectionFiltersFactory sectionFiltersFactory = new SectionFiltersFactory();37 SectionFiltersFactoryBuilder sectionFiltersFactoryBuilder = sectionFiltersFactory.newSectionFiltersFactoryBuilder();38 SectionFiltersFactoryBuilderLocator sectionFiltersFactoryBuilderLocator = sectionFiltersFactoryBuilder.newSectionFiltersFactoryBuilderLocator();39 SectionFilters sectionFilters = sectionFiltersFactoryBuilderLocator.newSectionFilters();40 SectionFilterReader sectionFilterReader = new SectionFilterReader();41 SectionFilter sectionFilter = sectionFilterReader.read(Arrays.asList("ocr"));

Full Screen

Full Screen

check

Using AI Code Generation

copy

Full Screen

1public class 1 {2 public static void main(String[] args) throws Exception {3 File file = new File("C:\\Users\\Dell\\Desktop\\test.png");4 BufferedImage image = ImageIO.read(file);5 Ocr ocr = new Ocr();6 ocr.setLanguage("eng");7 ocr.startEngine("eng", Ocr.SPEED_FASTEST);8 ocr.setImage(image);9 String text = ocr.recognize(new OcrCharacterOptions());10 SpecValidationOcr specValidationOcr = new SpecValidationOcr();11 specValidationOcr.setExpectedText("Test Image");12 boolean result = specValidationOcr.check(null, null, text);13 System.out.println(result);14 }15}

Full Screen

Full Screen

check

Using AI Code Generation

copy

Full Screen

1GalenPageDump pageDump = new GalenPageDump("pageName");2SpecValidationOcr specValidationOcr = new SpecValidationOcr();3String actualText = specValidationOcr.check(pageDump, new SpecOcr().withText("Hello World!"), null);4System.out.println("Actual Text: " + actualText);5GalenPageDump pageDump = new GalenPageDump("pageName");6SpecValidationOcr specValidationOcr = new SpecValidationOcr();7String actualText = specValidationOcr.check(pageDump, new SpecOcr().withText("Hello World!"), null);8System.out.println("Actual Text: " + actualText);9GalenPageDump pageDump = new GalenPageDump("pageName");10SpecValidationOcr specValidationOcr = new SpecValidationOcr();11String actualText = specValidationOcr.check(pageDump, new SpecOcr().withText("Hello World!"), null);12System.out.println("Actual Text: " + actualText);13GalenPageDump pageDump = new GalenPageDump("pageName");14SpecValidationOcr specValidationOcr = new SpecValidationOcr();15String actualText = specValidationOcr.check(pageDump, new SpecOcr().withText("Hello World!"), null);16System.out.println("Actual Text: " + actualText);17GalenPageDump pageDump = new GalenPageDump("pageName");18SpecValidationOcr specValidationOcr = new SpecValidationOcr();

Full Screen

Full Screen

check

Using AI Code Generation

copy

Full Screen

1package com.galenframework.java.official;2import com.galenframework.api.Galen;3import com.galenframework.browser.Browser;4import com.galenframework.browser.SeleniumBrowser;5import com.galenframework.java.official.support.GalenJavaExampleTestBase;6import com.galenframework.reports.model.LayoutR

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