You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The purpose of automated visual/layout testing is to help you determine when something has changed the layout of a web page. Rather than comparing screenshots, a more effective way is to compare HTML tags at different points in time on the same web page. If a change is detected, it could mean that something broke on the webpage, or it might be something harmless like a website redesign or dynamic content loading on the web page. To handle automated visual/layout testing, SeleniumBase uses the ``self.check_window()`` method, which can set visual baselines for comparison and then compare the latest versions of web pages to the existing baseline.
3
+
Automated visual testing can help you determine when something has changed the layout of a web page. Rather than comparing screenshots, a more effective way is to detect layout differences by comparing HTML tags and properties. If a change is detected, it could mean that something broke on the webpage, or possibly something harmless like a website redesign or dynamic content.
4
4
5
-
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 to a file, and creates the following three files with the listed data saved:
5
+
To handle automated visual testing, SeleniumBase uses the ``self.check_window()`` method, which can set visual baselines for comparison and then compare the latest versions of web pages to the existing baseline.
6
+
7
+
The first time a test calls ``self.check_window()`` with a unique "name" parameter, the visual baseline is set, which means a folder is created with the following files:
8
+
* page_url.txt -> The URL of the current window
9
+
* screenshot.png -> A screenshot of the current window
6
10
* tags_level1.txt -> HTML tags from the window
7
11
* tags_level2.txt -> HTML tags + attributes from the window
8
12
* tags_level3.txt -> HTML tags + attributes/values from the window
9
13
10
-
Baseline folders are named based on the test name and the name parameter passed to ``self.check_window()``. The same test can store multiple baseline folders.
14
+
After the first run of ``self.check_window()``, it will compare the HTML tags of the latest window to the one from the initial baseline run.
11
15
12
-
If the baseline is being set/reset, the "level" doesn't matter.
16
+
Here's an example call:
17
+
```
18
+
self.check_window(name="first_test)", level=1)
19
+
```
20
+
On the first run (<i>or if the baseline is being set/reset</i>) the "level" doesn't matter because that's only used for comparing the current layout to the existing baseline.
13
21
14
-
After the first run of ``self.check_window()``, it will compare the HTML tags of the latest window to the one from the initial run.
15
22
Here's how the level system works:
16
23
* level=0 ->
17
-
DRY RUN ONLY - Will perform a comparison to the baseline, and
18
-
print out any differences that are found, but
19
-
won't fail the test even if differences exist.
24
+
DRY RUN ONLY - Will perform a comparison to the baseline, and print out any differences that are found, but won't fail the test even if differences exist.
20
25
* level=1 ->
21
26
HTML tags are compared to tags_level1.txt
22
27
* level=2 ->
@@ -29,20 +34,54 @@ Here's how the level system works:
29
34
30
35
As shown, Level-3 is the most strict, Level-1 is the least strict. If the comparisons from the latest window to the existing baseline don't match, the current test will fail, except for Level-0 tests.
31
36
32
-
You can reset the visual baseline on the command line by using:
33
-
``--visual_baseline``
37
+
You can reset the visual baseline on the command line by adding the following parameter at runtime:
38
+
``--visual_baseline``
39
+
34
40
As long as ``--visual_baseline`` is used on the command line while running tests, the ``self.check_window()`` method cannot fail because it will rebuild the visual baseline rather than comparing the html tags of the latest run to the existing baseline. If there are any expected layout changes to a website that you're testing, you'll need to reset the baseline to prevent unnecessary failures.
35
41
36
-
``self.check_window()`` will fail with "Page Domain Mismatch Failure" if the page domain doesn't match the domain of the baseline.
42
+
``self.check_window()`` will fail with "Page Domain Mismatch Failure" if the domain of the current URL doesn't match the domain of the baseline URL.
37
43
38
-
If you want to use ``self.check_window()`` to compare a web page to a later version of itself from within the same test run, you can add the parameter ``baseline=True`` to the first time you call ``self.check_window()`` in a test to use that as the baseline. This only makes sense if you're calling ``self.check_window()`` more than once with the same name parameter in the same test.
44
+
If you want to use ``self.check_window()`` to compare a web page to a later version of itself from within the same test run, you can add the parameter ``baseline=True`` to the first time you call ``self.check_window()`` in a test to use that as the baseline. This only makes sense if you're calling ``self.check_window()`` more than once with the same "name" parameter in the same test.
39
45
40
-
Automated Visual/Layout Testing with ``self.check_window()`` is not very effective for websites that have dynamic content that changes the layout and structure of web pages. For those, you're much better off using regular SeleniumBase functional testing.
46
+
Automated Visual Testing with ``self.check_window()`` is not very effective for websites that have dynamic content because that changes the layout and structure of web pages. For those pages, you're much better off using regular SeleniumBase functional testing.
0 commit comments