*** Automated Visual Testing with SeleniumBase *** The first time a test calls self.check_window() for a unique "name" parameter provided, it will set a visual baseline, meaning that it creates a folder, saves the URL to a file, saves the current window screenshot
(
self,
name="default",
level=0,
baseline=False,
check_domain=True,
full_diff=False,
)
| 11604 | out_file.close() |
| 11605 | |
| 11606 | def check_window( |
| 11607 | self, |
| 11608 | name="default", |
| 11609 | level=0, |
| 11610 | baseline=False, |
| 11611 | check_domain=True, |
| 11612 | full_diff=False, |
| 11613 | ): |
| 11614 | """*** Automated Visual Testing with SeleniumBase *** |
| 11615 | |
| 11616 | The first time a test calls self.check_window() for a unique "name" |
| 11617 | parameter provided, it will set a visual baseline, meaning that it |
| 11618 | creates a folder, saves the URL to a file, saves the current window |
| 11619 | screenshot to a file, and creates the following three files |
| 11620 | with the listed data saved: |
| 11621 | tags_level1.txt -> HTML tags from the window |
| 11622 | tags_level2.txt -> HTML tags + attributes from the window |
| 11623 | tags_level3.txt -> HTML tags + attributes/values from the window |
| 11624 | |
| 11625 | Baseline folders are named based on the test name and the name |
| 11626 | parameter passed to self.check_window(). The same test can store |
| 11627 | multiple baseline folders. |
| 11628 | |
| 11629 | If the baseline is being set/reset, the "level" doesn't matter. |
| 11630 | |
| 11631 | After the first run of self.check_window(), it will compare the |
| 11632 | HTML tags of the latest window to the one from the initial run. |
| 11633 | Here's how the level system works: |
| 11634 | * level=0 -> |
| 11635 | DRY RUN ONLY - Will perform comparisons to the baseline (and |
| 11636 | print out any differences that are found) but |
| 11637 | won't fail the test even if differences exist. |
| 11638 | * level=1 -> |
| 11639 | HTML tags are compared to tags_level1.txt |
| 11640 | * level=2 -> |
| 11641 | HTML tags are compared to tags_level1.txt and |
| 11642 | HTML tags/attributes are compared to tags_level2.txt |
| 11643 | * level=3 -> |
| 11644 | HTML tags are compared to tags_level1.txt and |
| 11645 | HTML tags + attributes are compared to tags_level2.txt and |
| 11646 | HTML tags + attributes/values are compared to tags_level3.txt |
| 11647 | As shown, Level-3 is the most strict, Level-1 is the least strict. |
| 11648 | If the comparisons from the latest window to the existing baseline |
| 11649 | don't match, the current test will fail, except for Level-0 tests. |
| 11650 | |
| 11651 | You can reset the visual baseline on the command line by using: |
| 11652 | --visual_baseline |
| 11653 | As long as "--visual_baseline" is used on the command line while |
| 11654 | running tests, the self.check_window() method cannot fail because |
| 11655 | it will rebuild the visual baseline rather than comparing the html |
| 11656 | tags of the latest run to the existing baseline. If there are any |
| 11657 | expected layout changes to a website that you're testing, you'll |
| 11658 | need to reset the baseline to prevent unnecessary failures. |
| 11659 | |
| 11660 | self.check_window() will fail with "Page Domain Mismatch Failure" |
| 11661 | if the page domain doesn't match the domain of the baseline, |
| 11662 | unless "check_domain" is set to False when calling check_window(). |
| 11663 |