How to use getType method of com.galenframework.specs.SpecImage class

Best Galen code snippet using com.galenframework.specs.SpecImage.getType

Source:SpecsReaderV2Test.java Github

copy

Full Screen

...384 @Test385 public void shouldReadSpec_text_is_some_text() throws IOException {386 SpecText spec = (SpecText)readSpec("text is \"Some text\"");387 assertThat(spec.getText(), is("Some text"));388 assertThat(spec.getType(), is(SpecText.Type.IS));389 }390 @Test391 public void shouldReadSpec_text_is_some_text_2() throws IOException {392 SpecText spec = (SpecText)readSpec("text is \"Some text\\\" with \\t special \\n symbols\"");393 assertThat(spec.getText(), is("Some text\" with \t special \n symbols"));394 assertThat(spec.getType(), is(SpecText.Type.IS));395 }396 @Test397 public void shouldReadSpec_text_is_empty() throws IOException {398 SpecText spec = (SpecText)readSpec("text is \"\"");399 assertThat(spec.getText(), is(""));400 assertThat(spec.getType(), is(SpecText.Type.IS));401 }402 @Test403 public void shouldReadSpec_text_contains_some_text() throws IOException {404 SpecText spec = (SpecText)readSpec("text contains \"Some text\" ");405 assertThat(spec.getText(), is("Some text"));406 assertThat(spec.getType(), is(SpecText.Type.CONTAINS));407 }408 @Test409 public void shouldReadSpec_text_startsWith_some_text() throws IOException {410 SpecText spec = (SpecText)readSpec("text starts \"Some text\" ");411 assertThat(spec.getText(), is("Some text"));412 assertThat(spec.getType(), is(SpecText.Type.STARTS));413 }414 @Test415 public void shouldReadSpec_text_endssWith_some_text() throws IOException {416 SpecText spec = (SpecText)readSpec("text ends \"Some text\" ");417 assertThat(spec.getText(), is("Some text"));418 assertThat(spec.getType(), is(SpecText.Type.ENDS));419 }420 @Test421 public void shouldReadSpec_text_matches_some_text() throws IOException {422 SpecText spec = (SpecText)readSpec("text matches \"Some * text\" ");423 assertThat(spec.getText(), is("Some * text"));424 assertThat(spec.getType(), is(SpecText.Type.MATCHES));425 }426 @Test427 public void shouldReadSpec_text_lowercase_is() throws IOException {428 SpecText spec = (SpecText)readSpec("text lowercase is \"some text\"");429 assertThat(spec.getText(), is("some text"));430 assertThat(spec.getType(), is(SpecText.Type.IS));431 assertThat(spec.getOperations(), contains("lowercase"));432 }433 @Test434 public void shouldReadSpec_text_lowercase_uppercase_is() throws IOException {435 SpecText spec = (SpecText)readSpec("text lowercase uppercase is \"SOME TEXT\"");436 assertThat(spec.getText(), is("SOME TEXT"));437 assertThat(spec.getType(), is(SpecText.Type.IS));438 assertThat(spec.getOperations(), contains("lowercase", "uppercase"));439 }440 @Test441 public void shouldReadSpec_text_singleline() throws IOException {442 SpecText spec = (SpecText)readSpec("text singleline is \"Some text\"");443 assertThat(spec.getText(), is("Some text"));444 assertThat(spec.getType(), is(SpecText.Type.IS));445 assertThat(spec.getOperations(), contains("singleline"));446 }447 @Test448 public void shouldReadSpec_css_fontsize_is_18px() throws IOException {449 SpecCss spec = (SpecCss)readSpec("css font-size is \"18px\"");450 assertThat(spec.getCssPropertyName(), is("font-size"));451 assertThat(spec.getText(), is("18px"));452 assertThat(spec.getType(), is(SpecText.Type.IS));453 }454 @Test455 public void shouldReadSpec_css_fontsize_starts() throws IOException {456 SpecCss spec = (SpecCss)readSpec("css font-size starts \"18px\"");457 assertThat(spec.getCssPropertyName(), is("font-size"));458 assertThat(spec.getText(), is("18px"));459 assertThat(spec.getType(), is(SpecText.Type.STARTS));460 }461 @Test462 public void shouldReadSpec_css_fontsize_ends() throws IOException {463 SpecCss spec = (SpecCss)readSpec("css font-size ends \"18px\"");464 assertThat(spec.getCssPropertyName(), is("font-size"));465 assertThat(spec.getText(), is("18px"));466 assertThat(spec.getType(), is(SpecText.Type.ENDS));467 }468 @Test469 public void shouldReadSpec_css_fontsize_contains() throws IOException {470 SpecCss spec = (SpecCss)readSpec("css font-size contains \"18px\"");471 assertThat(spec.getCssPropertyName(), is("font-size"));472 assertThat(spec.getText(), is("18px"));473 assertThat(spec.getType(), is(SpecText.Type.CONTAINS));474 }475 @Test476 public void shouldReadSpec_css_fontsize_matches() throws IOException {477 SpecCss spec = (SpecCss)readSpec("css font-size matches \"18px\"");478 assertThat(spec.getCssPropertyName(), is("font-size"));479 assertThat(spec.getText(), is("18px"));480 assertThat(spec.getType(), is(SpecText.Type.MATCHES));481 }482 @Test483 public void shouldReadSpec_above_object_20px() throws IOException {484 SpecAbove spec = (SpecAbove)readSpec("above object 20px");485 assertThat(spec.getObject(), is("object"));486 assertThat(spec.getRange(), is(Range.exact(20)));487 }488 @Test489 public void shouldReadSpec_above_object_10_20px() throws IOException {490 SpecAbove spec = (SpecAbove)readSpec("above object 10 to 20px");491 assertThat(spec.getObject(), is("object"));492 assertThat(spec.getRange(), is(Range.between(10, 20)));493 }494 @Test495 public void shouldReadSpec_above() throws IOException {496 SpecAbove spec = (SpecAbove)readSpec("above object");497 assertThat(spec.getObject(), is("object"));498 assertThat(spec.getRange(), is(Range.greaterThanOrEquals(0)));499 }500 @Test501 public void shouldReadSpec_below() throws IOException {502 SpecBelow spec = (SpecBelow)readSpec("below object");503 assertThat(spec.getObject(), is("object"));504 assertThat(spec.getRange(), is(Range.greaterThanOrEquals(0)));505 }506 @Test507 public void shouldReadSpec_below_object_20px() throws IOException {508 SpecBelow spec = (SpecBelow)readSpec("below object 20px");509 assertThat(spec.getObject(), is("object"));510 assertThat(spec.getRange(), is(Range.exact(20)));511 }512 @Test513 public void shouldReadSpec_below_object_10_to_20px() throws IOException {514 SpecBelow spec = (SpecBelow)readSpec("below object 10 to 20px");515 assertThat(spec.getObject(), is("object"));516 assertThat(spec.getRange(), is(Range.between(10, 20)));517 }518 @Test519 public void shouldReadSpec_left_of_object_10px() throws IOException {520 SpecLeftOf specLeftOf = (SpecLeftOf)readSpec("left-of object 10px");521 assertThat(specLeftOf.getObject(), is("object"));522 assertThat(specLeftOf.getRange(), is(Range.exact(10)));523 }524 @Test525 public void shouldReadSpec_left_of_object_10_to_20px() throws IOException {526 SpecLeftOf specLeftOf = (SpecLeftOf)readSpec("left-of object 10 to 20px");527 assertThat(specLeftOf.getObject(), is("object"));528 assertThat(specLeftOf.getRange(), is(Range.between(10, 20)));529 }530 @Test531 public void shouldReadSpec_left_of_object() throws IOException {532 SpecLeftOf specLeftOf = (SpecLeftOf)readSpec("left-of object");533 assertThat(specLeftOf.getObject(), is("object"));534 assertThat(specLeftOf.getRange(), is(Range.greaterThanOrEquals(0)));535 }536 @Test537 public void shouldReadSpec_right_of_object_10px() throws IOException {538 SpecRightOf specRightOf = (SpecRightOf)readSpec("right-of object 10px");539 assertThat(specRightOf.getObject(), is("object"));540 assertThat(specRightOf.getRange(), is(Range.exact(10)));541 }542 @Test543 public void shouldReadSpec_right_of_object_10_to_20px() throws IOException {544 SpecRightOf specRightOf = (SpecRightOf)readSpec("right-of object 10 to 20px");545 assertThat(specRightOf.getObject(), is("object"));546 assertThat(specRightOf.getRange(), is(Range.between(10, 20)));547 }548 @Test549 public void shouldReadSpec_right_of_object() throws IOException {550 SpecRightOf specRightOf = (SpecRightOf)readSpec("right-of object");551 assertThat(specRightOf.getObject(), is("object"));552 assertThat(specRightOf.getRange(), is(Range.greaterThanOrEquals(0)));553 }554 @Test(expectedExceptions = {SyntaxException.class},555 expectedExceptionsMessageRegExp = "Missing validation type \\(is, contains, starts, ends, matches\\)"556 )557 public void shouldGiveException_empty_css_spec() throws IOException {558 readSpec("css \"18px\"");559 }560 @Test(expectedExceptions = {SyntaxException.class},561 expectedExceptionsMessageRegExp = "Unknown validation type: \"18px\""562 )563 public void shouldGiveException_css_without_type() throws IOException {564 readSpec("css font-size \"18px\"");565 }566 @Test567 public void shouldReadSpec_centered_inside_object() throws IOException {568 SpecCentered spec = (SpecCentered)readSpec("centered inside object");569 assertThat(spec.getObject(), is("object"));570 assertThat(spec.getLocation(), is(SpecCentered.Location.INSIDE));571 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.ALL));572 }573 @Test574 public void shouldReadSpec_centered_horizontally_inside_object() throws IOException {575 SpecCentered spec = (SpecCentered)readSpec("centered horizontally inside object");576 assertThat(spec.getObject(), is("object"));577 assertThat(spec.getLocation(), is(SpecCentered.Location.INSIDE));578 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.HORIZONTALLY));579 }580 @Test581 public void shouldReadSpec_centered_vertically_inside_object() throws IOException {582 SpecCentered spec = (SpecCentered)readSpec("centered vertically inside object");583 assertThat(spec.getObject(), is("object"));584 assertThat(spec.getLocation(), is(SpecCentered.Location.INSIDE));585 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.VERTICALLY));586 }587 @Test588 public void shouldReadSpec_centered_all_inside_object() throws IOException {589 SpecCentered spec = (SpecCentered)readSpec("centered all inside object");590 assertThat(spec.getObject(), is("object"));591 assertThat(spec.getLocation(), is(SpecCentered.Location.INSIDE));592 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.ALL));593 }594 @Test595 public void shouldReadSpec_centered_all_on_object() throws IOException {596 SpecCentered spec = (SpecCentered)readSpec("centered all on object");597 assertThat(spec.getObject(), is("object"));598 assertThat(spec.getLocation(), is(SpecCentered.Location.ON));599 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.ALL));600 }601 @Test602 public void shouldReadSpec_centered_on_object() throws IOException {603 SpecCentered spec = (SpecCentered)readSpec("centered on object");604 assertThat(spec.getObject(), is("object"));605 assertThat(spec.getLocation(), is(SpecCentered.Location.ON));606 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.ALL));607 }608 @Test609 public void shouldReadSpec_centered_horizontally_on_object() throws IOException {610 SpecCentered spec = (SpecCentered)readSpec("centered horizontally on object");611 assertThat(spec.getObject(), is("object"));612 assertThat(spec.getLocation(), is(SpecCentered.Location.ON));613 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.HORIZONTALLY));614 }615 @Test616 public void shouldReadSpec_centered_horizontally_on_object_25px() throws IOException {617 SpecCentered spec = (SpecCentered)readSpec("centered horizontally on object 25px");618 assertThat(spec.getObject(), is("object"));619 assertThat(spec.getLocation(), is(SpecCentered.Location.ON));620 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.HORIZONTALLY));621 assertThat(spec.getErrorRate(), is(25));622 }623 @Test624 public void shouldReadSpec_centered_horizontally_on_object_25_px() throws IOException {625 SpecCentered spec = (SpecCentered)readSpec("centered horizontally on object 25 px");626 assertThat(spec.getObject(), is("object"));627 assertThat(spec.getLocation(), is(SpecCentered.Location.ON));628 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.HORIZONTALLY));629 assertThat(spec.getErrorRate(), is(25));630 }631 @Test632 public void shouldReadSpec_centered_vertically_on_object() throws IOException {633 SpecCentered spec = (SpecCentered)readSpec("centered vertically on object");634 assertThat(spec.getObject(), is("object"));635 assertThat(spec.getLocation(), is(SpecCentered.Location.ON));636 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.VERTICALLY));637 }638 @Test639 public void shoulReadSpec_on_object_10px_left() throws IOException {640 SpecOn spec = (SpecOn)readSpec("on edge object 10px left");641 assertThat(spec.getSideHorizontal(), is(TOP));642 assertThat(spec.getSideVertical(), is(LEFT));643 assertThat(spec.getObject(), is("object"));644 List<Location> locations = spec.getLocations();645 assertThat(locations.size(), is(1));646 assertThat(spec.getLocations(), contains(new Location(Range.exact(10), sides(LEFT))));647 assertThat(spec.getOriginalText(), is("on edge object 10px left"));648 }649 @Test650 public void shoulReadSpec_on_object_10px_left_20px_top() throws IOException {651 SpecOn spec = (SpecOn)readSpec("on edge object 10px left, 20px top");652 assertThat(spec.getSideHorizontal(), is(TOP));653 assertThat(spec.getSideVertical(), is(LEFT));654 assertThat(spec.getObject(), is("object"));655 List<Location> locations = spec.getLocations();656 assertThat(locations.size(), is(2));657 assertThat(spec.getLocations(), contains(new Location(Range.exact(10), sides(LEFT)), new Location(Range.exact(20), sides(TOP))));658 assertThat(spec.getOriginalText(), is("on edge object 10px left, 20px top"));659 }660 @Test661 public void shouldReadSpec_on_top_object_10px_top_right() throws Exception {662 SpecOn spec = (SpecOn)readSpec("on top edge object 10px top right");663 assertThat(spec.getSideHorizontal(), is(TOP));664 assertThat(spec.getSideVertical(), is(LEFT));665 assertThat(spec.getObject(), is("object"));666 List<Location> locations = spec.getLocations();667 assertThat(locations.size(), is(1));668 assertThat(spec.getLocations(), contains(new Location(Range.exact(10), sides(TOP, RIGHT))));669 assertThat(spec.getOriginalText(), is("on top edge object 10px top right"));670 }671 @Test672 public void shouldReadSpec_on_left_object_10px_top_right() throws Exception {673 SpecOn spec = (SpecOn)readSpec("on left edge object 10px top right");674 assertThat(spec.getSideHorizontal(), is(TOP));675 assertThat(spec.getSideVertical(), is(LEFT));676 assertThat(spec.getObject(), is("object"));677 List<Location> locations = spec.getLocations();678 assertThat(locations.size(), is(1));679 assertThat(spec.getLocations(), contains(new Location(Range.exact(10), sides(TOP, RIGHT))));680 assertThat(spec.getOriginalText(), is("on left edge object 10px top right"));681 }682 @Test683 public void shouldReadSpec_on_bottom_right_object_10px_top_right() throws Exception {684 SpecOn spec = (SpecOn)readSpec("on right bottom edge object 10px top right");685 assertThat(spec.getSideHorizontal(), is(BOTTOM));686 assertThat(spec.getSideVertical(), is(RIGHT));687 assertThat(spec.getObject(), is("object"));688 List<Location> locations = spec.getLocations();689 assertThat(locations.size(), is(1));690 assertThat(spec.getLocations(), contains(new Location(Range.exact(10), sides(TOP, RIGHT))));691 assertThat(spec.getOriginalText(), is("on right bottom edge object 10px top right"));692 }693 @Test(expectedExceptions = SyntaxException.class,694 expectedExceptionsMessageRegExp = "Missing \"edge\"")695 public void shouldGiveError_missingEdges_forSpec_on() throws Exception {696 readSpec("on top left object 10px");697 }698 @Test699 public void shouldReadSpec_color_scheme_40percent_black_approx_30percent_white() throws Exception {700 SpecColorScheme spec = (SpecColorScheme)readSpec("color-scheme 40% black , ~30% white");701 List<ColorRange> colors = spec.getColorRanges();702 assertThat(colors.size(), is(2));703 assertThat(colors.get(0).getRange(), is(Range.exact(40)));704 assertThat(colors.get(0).getColorClassifier(), is(new SimpleColorClassifier("black", new Color(0, 0, 0))));705 assertThat(colors.get(1).getRange(), is(Range.between(28, 32)));706 assertThat(colors.get(1).getColorClassifier(), is(new SimpleColorClassifier("white", new Color(255, 255, 255))));707 }708 @Test709 public void shouldReadSpec_color_scheme_greater_than_40percent_ffaa03() throws Exception {710 SpecColorScheme spec = (SpecColorScheme)readSpec("color-scheme > 40% #ffaa03");711 List<ColorRange> colors = spec.getColorRanges();712 assertThat(colors.size(), is(1));713 assertThat(colors.get(0).getRange(), is(Range.greaterThan(40)));714 assertThat(colors.get(0).getColorClassifier(), is(new SimpleColorClassifier("#ffaa03", new Color(255, 170, 3))));715 }716 @Test717 public void shouldReadSpec_color_scheme_40_to_50percent_ffaa03() throws Exception {718 SpecColorScheme spec = (SpecColorScheme)readSpec("color-scheme 40 to 50% red");719 List<ColorRange> colors = spec.getColorRanges();720 assertThat(colors.size(), is(1));721 assertThat(colors.get(0).getRange(), is(Range.between(40, 50)));722 assertThat(colors.get(0).getColorClassifier(), is(new SimpleColorClassifier("red", new Color(255, 0, 0))));723 }724 @Test725 public void shouldReadSpec_color_withShorthand_hexColorNotation() throws Exception {726 SpecColorScheme spec = (SpecColorScheme)readSpec("color-scheme 40% #f3e");727 List<ColorRange> colors = spec.getColorRanges();728 assertThat(colors.size(), is(1));729 assertThat(colors.get(0).getRange(), is(Range.exact(40)));730 assertThat(colors.get(0).getColorClassifier(), is(new SimpleColorClassifier("#f3e", new Color(255, 51, 238))));731 }732 @Test733 public void shouldReadSpec_color_withGradients() throws Exception {734 SpecColorScheme spec = (SpecColorScheme)readSpec("color-scheme 40% white-green-blue");735 List<ColorRange> colors = spec.getColorRanges();736 assertThat(colors.size(), is(1));737 assertThat(colors.get(0).getRange(), is(Range.exact(40)));738 assertThat(colors.get(0).getColorClassifier(), is(new GradientColorClassifier("white-green-blue", asList(739 new Color(255, 255, 255),740 new Color(0, 255, 0),741 new Color(0, 0, 255)742 ))));743 }744 @Test745 public void shouldReadSpec_color_withGradients_2() throws Exception {746 SpecColorScheme spec = (SpecColorScheme)readSpec("color-scheme 40% white - green - blue, 10 to 23% #a3f - #00e");747 List<ColorRange> colors = spec.getColorRanges();748 assertThat(colors.size(), is(2));749 assertThat(colors.get(0).getRange(), is(Range.exact(40)));750 assertThat(colors.get(0).getColorClassifier(), is(new GradientColorClassifier("white - green - blue", asList(751 new Color(255, 255, 255),752 new Color(0, 255, 0),753 new Color(0, 0, 255)754 ))));755 assertThat(colors.get(1).getRange(), is(Range.between(10, 23)));756 assertThat(colors.get(1).getColorClassifier(), is(new GradientColorClassifier("#a3f - #00e", asList(757 new Color(170, 51, 255),758 new Color(0, 0, 238)759 ))));760 }761 @Test762 public void shouldReadSpec_image_withMaxPercentageError() throws IOException {763 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 2.4%");764 assertThat(spec.getImagePaths(), contains("imgs/image.png"));765 assertThat(spec.getErrorRate().getValue(), is(2.4));766 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PERCENT));767 assertThat(spec.getTolerance(), is(25));768 }769 @Test770 public void shouldReadSpec_image_withMaxPixelsError() throws IOException {771 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px");772 assertThat(spec.getImagePaths(), contains("imgs/image.png"));773 assertThat(spec.getErrorRate().getValue(), is(112.0));774 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));775 assertThat(spec.getTolerance(), is(25));776 }777 @Test778 public void shouldReadSpec_image_withMaxPixelsError_tolerance5() throws IOException {779 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px, tolerance 5");780 assertThat(spec.getImagePaths(), contains("imgs/image.png"));781 assertThat(spec.getErrorRate().getValue(), is(112.0));782 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));783 assertThat(spec.getTolerance(), is(5));784 assertThat(spec.isStretch(), is(false));785 assertThat(spec.isCropIfOutside(), is(false));786 }787 @Test788 public void shouldReadSpec_image_withMaxPixelsError_tolerance5_stretch() throws IOException {789 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px, tolerance 5, stretch");790 assertThat(spec.getImagePaths(), contains("imgs/image.png"));791 assertThat(spec.getErrorRate().getValue(), is(112.0));792 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));793 assertThat(spec.getTolerance(), is(5));794 assertThat(spec.isStretch(), is(true));795 }796 @Test797 public void shouldReadSpec_image_withCropIfOutside() throws IOException {798 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, crop-if-outside");799 assertThat(spec.getImagePaths(), contains("imgs/image.png"));800 assertThat(spec.isCropIfOutside(), is(true));801 }802 @Test803 public void shouldReadSpec_image_withMaxPixelsError_tolerance5_filterBlur2() throws IOException {804 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px, tolerance 5, filter blur 2");805 assertThat(spec.getImagePaths(), contains("imgs/image.png"));806 assertThat(spec.getErrorRate().getValue(), is(112.0));807 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));808 assertThat(spec.getTolerance(), is(5));809 assertThat(spec.getOriginalFilters().size(), is(1));810 assertThat(spec.getSampleFilters().size(), is(1));811 assertThat(((BlurFilter)spec.getOriginalFilters().get(0)).getRadius(), is(2));812 assertThat(((BlurFilter)spec.getSampleFilters().get(0)).getRadius(), is(2));813 }814 @Test815 public void shouldReadSpec_image_withMaxPixelsError_tolerance5_filterABlur2() throws IOException {816 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px, tolerance 5, filter-a blur 2");817 assertThat(spec.getImagePaths(), contains("imgs/image.png"));818 assertThat(spec.getErrorRate().getValue(), is(112.0));819 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));820 assertThat(spec.getTolerance(), is(5));821 assertThat(spec.getOriginalFilters().size(), is(1));822 assertThat(spec.getSampleFilters().size(), is(0));823 assertThat(((BlurFilter)spec.getOriginalFilters().get(0)).getRadius(), is(2));824 }825 @Test826 public void shouldReadSpec_image_withMaxPixelsError_tolerance5_filterBBlur2() throws IOException {827 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px, tolerance 5, filter-b blur 2");828 assertThat(spec.getImagePaths(), contains("imgs/image.png"));829 assertThat(spec.getErrorRate().getValue(), is(112.0));830 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));831 assertThat(spec.getTolerance(), is(5));832 assertThat(spec.getOriginalFilters().size(), is(0));833 assertThat(spec.getSampleFilters().size(), is(1));834 assertThat(((BlurFilter)spec.getSampleFilters().get(0)).getRadius(), is(2));835 }836 @Test837 public void shouldReadSpec_image_withMaxPixelsError_tolerance5_filterBlur2_filterDenoise1() throws IOException {838 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px, filter blur 2, filter denoise 4, tolerance 5");839 assertThat(spec.getImagePaths(), contains("imgs/image.png"));840 assertThat(spec.getErrorRate().getValue(), is(112.0));841 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));842 assertThat(spec.getTolerance(), is(5));843 assertThat(spec.getOriginalFilters().size(), is(2));844 BlurFilter filter1 = (BlurFilter) spec.getOriginalFilters().get(0);845 assertThat(filter1.getRadius(), is(2));846 DenoiseFilter filter2 = (DenoiseFilter) spec.getOriginalFilters().get(1);847 assertThat(filter2.getRadius(), is(4));848 }849 @Test850 public void shouldReadSpec_image_withMaxPixelsError_tolerance5_filterBlur2_filterSaturation10_mapFilterDenoise1() throws IOException {851 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px, filter blur 2, filter saturation 10, map-filter denoise 4, tolerance 5");852 assertThat(spec.getErrorRate().getValue(), is(112.0));853 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));854 assertThat(spec.getImagePaths(), contains("imgs/image.png"));855 assertThat(spec.getTolerance(), is(5));856 assertThat(spec.getOriginalFilters().size(), is(2));857 assertThat(spec.getSampleFilters().size(), is(2));858 assertThat(spec.getMapFilters().size(), is(1));859 assertThat(((BlurFilter)spec.getOriginalFilters().get(0)).getRadius(), is(2));860 assertThat(((BlurFilter)spec.getSampleFilters().get(0)).getRadius(), is(2));861 assertThat(((SaturationFilter)spec.getOriginalFilters().get(1)).getLevel(), is(10));862 assertThat(((SaturationFilter)spec.getSampleFilters().get(1)).getLevel(), is(10));863 DenoiseFilter filter2 = (DenoiseFilter) spec.getMapFilters().get(0);864 assertThat(filter2.getRadius(), is(4));865 }866 @Test867 public void shouldReadSpec_image_withMask() throws IOException {868 SpecImage spec = (SpecImage)readSpec("image file image.png, filter mask color-scheme-image-1.png");869 assertThat(spec.getImagePaths(), contains("image.png"));870 assertThat(spec.getOriginalFilters().size(), is(1));871 assertThat(spec.getOriginalFilters().get(0), is(instanceOf(MaskFilter.class)));872 assertThat(spec.getSampleFilters().size(), is(1));873 assertThat(spec.getSampleFilters().get(0), is(instanceOf(MaskFilter.class)));874 }875 @Test876 public void shouldReadSpec_image_withMaxPixelsError_andArea() throws IOException {877 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px, area 10 10 100 20");878 assertThat(spec.getImagePaths(), contains("imgs/image.png"));879 assertThat(spec.getErrorRate().getValue(), is(112.0));880 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));881 assertThat(spec.getTolerance(), is(25));882 assertThat(spec.getSelectedArea(), is(new Rect(10,10,100,20)));883 }884 @Test885 public void shouldReadSpec_image_withAnalyzeOffset() throws IOException {886 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, analyze-offset 5");887 assertThat(spec.getImagePaths(), contains("imgs/image.png"));888 assertThat(spec.getAnalyzeOffset(), is(5));889 }890 @Test891 public void shouldReadSpec_image_andBuildImagePath_withContextPath() throws IOException {892 SpecImage spec = (SpecImage) readSpec("image file image.png", "some-component/specs");893 assertThat(spec.getImagePaths(), contains("some-component/specs/image.png"));894 }895 /**896 * Comes from https//github.com/galenframework/galen/issues/171897 * @throws IOException898 */899 @Test900 public void shouldReadSpec_image_toleranceAndErrorRate_fromConfig() throws IOException {901 System.setProperty("galen.spec.image.tolerance", "21");902 System.setProperty("galen.spec.image.error", "121%");903 SpecImage spec = (SpecImage)readSpec("image file image.png");904 assertThat(spec.getTolerance(), is(21));905 assertThat(spec.getErrorRate().getValue(), is(121.0));906 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PERCENT));907 System.getProperties().remove("galen.spec.image.tolerance");908 System.getProperties().remove("galen.spec.image.error");909 }910 @Test911 public void shouldReadSpec_image_replaceColors() throws IOException {912 SpecImage specImage = (SpecImage) readSpec("image file image.png, filter replace-colors #000-#333 #f0f0f0 #a0a0a0-#a0b0a0-#a0b0c0 with #111 tolerance 30 radius 2");913 assertThat(specImage.getOriginalFilters().size(), is(1));914 assertThat(specImage.getOriginalFilters().get(0), is(instanceOf(ReplaceColorsFilter.class)));915 ReplaceColorsFilter filter = (ReplaceColorsFilter) specImage.getOriginalFilters().get(0);916 assertThat(filter.getReplaceColorsDefinitions().size(), is(1));917 ReplaceColorsDefinition replaceColorsDefinitions = filter.getReplaceColorsDefinitions().get(0);918 assertThat(replaceColorsDefinitions.getReplaceColor(), is(new Color(17, 17, 17)));919 assertThat(replaceColorsDefinitions.getTolerance(), is(30));920 assertThat(replaceColorsDefinitions.getRadius(), is(2));921 assertThat(replaceColorsDefinitions.getColorClassifiers().size(), is(3));922 assertThat(replaceColorsDefinitions.getColorClassifiers().get(0), instanceOf(GradientColorClassifier.class));923 GradientColorClassifier gradient = (GradientColorClassifier) replaceColorsDefinitions.getColorClassifiers().get(0);924 assertThat(gradient.getName(), is("#000-#333"));925 assertThat(replaceColorsDefinitions.getColorClassifiers().get(1), instanceOf(SimpleColorClassifier.class));926 SimpleColorClassifier simple = (SimpleColorClassifier) replaceColorsDefinitions.getColorClassifiers().get(1);927 assertThat(simple.getName(), is("#f0f0f0"));928 assertThat(replaceColorsDefinitions.getColorClassifiers().get(2), instanceOf(GradientColorClassifier.class));929 gradient = (GradientColorClassifier) replaceColorsDefinitions.getColorClassifiers().get(2);930 assertThat(gradient.getName(), is("#a0a0a0-#a0b0a0-#a0b0c0"));931 }932 @Test933 public void shouldReadSpec_image_ignoredObjects() throws IOException {934 SpecImage spec = (SpecImage) readSpec("image file img.png, ignore-objects [menu_item-*, &excluded_objects], error 10px, ignore-objects one_more_obj");935 assertThat(spec.getImagePaths(), contains("img.png"));936 assertThat(spec.getIgnoredObjectExpressions(), contains("menu_item-*, &excluded_objects", "one_more_obj"));937 assertThat(spec.getErrorRate().getValue(), is(10.0));938 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));939 }940 @Test941 public void shouldReadSpec_component() throws IOException {942 SpecComponent spec = (SpecComponent)readSpec("component some.spec");943 assertThat(spec.isFrame(), is(false));944 assertThat(spec.getSpecPath(), is("some.spec"));945 assertThat(spec.getOriginalText(), is("component some.spec"));946 }947 @Test948 public void shouldReadSpec_component_frame() throws IOException {949 SpecComponent spec = (SpecComponent)readSpec("component frame some.spec");950 assertThat(spec.isFrame(), is(true));951 assertThat(spec.getSpecPath(), is("some.spec"));952 assertThat(spec.getOriginalText(), is("component frame some.spec"));...

Full Screen

Full Screen

Source:SpecImage.java Github

copy

Full Screen

...52 }53 public void setValue(Double value) {54 this.value = value;55 }56 public SpecImage.ErrorRateType getType() {57 return type;58 }59 public void setType(ErrorRateType type) {60 this.type = type;61 }62 public static ErrorRate fromString(String errorRateText) {63 if (errorRateText == null || errorRateText.trim().isEmpty()) {64 return new ErrorRate(0.0, ErrorRateType.PIXELS);65 }66 StringCharReader reader = new StringCharReader(errorRateText);67 Double value = number().read(reader);68 String rest = reader.getTheRest().trim();69 ErrorRateType type;70 if (rest.isEmpty() || rest.equals("px")) {...

Full Screen

Full Screen

getType

Using AI Code Generation

copy

Full Screen

1package com.galenframework.java.official;2import com.galenframework.api.Galen;3import com.galenframework.specs.SpecImage;4import com.galenframework.specs.page.PageSection;5import com.galenframework.specs.page.PageSectionFilter;6import java.util.Arrays;7import java.util.List;8public class GalenImageSpecs {9 public static void main(String[] args) throws Exception {10 PageSectionFilter filter = new PageSectionFilter();11 filter.setInclude(Arrays.asList("image"));12 for (PageSection pageSection : pageSections) {13 for (SpecImage specImage : pageSection.getSpec().getImage()) {14 System.out.println("Image spec type: " + specImage.getType());15 System.out.println("Image spec object: " + specImage.getObject());16 System.out.println("Image spec area: " + specImage.getArea());17 System.out.println("Image spec file: " + specImage.getFile());18 System.out.println("Image spec tolerance: " + specImage.getTolerance());19 System.out.println("Image spec threshold: " + specImage.getThreshold());20 System.out.println("Image spec min coverage: " + specImage.getMinCoverage());21 System.out.println("Image spec max difference: " + specImage.getMaxDifference());22 System.out.println("Image spec max color difference: " + specImage.getMaxColorDifference());23 }24 }25 }26}

Full Screen

Full Screen

getType

Using AI Code Generation

copy

Full Screen

1package com.galenframework.specs;2import com.galenframework.validation.ValidationObject;3import com.galenframework.validation.ValidationError;4import com.galenframework.validation.ValidationResult;5import com.galenframework.validation.ValidationListener;6import com.galenframework.specs.reader.StringCharReader;7import com.galenframework.specs.reader.page.PageSection;8import com.galenframework.specs.reader.page.PageSectionFilter;9import com.galenframework.specs.reader.page.SectionFilter;10import com.galenframework.specs.reader.page.SectionFilters;11import com.galenframework.specs.page.PageSectionFactory;12import com.galenframework.specs.page.Locator;13import com.galenframework.specs.page.PageSection;14import com.galenframework.specs.page.PageSectionFilter;15import com.galenframework.specs.page.SectionFilter;16import com.galenframework.specs.page.SectionFilters;17import com.galenframework.specs.page.PageSection;18import com.galenframework.specs.page.PageSectionFilter;19import com.galenframework.specs.page.SectionFilter;20import com.galenframework.specs.page.SectionFilters;21import com.galenframework.specs.page.PageSection;22import com.galenframework.specs.page.PageSectionFilter;23import com.galenframework.specs.page.SectionFilter;24import com.galenframework.specs.page.SectionFilters;25import com.galenframework.specs.page.PageSection;26import com.galenframework.specs.page.PageSectionFilter;27import com.galenframework.specs.page.SectionFilter;28import com.galenframework.specs.page.SectionFilters;29import com.galenframework.specs.page.PageSection;30import com.galenframework.specs.page.PageSectionFilter;31import com.galenframework.specs.page.SectionFilter;32import com.galenframework.specs.page.SectionFilters;33import com.galenframework.specs.page.PageSection;34import com.galenframework.specs.page.PageSectionFilter;35import com.galenframework.specs.page.SectionFilter;36import com.galenframework.specs.page.SectionFilters;37import com.galenframework.specs.page.PageSection;38import com.galenframework.specs.page.PageSectionFilter;39import com.galenframework.specs.page.SectionFilter;40import com.galenframework.specs.page.SectionFilters;41import com.galenframework.specs.page.PageSection;42import com.galenframework.specs.page.PageSectionFilter;43import com.galenframework.specs.page.SectionFilter;44import com.galenframework.specs.page.SectionFilters;45import com.galenframework.specs.page.PageSection;

Full Screen

Full Screen

getType

Using AI Code Generation

copy

Full Screen

1package com.galenframework.java.sample;2import com.galenframework.java.GalenJava;3import com.galenframework.java.sample.components.*;4import com.galenframework.specs.Spec;5import com.galenframework.specs.SpecImage;6import com.galenframework.specs.page.Locator;7import com.galenframework.specs.page.PageSection;8import com.galenframework.specs.page.PageSectionFilter;9import com.galenframework.specs.reader.page.PageSpecReader;10import com.galenframework.specs.reader.page.SectionFilter;11import com.galenframework.specs.reader.page.SectionFilterType;12import com.galenframework.specs.reader.page.SectionFilters;13import com.galenframework.validation.ValidationListener;14import com.galenframework.validation.ValidationResult;15import org.openqa.selenium.WebDriver;16import org.openqa.selenium.chrome.ChromeDriver;17import java.io.IOException;18import java.util.LinkedList;19import java.util.List;20import static com.galenframework.components.JsUtils.jsSupports;21public class GalenJavaSample {22 public static void main(String[] args) throws IOException {23 System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Downloads\\chromedriver_win32\\chromedriver.exe");24 WebDriver driver = new ChromeDriver();25 driver.manage().window().maximize();26 GalenJava.checkLayout(driver, "specs/homepage.spec", null, null);27 GalenJava.checkLayout(driver, "specs/homepage.spec", new PageSection("header", new Locator("id", "header")), null);28 PageSectionFilter filter = new PageSectionFilter();29 filter.addFilter(new SectionFilter(SectionFilterType.TAG, "h1"));30 filter.addFilter(new SectionFilter(SectionFilterType.CLASS, "logo"));31 GalenJava.checkLayout(driver, "specs/homepage.spec", new PageSection("header", new Locator("id", "header"), filter), null);32 List<ValidationListener> validationListeners = new LinkedList<ValidationListener>();

Full Screen

Full Screen

getType

Using AI Code Generation

copy

Full Screen

1package com.galenframework.specs;2import com.galenframework.page.Rect;3import com.galenframework.specs.page.Locator;4import com.galenframework.validation.ValidationObject;5public class SpecImage extends Spec {6 private String image;7 private Locator locator;8 public SpecImage(String image) {9 this.image = image;10 }11 public String getImage() {12 return image;13 }14 public void setImage(String image) {15 this.image = image;16 }17 public Locator getLocator() {18 return locator;19 }20 public void setLocator(Locator locator) {21 this.locator = locator;22 }23 public String getName() {24 return "image";25 }26 public void check(String objectName, ValidationObject object, Context context) throws GalenSpecException {27 Rect area = object.getArea();28 if (area == null) {29 throw new GalenSpecException("There is no area found for object \"" + objectName + "\"");30 }31 context.getTestSession().checkImage(objectName, area, image);32 }33 public String toString() {34 return getName() + " " + image;35 }36}37package com.galenframework.specs;38import com.galenframework.page.Rect;39import com.galenframework.specs.page.Locator;40import com.galenframework.validation.ValidationObject;41public class SpecText extends Spec {42 private String text;43 private Locator locator;44 public SpecText(String text) {45 this.text = text;46 }47 public String getText() {48 return text;49 }50 public void setText(String text) {51 this.text = text;52 }53 public Locator getLocator() {54 return locator;55 }56 public void setLocator(Locator locator) {57 this.locator = locator;58 }59 public String getName() {60 return "text";61 }62 public void check(String objectName, ValidationObject object, Context context) throws GalenSpecException {63 Rect area = object.getArea();64 if (area == null) {65 throw new GalenSpecException("There is no area found for object \"" + objectName + "\"");66 }67 context.getTestSession().checkText(objectName, area

Full Screen

Full Screen

getType

Using AI Code Generation

copy

Full Screen

1package com.galenframework.specs;2import com.galenframework.specs.reader.StringCharReader;3import com.galenframework.specs.reader.StringCharReader;4import com.galenframework.specs.reader.StringCharReader;5import com.galenframework.specs.reader.StringCharReader;6public class SpecImage extends Spec {7 private String image;8 public SpecImage(String image) {9 this.image = image;10 }11 public static SpecImage read(StringCharReader reader) {12 return new SpecImage(reader.readWord());13 }14 public String getImage() {15 return image;16 }17 public String getType() {18 return "image";19 }20}21package com.galenframework.specs;22import com.galenframework.specs.reader.StringCharReader;23import com.galenframework.specs.reader.StringCharReader;24import com.galenframework.specs.reader.StringCharReader;25import com.galenframework.specs.reader.StringCharReader;26public class SpecText extends Spec {27 private String text;28 public SpecText(String text) {29 this.text = text;30 }31 public static SpecText read(StringCharReader reader) {32 return new SpecText(reader.readWord());33 }34 public String getText() {35 return text;36 }37 public String getType() {38 return "text";39 }40}41package com.galenframework.specs;42import com.galenframework.specs.reader.StringCharReader;43import com.galenframework.specs.reader.StringCharReader;44import com.galenframework.specs.reader.StringCharReader;45import com.galenframework.specs.reader.StringCharReader;46public class SpecLink extends Spec {47 private String text;48 public SpecLink(String text) {49 this.text = text;50 }51 public static SpecLink read(StringCharReader reader) {52 return new SpecLink(reader.readWord());53 }54 public String getText() {55 return text;56 }57 public String getType() {58 return "link";59 }60}

Full Screen

Full Screen

getType

Using AI Code Generation

copy

Full Screen

1package com.galenframework.specs;2public class SpecImage {3 public String getType() {4 return "image";5 }6}7package com.galenframework.specs;8public class SpecImage {9 public String getType() {10 return "image";11 }12}13package com.galenframework.specs;14public class SpecImage {15 public String getType() {16 return "image";17 }18}19package com.galenframework.specs;20public class SpecImage {21 public String getType() {22 return "image";23 }24}25package com.galenframework.specs;26public class SpecImage {27 public String getType() {28 return "image";29 }30}31package com.galenframework.specs;32public class SpecImage {33 public String getType() {34 return "image";35 }36}37package com.galenframework.specs;38public class SpecImage {39 public String getType() {40 return "image";41 }42}43package com.galenframework.specs;44public class SpecImage {45 public String getType() {46 return "image";47 }48}

Full Screen

Full Screen

getType

Using AI Code Generation

copy

Full Screen

1import com.galenframework.specs.SpecImage;2import com.galenframework.specs.Spec;3import com.galenframework.parser.SyntaxException;4import java.io.IOException;5import java.util.List;6import java.util.ArrayList;7import java.util.Arrays;8import java.util.HashMap;9import java.util.Map;10import java.util.Iterator;11import java.util.Set;12import com.galenframework.specs.Spec;13import com.galenframework.specs.page.Locator;14import com.galenframework.specs.page.PageSection;15import com.galenframework.specs.page.PageSectionFilter;16import com.galenframework.specs.page.PageSectionFilterType;17import com.galenframework.specs.page.PageSectionPart;18import com.galenframework.specs.page.PageSectionPartType;19import com.galenframework.specs.page.PageSectionType;20import com.galenframework.specs.page.PageSections;21import com.galenframework.specs.page.PageSpec;22import java.util.LinkedHashMap;23import java.util.LinkedList;24import java.util.List;25import java.util.Map;26import java.util.regex.Matcher;27import java.util.regex.Pattern;28import com.galenframework.parser.SyntaxException;29import com.galenframework.specs.page.PageSection;30import com.galenframework.specs.page.PageSectionFilter;31import com.galenframework.specs.page.PageSectionFilterType;32import com.galenframework.specs.page.PageSectionPart;33import com.galenframework.specs.page.PageSectionPartType;34import com.galenframework.specs.page.PageSectionType;35import com.galenframework.specs.page.PageSections;36import com.galenframework.specs.page.PageSpec;37import com.galenframework.specs.Spec;38import com.galenframework.specs.SpecImage;39import com.galenframework.specs.SpecText;40import com.galenframework.specs.SpecVisible;41import com.galenframework.specs.page.Locator;42import com.galenframework.specs.page.PageSection;43import com.galenframework.specs.page.PageSectionFilter;44import com.galenframework.specs.page.PageSectionFilterType;45import com.galenframework.specs.page.PageSectionPart;46import com.galenframework.specs.page.PageSectionPartType;47import com.galenframework.specs.page.PageSectionType;48import com.galenframework.specs.page.PageSections;49import com.galenframework.specs.page.PageSpec;50import com.galenframework.specs.Spec;51import com.galenframework.specs.Spec

Full Screen

Full Screen

getType

Using AI Code Generation

copy

Full Screen

1public class ImageTest {2 public void testImage() throws IOException {3 String spec = "image /path/to/image.jpg 10px";4 SpecImage specImage = new SpecImage(spec);5 System.out.println(specImage.getType());6 }7}

Full Screen

Full Screen

getType

Using AI Code Generation

copy

Full Screen

1package com.galenframework.specs;2import com.galenframework.specs.SpecImage;3public class GalenSpecImageGetType {4 public static void main(String[] args) {5 SpecImage specImage = new SpecImage("image", "image.png");6 System.out.println(specImage.getType());7 }8}9package com.galenframework.specs;10import com.galenframework.specs.SpecImage;11public class GalenSpecImageGetFileName {12public static void main(String[] args) {13SpecImage specImage = new SpecImage("image", "image.png");14System.out.println(specImage.getFileName());15}16}17package com.galenframework.specs;18import com.galenframework.specs.SpecImage;19public class GalenSpecImageGetArea {20public static void main(String[] args) {21SpecImage specImage = new SpecImage("image", "image.png");22System.out.println(specImage.getArea());23}24}25package com.galenframework.specs;26import com.galenframework.specs.SpecImage;27public class GalenSpecImageGetRegion {28public static void main(String[] args) {29SpecImage specImage = new SpecImage("image", "image.png");30System.out.println(specImage.getRegion());31}32}

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