Skip to content

Commit b764edd

Browse files
committed
Update a ReadMe and test comments
1 parent 1dbac6e commit b764edd

File tree

3 files changed

+46
-28
lines changed

3 files changed

+46
-28
lines changed

examples/visual_testing/ReadMe.md

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ If you want to use ``self.check_window()`` to compare a web page to a later vers
4343

4444
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, unless you can remove the dynamic content before performing the comparison, (such as by using ``self.ad_block()`` to remove dynamic ad content on a web page).
4545

46-
Example usage of ``self.check_window()``:
46+
Example usage of ``self.check_window()`` with different levels:
4747
```python
4848
self.check_window(name="testing", level=0)
4949
self.check_window(name="xkcd_home", level=1)
@@ -55,37 +55,23 @@ Example usage of ``self.check_window()``:
5555
self.check_window(name="helloworld", level=3)
5656
```
5757

58-
Full example test:
58+
Here's an example where clicking a button makes a hidden element visible:
5959
```python
6060
from seleniumbase import BaseCase
6161

62-
6362
class VisualLayoutTest(BaseCase):
6463

65-
def test_applitools_layout_change(self):
64+
def test_applitools_layout_change_failure(self):
6665
self.open('https://applitools.com/helloworld?diff1')
67-
print('\nCreating baseline in "visual_baseline" folder...')
66+
print('\nCreating baseline in "visual_baseline" folder.')
6867
self.check_window(name="helloworld", baseline=True)
68+
# Click a button that changes the text of an element
6969
self.click('a[href="?diff1"]')
70-
# Verify html tags match previous version
71-
self.check_window(name="helloworld", level=1)
72-
# Verify html tags and attribute names match previous version
73-
self.check_window(name="helloworld", level=2)
74-
# Verify html tags and attribute values match previous version
75-
self.check_window(name="helloworld", level=3)
76-
# Change the page enough for a Level-3 comparison to fail
70+
# Click a button that makes a hidden element visible
7771
self.click("button")
78-
self.check_window(name="helloworld", level=1)
79-
self.check_window(name="helloworld", level=2)
80-
with self.assertRaises(Exception):
81-
self.check_window(name="helloworld", level=3)
82-
# Now that we know the Exception was raised as expected,
83-
# let's print out the comparison results by running in Level-0.
84-
# (NOTE: Running with level-0 will print but NOT raise an Exception.)
85-
self.check_window(name="helloworld", level=0)
72+
self.check_window(name="helloworld", level=3)
8673
```
87-
88-
Here's the output of that:
74+
Here's the output of that: (<i>Text changes do not impact visual comparisons</i>)
8975
```
9076
AssertionError:
9177
First differing element 39:
@@ -100,23 +86,52 @@ First differing element 39:
10086
* HTML tag attribute values don't match the baseline!
10187
```
10288

103-
Here's another example:
89+
Here's an example where a button is removed from a web page:
10490
```python
10591
from seleniumbase import BaseCase
10692

93+
class VisualLayoutTest(BaseCase):
94+
95+
def test_python_home_layout_change_failure(self):
96+
self.open('https://python.org/')
97+
print('\nCreating baseline in "visual_baseline" folder.')
98+
self.check_window(name="github_home", baseline=True)
99+
# Remove the "Donate" button
100+
self.remove_element('a.donate-button')
101+
self.check_window(name="github_home", level=3)
102+
```
103+
Here's the output of that:
104+
```
105+
AssertionError:
106+
First differing element 33:
107+
['a', [['class', ['donate-button']], ['href', '/psf/donations/']]]
108+
['div', [['class', ['options-bar']]]]
109+
110+
- ['a', [['class', ['donate-button']], ['href', '/psf/donations/']]],
111+
- 'display: list-item; opacity: 0.995722;']]],
112+
? -------------------
113+
+ 'display: list-item;']]],
114+
*
115+
*** Exception: <Level 3> Visual Diff Failure:
116+
* HTML tag attribute values don't match the baseline!
117+
118+
```
119+
120+
Here's an example where a web site logo is resized:
121+
```python
122+
from seleniumbase import BaseCase
107123

108124
class VisualLayoutTest(BaseCase):
109125

110-
def test_xkcd_layout_change(self):
126+
def test_xkcd_layout_change_failure(self):
111127
self.open('https://xkcd.com/554/')
112128
print('\nCreating baseline in "visual_baseline" folder.')
113129
self.check_window(name="xkcd_554", baseline=True)
114130
# Change height: (83 -> 130) , Change width: (185 -> 120)
115131
self.set_attribute('[alt="xkcd.com logo"]', "height", "130")
116132
self.set_attribute('[alt="xkcd.com logo"]', "width", "120")
117-
self.check_window(name="xkcd_554", level=0)
133+
self.check_window(name="xkcd_554", level=3)
118134
```
119-
120135
Here's the output of that:
121136
```
122137
AssertionError:

examples/visual_testing/layout_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ def test_applitools_layout_change(self):
77
self.open('https://applitools.com/helloworld?diff1')
88
print('\nCreating baseline in "visual_baseline" folder.')
99
self.check_window(name="helloworld", baseline=True)
10+
# Click a button that changes the text of an element
11+
# (Text changes do not impact visual comparisons)
1012
self.click('a[href="?diff1"]')
1113
# Verify html tags match the baseline
1214
self.check_window(name="helloworld", level=1)
1315
# Verify html tags and attribute names match the baseline
1416
self.check_window(name="helloworld", level=2)
1517
# Verify html tags and attribute values match the baseline
1618
self.check_window(name="helloworld", level=3)
17-
# Change the page enough for a Level-3 comparison to fail
19+
# Click a button that makes a hidden element visible
1820
self.click("button")
1921
self.check_window(name="helloworld", level=1)
2022
self.check_window(name="helloworld", level=2)

examples/visual_testing/test_layout_fail.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ def test_applitools_layout_change_failure(self):
77
self.open('https://applitools.com/helloworld?diff1')
88
print('\nCreating baseline in "visual_baseline" folder.')
99
self.check_window(name="helloworld", baseline=True)
10+
# Click a button that changes the text of an element
1011
self.click('a[href="?diff1"]')
11-
# Change the page enough for a Level-3 comparison to fail
12+
# Click a button that makes a hidden element visible
1213
self.click("button")
1314
self.check_window(name="helloworld", level=3)
1415

0 commit comments

Comments
 (0)