Skip to content

Commit 2913f31

Browse files
authored
Merge pull request #1034 from seleniumbase/updates-to-visual-testing
Some updates to Visual Testing
2 parents 0f6221c + a17cf3b commit 2913f31

File tree

8 files changed

+128
-31
lines changed

8 files changed

+128
-31
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<h3 align="center"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.io/cdn/img/mac_sb_logo_5.png" alt="SeleniumBase" title="SeleniumBase" width="300" /></a></h3>
99
<!-- View on GitHub -->
10-
<h4 align="center">Better web testing with <a href="https://www.selenium.dev/documentation/">Selenium</a> and <a href="https://docs.pytest.org/en/latest/index.html">pytest</a>.</h4>
10+
<h4 align="center">Better web testing with <a href="https://www.selenium.dev/documentation/">Selenium</a> and <a href="https://docs.pytest.org/en/stable/">pytest</a>.</h4>
1111
<p align="center">
1212
<a href="https://github.com/seleniumbase/SeleniumBase/releases">
1313
<img src="https://img.shields.io/github/v/release/seleniumbase/SeleniumBase.svg?color=2277EE" alt="Latest Release on GitHub" /></a> <a href="https://pypi.python.org/pypi/seleniumbase">
@@ -84,8 +84,9 @@ pip install -e . # Editable install
8484
pip install seleniumbase
8585
```
8686

87-
> (Add ``--upgrade`` OR ``-U`` to upgrade an installation.)
88-
> (Add ``--force-reinstall`` to upgrade dependencies.)
87+
> (Add ``--upgrade`` OR ``-U`` to install the latest ``seleniumbase``.)
88+
> (Add ``--force-reinstall`` to also install the latest dependencies.)
89+
> (Add ``--index-url=http://pypi.python.org/simple/`` if blocked by a VPN.)
8990
> (Use ``pip3`` if multiple versions of Python are installed.)
9091
9192
🔵 Type ``seleniumbase`` or ``sbase`` to verify that SeleniumBase was installed successfully:

help_docs/method_summary.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,8 @@ self.switch_to_alert(timeout=None)
672672

673673
############
674674

675-
self.check_window(name="default", level=0, baseline=False, check_domain=True)
675+
self.check_window(
676+
name="default", level=0, baseline=False, check_domain=True, full_diff=False)
676677

677678
############
678679

@@ -682,6 +683,12 @@ self.deferred_assert_element(selector, by=By.CSS_SELECTOR, timeout=None)
682683
self.deferred_assert_text(text, selector="html", by=By.CSS_SELECTOR, timeout=None)
683684
# Duplicates: self.delayed_assert_text(text, selector="html", by=By.CSS_SELECTOR, timeout=None)
684685

686+
self.deferred_check_window(
687+
name="default", level=0, baseline=False, check_domain=True, full_diff=False)
688+
# Duplicates:
689+
# self.deferred_check_window(
690+
# name=name, level=level, baseline=baseline, check_domain=check_domain, full_diff=full_diff)
691+
685692
self.process_deferred_asserts(print_only=False)
686693
# Duplicates: self.process_delayed_asserts(print_only=False)
687694

mkdocs_build/requirements.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
regex>=2021.10.23
22
tqdm>=4.62.3
3+
docutils==0.17.1
4+
python-dateutil==2.8.2
35
livereload==2.6.3;python_version>="3.6"
46
joblib==1.1.0;python_version>="3.6"
57
Markdown==3.3.4;python_version>="3.6"
68
MarkupSafe==2.0.1;python_version>="3.6"
7-
jsmin==3.0.0;python_version>="3.6"
8-
docutils==0.17.1
9-
python-dateutil==2.8.2
9+
pyparsing==3.0.1;python_version>="3.6"
1010
keyring==23.2.1;python_version>="3.6"
1111
pkginfo==1.7.1;python_version>="3.6"
1212
Jinja2==3.0.2;python_version>="3.6"
@@ -16,6 +16,7 @@ readme-renderer==30.0
1616
pymdown-extensions==9.0;python_version>="3.6"
1717
importlib-metadata==4.8.1;python_version>="3.6"
1818
bleach==4.1.0
19+
jsmin==3.0.0;python_version>="3.6"
1920
lunr==0.6.1;python_version>="3.6"
2021
nltk==3.6.5;python_version>="3.6"
2122
watchdog==2.1.6;python_version>="3.6"

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ setuptools>=50.3.2;python_version>="3.5" and python_version<"3.6"
88
setuptools>=58.3.0;python_version>="3.6"
99
setuptools-scm==5.0.2;python_version<"3.6"
1010
setuptools-scm>=6.3.2;python_version>="3.6"
11-
tomli>=1.2.1;python_version>="3.6"
11+
tomli>=1.2.2;python_version>="3.6"
1212
wheel>=0.37.0
1313
attrs>=21.2.0
1414
PyYAML>=6.0;python_version>="3.6"
@@ -80,7 +80,7 @@ cryptography==35.0.0;python_version>="3.7"
8080
pygments==2.5.2;python_version<"3.5"
8181
pygments==2.10.0;python_version>="3.5"
8282
traitlets==4.3.3;python_version<"3.7"
83-
traitlets==5.1.0;python_version>="3.7"
83+
traitlets==5.1.1;python_version>="3.7"
8484
prompt-toolkit==1.0.18;python_version<"3.5"
8585
prompt-toolkit==2.0.10;python_version>="3.5" and python_version<"3.6.2"
8686
prompt-toolkit==3.0.21;python_version>="3.6.2"

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "2.0.6"
2+
__version__ = "2.0.7"

seleniumbase/fixtures/base_case.py

Lines changed: 92 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9292,7 +9292,12 @@ def __assert_eq(self, *args, **kwargs):
92929292
raise Exception(minified_exception)
92939293

92949294
def check_window(
9295-
self, name="default", level=0, baseline=False, check_domain=True
9295+
self,
9296+
name="default",
9297+
level=0,
9298+
baseline=False,
9299+
check_domain=True,
9300+
full_diff=False,
92969301
):
92979302
"""*** Automated Visual Testing with SeleniumBase ***
92989303
@@ -9351,6 +9356,10 @@ def check_window(
93519356
only makes sense if you're calling self.check_window() more than
93529357
once with the same name parameter in the same test.
93539358
9359+
If "full_diff" is set to False, the error output will only
9360+
include the first differing element in the list comparison.
9361+
Set "full_diff" to True if you want to see the full output.
9362+
93549363
Automated Visual Testing with self.check_window() is not very
93559364
effective for websites that have dynamic content that changes
93569365
the layout and structure of web pages. For those, you're much
@@ -9482,12 +9491,21 @@ def check_window(
94829491
self.assertEqual(page_data_domain, page_domain, domain_fail)
94839492
unittest.TestCase.maxDiff = 6400 # Use `None` for no limit
94849493
if level == 3:
9485-
self.__assert_eq(level_3_data, level_3, level_3_failure)
9494+
if not full_diff:
9495+
self.__assert_eq(level_3_data, level_3, level_3_failure)
9496+
else:
9497+
self.assertEqual(level_3_data, level_3, level_3_failure)
94869498
unittest.TestCase.maxDiff = 3200
94879499
if level == 2:
9488-
self.__assert_eq(level_2_data, level_2, level_2_failure)
9500+
if not full_diff:
9501+
self.__assert_eq(level_2_data, level_2, level_2_failure)
9502+
else:
9503+
self.assertEqual(level_2_data, level_2, level_2_failure)
94899504
if level == 1:
9490-
self.__assert_eq(level_1_data, level_1, level_1_failure)
9505+
if not full_diff:
9506+
self.__assert_eq(level_1_data, level_1, level_1_failure)
9507+
else:
9508+
self.assertEqual(level_1_data, level_1, level_1_failure)
94919509
unittest.TestCase.maxDiff = 6400 # Use `None` for no limit
94929510
if level == 0:
94939511
try:
@@ -9497,19 +9515,36 @@ def check_window(
94979515
page_domain, page_data_domain, domain_fail
94989516
)
94999517
try:
9500-
self.__assert_eq(
9501-
level_1_data, level_1, level_1_failure
9502-
)
9518+
if not full_diff:
9519+
self.__assert_eq(
9520+
level_1_data, level_1, level_1_failure
9521+
)
9522+
else:
9523+
self.assertEqual(
9524+
level_1_data, level_1, level_1_failure
9525+
)
95039526
except Exception as e:
95049527
print(e)
95059528
try:
9506-
self.__assert_eq(
9507-
level_2_data, level_2, level_2_failure
9508-
)
9529+
if not full_diff:
9530+
self.__assert_eq(
9531+
level_2_data, level_2, level_2_failure
9532+
)
9533+
else:
9534+
self.assertEqual(
9535+
level_2_data, level_2, level_2_failure
9536+
)
95099537
except Exception as e:
95109538
print(e)
95119539
unittest.TestCase.maxDiff = 6400 # Use `None` for no limit
9512-
self.__assert_eq(level_3_data, level_3, level_3_failure)
9540+
if not full_diff:
9541+
self.__assert_eq(
9542+
level_3_data, level_3, level_3_failure
9543+
)
9544+
else:
9545+
self.assertEqual(
9546+
level_3_data, level_3, level_3_failure
9547+
)
95139548
except Exception as e:
95149549
print(e) # Level-0 Dry Run (Only print the differences)
95159550
unittest.TestCase.maxDiff = None # Reset unittest.TestCase.maxDiff
@@ -9635,6 +9670,32 @@ def deferred_assert_text(
96359670
self.__add_deferred_assert_failure()
96369671
return False
96379672

9673+
def deferred_check_window(
9674+
self,
9675+
name="default",
9676+
level=0,
9677+
baseline=False,
9678+
check_domain=True,
9679+
full_diff=False,
9680+
):
9681+
"""A non-terminating assertion for the check_window() method.
9682+
Failures will be saved until the process_deferred_asserts()
9683+
method is called from inside a test, likely at the end of it."""
9684+
self.__check_scope()
9685+
self.__deferred_assert_count += 1
9686+
try:
9687+
self.check_window(
9688+
name=name,
9689+
level=level,
9690+
baseline=baseline,
9691+
check_domain=check_domain,
9692+
full_diff=full_diff,
9693+
)
9694+
return True
9695+
except Exception:
9696+
self.__add_deferred_assert_failure()
9697+
return False
9698+
96389699
def process_deferred_asserts(self, print_only=False):
96399700
"""To be used with any test that uses deferred_asserts, which are
96409701
non-terminating verifications that only raise exceptions
@@ -9657,7 +9718,7 @@ def process_deferred_asserts(self, print_only=False):
96579718
if print_only:
96589719
print(exception_output)
96599720
else:
9660-
raise Exception(exception_output)
9721+
raise Exception(exception_output.replace("\\n", "\n"))
96619722

96629723
############
96639724

@@ -9679,6 +9740,23 @@ def delayed_assert_text(
96799740
text=text, selector=selector, by=by, timeout=timeout
96809741
)
96819742

9743+
def delayed_check_window(
9744+
self,
9745+
name="default",
9746+
level=0,
9747+
baseline=False,
9748+
check_domain=True,
9749+
full_diff=False
9750+
):
9751+
""" Same as self.deferred_check_window() """
9752+
return self.deferred_check_window(
9753+
name=name,
9754+
level=level,
9755+
baseline=baseline,
9756+
check_domain=check_domain,
9757+
full_diff=full_diff,
9758+
)
9759+
96829760
def process_delayed_asserts(self, print_only=False):
96839761
""" Same as self.process_deferred_asserts() """
96849762
self.process_deferred_asserts(print_only=print_only)
@@ -10743,7 +10821,6 @@ def __create_log_path_as_needed(self, test_logpath):
1074310821

1074410822
def __process_dashboard(self, has_exception, init=False):
1074510823
""" SeleniumBase Dashboard Processing """
10746-
existing_res = sb_config._results # Used by multithreaded tests
1074710824
if self._multithreaded:
1074810825
abs_path = os.path.abspath(".")
1074910826
dash_json_loc = constants.Dashboard.DASH_JSON
@@ -10831,8 +10908,8 @@ def __process_dashboard(self, has_exception, init=False):
1083110908
sb_config.item_count_untested -= 1
1083210909
elif (
1083310910
self._multithreaded
10834-
and test_id in existing_res.keys()
10835-
and existing_res[test_id] == "Skipped"
10911+
and test_id in sb_config._results.keys()
10912+
and sb_config._results[test_id] == "Skipped"
1083610913
):
1083710914
sb_config._results[test_id] = "Skipped"
1083810915
sb_config.item_count_skipped += 1

seleniumbase/plugins/pytest_plugin.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ def _perform_pytest_unconfigure_():
14831483
pass
14841484

14851485

1486-
def pytest_unconfigure():
1486+
def pytest_unconfigure(config):
14871487
""" This runs after all tests have completed with pytest. """
14881488
if hasattr(sb_config, "_multithreaded") and sb_config._multithreaded:
14891489
import fasteners
@@ -1492,7 +1492,6 @@ def pytest_unconfigure():
14921492
if (
14931493
hasattr(sb_config, "dashboard")
14941494
and sb_config.dashboard
1495-
and sb_config._dash_html
14961495
):
14971496
# Multi-threaded tests with the Dashboard
14981497
abs_path = os.path.abspath(".")
@@ -1502,17 +1501,29 @@ def pytest_unconfigure():
15021501
sb_config._only_unittest = False
15031502
dashboard_path = os.path.join(abs_path, "dashboard.html")
15041503
with dash_lock:
1505-
with open(dashboard_path, "w", encoding="utf-8") as f:
1506-
f.write(sb_config._dash_html)
1504+
if (
1505+
sb_config._dash_html
1506+
and config.getoption("htmlpath") == "dashboard.html"
1507+
):
1508+
# Dash is HTML Report (Multithreaded)
1509+
sb_config._dash_is_html_report = True
1510+
with open(dashboard_path, "w", encoding="utf-8") as f:
1511+
f.write(sb_config._dash_html)
1512+
# Dashboard Multithreaded
15071513
_perform_pytest_unconfigure_()
15081514
return
1515+
else:
1516+
# Dash Lock is missing
1517+
_perform_pytest_unconfigure_()
1518+
return
15091519
with dash_lock:
15101520
# Multi-threaded tests
15111521
_perform_pytest_unconfigure_()
15121522
return
15131523
else:
15141524
# Single-threaded tests
15151525
_perform_pytest_unconfigure_()
1526+
return
15161527

15171528

15181529
@pytest.fixture()

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
'setuptools>=58.3.0;python_version>="3.6"',
125125
'setuptools-scm==5.0.2;python_version<"3.6"',
126126
'setuptools-scm>=6.3.2;python_version>="3.6"',
127-
'tomli>=1.2.1;python_version>="3.6"',
127+
'tomli>=1.2.2;python_version>="3.6"',
128128
"wheel>=0.37.0",
129129
"attrs>=21.2.0",
130130
'PyYAML>=6.0;python_version>="3.6"',
@@ -196,7 +196,7 @@
196196
'pygments==2.5.2;python_version<"3.5"',
197197
'pygments==2.10.0;python_version>="3.5"',
198198
'traitlets==4.3.3;python_version<"3.7"',
199-
'traitlets==5.1.0;python_version>="3.7"',
199+
'traitlets==5.1.1;python_version>="3.7"',
200200
'prompt-toolkit==1.0.18;python_version<"3.5"',
201201
'prompt-toolkit==2.0.10;python_version>="3.5" and python_version<"3.6.2"', # noqa: E501
202202
'prompt-toolkit==3.0.21;python_version>="3.6.2"',

0 commit comments

Comments
 (0)