Best Galen code snippet using com.galenframework.specs.SpecImage.getErrorRate
Source:SpecsReaderV2Test.java
...222 public void shouldReadSpec_aligned_horizontally_centered() throws IOException {223 SpecHorizontally spec = (SpecHorizontally) readSpec("aligned horizontally centered object");224 assertThat(spec.getAlignment(), Matchers.is(Alignment.CENTERED));225 assertThat(spec.getObject(), is("object"));226 assertThat(spec.getErrorRate(), is(0));227 assertThat(spec.getOriginalText(), is("aligned horizontally centered object"));228 }229 @Test230 public void shouldReadSpec_aligned_horizontally_top() throws IOException {231 SpecHorizontally spec = (SpecHorizontally) readSpec("aligned horizontally top object");232 assertThat(spec.getAlignment(), is(Alignment.TOP));233 assertThat(spec.getObject(), is("object"));234 assertThat(spec.getErrorRate(), is(0));235 assertThat(spec.getOriginalText(), is("aligned horizontally top object"));236 }237 @Test238 public void shouldReadSpec_aligned_horizontally_bottom() throws IOException {239 SpecHorizontally spec = (SpecHorizontally) readSpec("aligned horizontally bottom object");240 assertThat(spec.getAlignment(), is(Alignment.BOTTOM));241 assertThat(spec.getObject(), is("object"));242 assertThat(spec.getErrorRate(), is(0));243 assertThat(spec.getOriginalText(), is("aligned horizontally bottom object"));244 }245 @Test246 public void shouldReadSpec_aligned_horizontally_all() throws IOException {247 SpecHorizontally spec = (SpecHorizontally) readSpec("aligned horizontally all object");248 assertThat(spec.getAlignment(), is(Alignment.ALL));249 assertThat(spec.getObject(), is("object"));250 assertThat(spec.getErrorRate(), is(0));251 assertThat(spec.getOriginalText(), is("aligned horizontally all object"));252 }253 @Test254 public void shouldReadSpec_aligned_vertically_centered() throws IOException {255 SpecVertically spec = (SpecVertically) readSpec("aligned vertically centered object");256 assertThat(spec.getAlignment(), is(Alignment.CENTERED));257 assertThat(spec.getObject(), is("object"));258 assertThat(spec.getErrorRate(), is(0));259 assertThat(spec.getOriginalText(), is("aligned vertically centered object"));260 }261 @Test262 public void shouldReadSpec_aligned_vertically_left() throws IOException {263 SpecVertically spec = (SpecVertically) readSpec("aligned vertically left object");264 assertThat(spec.getAlignment(), is(Alignment.LEFT));265 assertThat(spec.getObject(), is("object"));266 assertThat(spec.getErrorRate(), is(0));267 assertThat(spec.getOriginalText(), is("aligned vertically left object"));268 }269 @Test270 public void shouldReadSpec_aligned_vertically_right() throws IOException {271 SpecVertically spec = (SpecVertically) readSpec("aligned vertically right object");272 assertThat(spec.getAlignment(), is(Alignment.RIGHT));273 assertThat(spec.getObject(), is("object"));274 assertThat(spec.getErrorRate(), is(0));275 assertThat(spec.getOriginalText(), is("aligned vertically right object"));276 }277 @Test278 public void shouldReadSpec_aligned_vertically_all() throws IOException {279 SpecVertically spec = (SpecVertically) readSpec("aligned vertically all object");280 assertThat(spec.getAlignment(), is(Alignment.ALL));281 assertThat(spec.getObject(), is("object"));282 assertThat(spec.getErrorRate(), is(0));283 assertThat(spec.getOriginalText(), is("aligned vertically all object"));284 }285 @Test286 public void shouldReadSpec_aligned_vertically_with_error_rate_10px() throws IOException {287 SpecVertically spec = (SpecVertically) readSpec("aligned vertically all object 10px");288 assertThat(spec.getAlignment(), is(Alignment.ALL));289 assertThat(spec.getObject(), is("object"));290 assertThat(spec.getErrorRate(), is(10));291 assertThat(spec.getOriginalText(), is("aligned vertically all object 10px"));292 }293 @Test294 public void shouldReadSpec_aligned_vertically_with_error_rate_10_px() throws IOException {295 SpecVertically spec = (SpecVertically) readSpec("aligned vertically all object 10 px");296 assertThat(spec.getAlignment(), is(Alignment.ALL));297 assertThat(spec.getObject(), is("object"));298 assertThat(spec.getErrorRate(), is(10));299 assertThat(spec.getOriginalText(), is("aligned vertically all object 10 px"));300 }301 @Test302 public void shouldReadSpec_aligned_horizontally_with_error_rate_10px() throws IOException {303 SpecHorizontally spec = (SpecHorizontally) readSpec("aligned horizontally all object 10px");304 assertThat(spec.getAlignment(), is(Alignment.ALL));305 assertThat(spec.getObject(), is("object"));306 assertThat(spec.getErrorRate(), is(10));307 assertThat(spec.getOriginalText(), is("aligned horizontally all object 10px"));308 }309 @Test310 public void shouldReadSpec_aligned_horizontally_with_error_rate_10_px() throws IOException {311 SpecHorizontally spec = (SpecHorizontally) readSpec("aligned horizontally all object 10 px");312 assertThat(spec.getAlignment(), is(Alignment.ALL));313 assertThat(spec.getObject(), is("object"));314 assertThat(spec.getErrorRate(), is(10));315 assertThat(spec.getOriginalText(), is("aligned horizontally all object 10 px"));316 }317 @Test(expectedExceptions = SyntaxException.class,318 expectedExceptionsMessageRegExp = "Incorrect alignment direction. Expected 'vertically' or 'horizontally' but got: object")319 public void shouldGiveError_aligned_object() {320 readSpec("aligned object");321 }322 @Test(expectedExceptions = SyntaxException.class,323 expectedExceptionsMessageRegExp = "Incorrect side for vertical alignment: top")324 public void shouldGiveError_aligned_vertically_top_object() {325 readSpec("aligned vertically top object");326 }327 @Test(expectedExceptions = SyntaxException.class,328 expectedExceptionsMessageRegExp = "Incorrect side for horizontal alignment: left")329 public void shouldGiveError_aligned_horizontally_left_object() {330 readSpec("aligned horizontally left object");331 }332 @Test(expectedExceptions = SyntaxException.class,333 expectedExceptionsMessageRegExp = "Missing object name")334 public void shouldGiveError_aligned_horizontally_left() {335 readSpec("aligned horizontally left");336 }337 @Test338 public void shouldReadSpec_absent() throws IOException {339 Spec spec = readSpec("absent");340 assertThat(spec, instanceOf(SpecAbsent.class));341 assertThat(spec.getOriginalText(), is("absent"));342 }343 @Test344 public void shouldReadSpec_visible() throws IOException {345 Spec spec = readSpec("visible");346 assertThat(spec, instanceOf(SpecVisible.class));347 assertThat(spec.getOriginalText(), is("visible"));348 }349 @Test350 public void shouldReadSpec_width_10px() throws IOException {351 SpecWidth spec = (SpecWidth) readSpec("width 10px");352 assertThat(spec.getRange(), is(Range.exact(10)));353 assertThat(spec.getOriginalText(), is("width 10px"));354 }355 @Test356 public void shouldReadSpec_width_5_to_8px() throws IOException {357 SpecWidth spec = (SpecWidth) readSpec("width 5 to 8px");358 assertThat(spec.getRange(), is(Range.between(5, 8)));359 assertThat(spec.getOriginalText(), is("width 5 to 8px"));360 }361 @Test362 public void shouldReadSpec_width_100_percent_of_other_object_width() throws IOException {363 SpecWidth spec = (SpecWidth) readSpec("width 100% of main-big-container/width");364 assertThat(spec.getRange(), is(Range.exact(100).withPercentOf("main-big-container/width")));365 assertThat(spec.getOriginalText(), is("width 100% of main-big-container/width"));366 }367 @Test368 public void shouldReadSpec_height_10px() throws IOException {369 SpecHeight spec = (SpecHeight) readSpec("height 10px");370 assertThat(spec.getRange(), is(Range.exact(10)));371 assertThat(spec.getOriginalText(), is("height 10px"));372 }373 @Test374 public void shouldReadSpec_height_5_to_8px() throws IOException {375 SpecHeight spec = (SpecHeight) readSpec("height 5 to 8px");376 assertThat(spec.getRange(), is(Range.between(5, 8)));377 assertThat(spec.getOriginalText(), is("height 5 to 8px"));378 }379 @Test(expectedExceptions = SyntaxException.class,380 expectedExceptionsMessageRegExp = "Unexpected token: 1234 px")381 public void shouldGiveError_width_unexcpected_token() {382 readSpec("width 10 to 40 px 1234 px ");383 }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"));...
getErrorRate
Using AI Code Generation
1import com.galenframework.reports.model.LayoutReport;2import com.galenframework.reports.model.LayoutReportBuilder;3import com.galenframework.specs.SpecImage;4import com.galenframework.specs.page.Locator;5import com.galenframework.specs.page.PageSection;6import com.galenframework.specs.page.PageSectionSpec;7import com.galenframework.specs.page.PageSpec;8import com.galenframework.validation.ValidationObject;9import com.galenframework.validation.ValidationResult;10PageSpec pageSpec = new PageSpec();11pageSpec.addPageSection(new PageSection("main", new Locator("id", "main")));12pageSpec.addPageSection(new PageSection("header", new Locator("id", "header")));13pageSpec.addPageSection(new PageSection("footer", new Locator("id", "footer")));14pageSpec.addPageSection(new PageSection("sidebar", new Locator("id", "sidebar")));15pageSpec.addPageSection(new PageSection("content", new Locator("id", "content")));16SpecImage specImage = new SpecImage("image", new PageSectionSpec("main"), "test.png", 0.1);17ValidationResult result = specImage.check(pageSpec, new ValidationObject("image", new LayoutReportBuilder()));18System.out.println("ErrorRate: " + result.getErrorRate());
getErrorRate
Using AI Code Generation
1import com.galenframework.specs.SpecImage2SpecImage.getErrorRate()3import com.galenframework.specs.SpecImage4SpecImage.getErrorRate()5import com.galenframework.specs.SpecImage6SpecImage.getErrorRate()7import com.galenframework.specs.SpecImage8SpecImage.getErrorRate()9import com.galenframework.specs.SpecImage10SpecImage.getErrorRate()11import com.galenframework.specs.SpecImage12SpecImage.getErrorRate()13import com.galenframework.specs.SpecImage14SpecImage.getErrorRate()15import com.galenframework.specs.SpecImage16SpecImage.getErrorRate()17import com.galenframework.specs.SpecImage18SpecImage.getErrorRate()19import com.galenframework.specs.SpecImage20SpecImage.getErrorRate()21import com.galenframework.specs.SpecImage22SpecImage.getErrorRate()23import com.galenframework.specs.SpecImage24SpecImage.getErrorRate()25import com.galenframework.specs.SpecImage26SpecImage.getErrorRate()27import com.galenframework.specs.SpecImage28SpecImage.getErrorRate()29import com.galenframework.specs.SpecImage30SpecImage.getErrorRate()
getErrorRate
Using AI Code Generation
1import com.galenframework.reports.TestReport;2import com.galenframework.specs.SpecImage;3import com.galenframework.specs.page.PageSection;4import com.galenframework.validation.ValidationObject;5TestReport report = new TestReport();6PageSection pageSection = new PageSection("pageSection", 0, 0, 100, 100);7ValidationObject validationObject = new ValidationObject(pageSection);8SpecImage specImage = new SpecImage("specImage", "path_to_image", 0.9);9double errorRate = specImage.getErrorRate(validationObject, report);10System.out.println(errorRate);
getErrorRate
Using AI Code Generation
1import com.galenframework.api.Galen2import com.galenframework.reports.TestReport3import com.galenframework.reports.TestReportFactory4import com.galenframework.reports.model.LayoutReport5import com.galenframework.reports.model.LayoutReportItem6def spec = new File(specPath).getText('UTF-8')7def report = new TestReport()8def layoutReport = new LayoutReport()9def specImage = new com.galenframework.specs.SpecImage()10layoutReport.items = specImage.getErrorRate(spec, "src/test/galen/specs/test.png", "src/test/galen/specs/test2.png")11report.layout(layoutReport)12report.writeTo("target/galen-html-report")13import com.galenframework.api.Galen14import com.galenframework.reports.TestReport15import com.galenframework.reports.TestReportFactory16import com.galenframework.reports.model.LayoutReport17import com.galenframework.reports.model.LayoutReportItem18def spec = new File(specPath).getText('UTF-8')19def report = new TestReport()20def layoutReport = new LayoutReport()21def specImage = new com.galenframework.specs.SpecImage()22layoutReport.items = specImage.getErrorRate(spec, "src/test/galen/specs/test.png", "src/test/galen/specs/test2.png")23report.layout(layoutReport)24report.writeTo("target/galen-html-report")
getErrorRate
Using AI Code Generation
1import com.galenframework.specs.SpecImage;2SpecImage imageSpec = new SpecImage("image", "image.jpg");3import com.galenframework.specs.SpecText;4SpecText textSpec = new SpecText("text", "text");5import com.galenframework.specs.SpecRegion;6SpecRegion regionSpec = new SpecRegion("region", "region");7import com.galenframework.specs.SpecLayout;8SpecLayout layoutSpec = new SpecLayout("layout", "layout");9import com.galenframework.specs.SpecObject;10SpecObject objectSpec = new SpecObject("object", "object");11objectSpec.setIgnore(
getErrorRate
Using AI Code Generation
1import com.galenframework.browser.Browser;2import com.galenframework.reports.TestReport;3import com.galenframework.reports.TestReportFactory;4import com.galenframework.specs.SpecImage;5import com.galenframework.specs.page.PageSection;6import com.galenframework.specs.page.PageSpec;7import com.galenframework.specs.page.PageValidation;8import com.galenframework.specs.page.PageValidationListener;9import com.galenframework.validation.ValidationError;10import com.galenframework.validation.ValidationObject;11import com.galenframework.validation.ValidationResult;12import com.galenframework.validation.ValidationResultListener;13import com.galenframework.validation.ValidationResults;14import com.galenframework.validation.Validator;15import com.galenframework.validation.ValidationError.ErrorLevel;16import com.galenframework.validation.ValidationObject.ValidationObjectListener;17import com.galenframework.validation.ValidationObject.ValidationObjectListenerAdapter;18import com.galenframework.validation.ValidationResults.ValidationResultsListener;19import com.galenframework.validation.ValidationResults.ValidationResultsListenerAdapter;20import com.galenframework.validation.Validator;21import org.openqa.selenium.By;22import org.openqa.selenium.WebDriver;23import org.openqa.selenium.WebElement;24import org.openqa.selenium.chrome.ChromeDriver;25import org.openqa.selenium.chrome.ChromeOptions;26import org.openqa.selenium.support.ui.ExpectedConditions;27import org.openqa.selenium.support.ui.WebDriverWait;28import java.io.File;29import java.io.IOException;30import java.util.List;31public class GalenTest {32 public static void main(String[] args) throws IOException {33 System.setProperty("webdriver.chrome.driver", "/Users/ram/Documents/chromedriver");34 ChromeOptions options = new ChromeOptions();35 options.addArguments("--start-maximized");36 WebDriver driver = new ChromeDriver(options);37 WebDriverWait wait = new WebDriverWait(driver, 10);38 wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("q")));39 WebElement searchBox = driver.findElement(By.name("q"));40 searchBox.sendKeys("galenframework.com");41 searchBox.submit();42 wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("rso")));43 WebElement searchResult = driver.findElement(By.id("rso"));44 List<WebElement> searchResults = searchResult.findElements(By.tagName("a"));45 for (WebElement result : searchResults) {46 if (result.getText().equals
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!