Skip to content

Commit 592dfba

Browse files
authored
Merge pull request #301 from seleniumbase/automated-visual-testing
Automated Visual Testing
2 parents 4553a90 + 932ee24 commit 592dfba

File tree

11 files changed

+419
-22
lines changed

11 files changed

+419
-22
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ report.xml
6666
# Tours
6767
tours_exported
6868

69+
# Automated Visual Testing
70+
visual_baseline
71+
6972
# Other
7073
selenium-server-standalone.jar
7174
proxy.zip

examples/visual_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from seleniumbase import BaseCase
2+
3+
4+
class AutomatedVisualTest(BaseCase):
5+
6+
def test_applitools_helloworld(self):
7+
self.open('https://applitools.com/helloworld?diff1')
8+
print('Creating baseline in "visual_baseline" folder...')
9+
self.check_window(name="helloworld", baseline=True)
10+
self.click('a[href="?diff1"]')
11+
# Verify html tags match previous version
12+
self.check_window(name="helloworld", level=1)
13+
# Verify html tags + attributes match previous version
14+
self.check_window(name="helloworld", level=2)
15+
# Verify html tags + attributes + values match previous version
16+
self.check_window(name="helloworld", level=3)
17+
# Change the page enough for a Level-3 comparison to fail
18+
self.click("button")
19+
self.check_window(name="helloworld", level=1)
20+
self.check_window(name="helloworld", level=2)
21+
with self.assertRaises(Exception):
22+
self.check_window(name="helloworld", level=3)
23+
# Now that we know the exception was raised as expected,
24+
# let's print out the comparison results by running in Level-0.
25+
self.check_window(name="helloworld", level=0)

help_docs/method_summary.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ self.get_domain_url(url)
172172

173173
self.get_beautiful_soup(source=None)
174174

175+
self.get_unique_links()
176+
177+
self.get_link_status_code(link, allow_redirects=False, timeout=5)
178+
179+
self.assert_no_404_errors()
180+
181+
self.print_unique_links_with_status_codes()
182+
175183
self.safe_execute_script(script)
176184

177185
self.download_file(file_url, destination_folder=None)
@@ -345,6 +353,8 @@ self.switch_to_window(window, timeout=settings.SMALL_TIMEOUT)
345353

346354
self.switch_to_default_window()
347355

356+
self.check_window(name="default", level=0, baseline=False)
357+
348358
self.save_screenshot(name, folder=None)
349359

350360
self.get_new_driver(browser=None, headless=None, servername=None, port=None,

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ unittest2
88
selenium==3.141.0
99
requests==2.21.0
1010
urllib3==1.24.1
11-
pytest>=4.3.1
11+
pytest>=4.4.0
1212
pytest-cov>=2.6.1
1313
pytest-html>=1.20.0
14-
pytest-rerunfailures>=6.0
15-
pytest-xdist>=1.26.1
14+
pytest-rerunfailures>=7.0
15+
pytest-xdist>=1.27.0
1616
parameterized>=0.7.0
1717
beautifulsoup4>=4.6.0
1818
colorama==0.4.1

seleniumbase/core/visual_helper.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
from seleniumbase.fixtures import constants
3+
4+
VISUAL_BASELINE_DIR = constants.VisualBaseline.STORAGE_FOLDER
5+
abs_path = os.path.abspath('.')
6+
visual_baseline_path = os.path.join(abs_path, VISUAL_BASELINE_DIR)
7+
8+
9+
def get_visual_baseline_folder():
10+
return visual_baseline_path
11+
12+
13+
def visual_baseline_folder_setup():
14+
""" Handle Logging """
15+
if not os.path.exists(visual_baseline_path):
16+
try:
17+
os.makedirs(visual_baseline_path)
18+
except Exception:
19+
pass # Should only be reachable during multi-threaded runs

0 commit comments

Comments
 (0)