Skip to content

Commit e8b8338

Browse files
authored
Merge pull request #1104 from seleniumbase/fix-visual-tests-that-use-the-sb-fixture
Fix visual tests that use the "sb" fixture (and more!)
2 parents d77472c + 98b8990 commit e8b8338

File tree

10 files changed

+58
-34
lines changed

10 files changed

+58
-34
lines changed

examples/custom_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
# Waiting for Document.readyState to be "Complete" after browser actions.
2121
WAIT_FOR_RSC_ON_PAGE_LOADS = True
22-
WAIT_FOR_RSC_ON_CLICKS = True
22+
WAIT_FOR_RSC_ON_CLICKS = False
2323
WAIT_FOR_ANGULARJS = True
2424

2525
# Changing the default behavior of Demo Mode. Activate with: --demo_mode

examples/github_test.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ def test_github(self):
99
# To avoid this automation blocker, two steps are being taken:
1010
# 1. self.slow_click() is being used to slow down Selenium actions.
1111
# 2. The browser's User Agent is modified to avoid Selenium-detection
12-
# when running in headless mode on Chrome or Edge (Chromium).
13-
if self.headless and (
14-
self.browser == "chrome" or self.browser == "edge"
15-
):
12+
# when running in headless mode.
13+
if self.headless:
1614
self.get_new_driver(
1715
agent="""Mozilla/5.0 """
1816
"""AppleWebKit/537.36 (KHTML, like Gecko) """
19-
"""Chrome/92.0.4515.159 Safari/537.36"""
17+
"""Chrome/Version 96.0.4664.55 Safari/537.36"""
2018
)
2119
self.open("https://github.com/search?q=SeleniumBase")
2220
self.slow_click('a[href="/seleniumbase/SeleniumBase"]')

examples/handle_alert_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
class HandleAlertTests(BaseCase):
55
def test_alerts(self):
6-
if self.browser == "safari":
7-
self.skip("This test doesn't run on Safari! (alert issues)")
86
self.open("about:blank")
97
self.execute_script('window.alert("ALERT!!!");')
108
self.sleep(1) # Not needed (Lets you see the alert pop up)
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1+
""" Visual Layout Testing with different Syntax Formats """
2+
13
from seleniumbase import BaseCase
24

35

6+
class VisualLayout_FixtureTests():
7+
def test_python_home_change(sb):
8+
sb.open("https://python.org/")
9+
print('\nCreating baseline in "visual_baseline" folder.')
10+
sb.check_window(name="python_home", baseline=True)
11+
# Remove the "Donate" button
12+
sb.remove_element("a.donate-button")
13+
print("(This test should fail)") # due to missing button
14+
sb.check_window(name="python_home", level=3)
15+
16+
417
class VisualLayoutFailureTests(BaseCase):
518
def test_applitools_change(self):
619
self.open("https://applitools.com/helloworld?diff1")
@@ -10,24 +23,15 @@ def test_applitools_change(self):
1023
self.click('a[href="?diff1"]')
1124
# Click a button that makes a hidden element visible
1225
self.click("button")
13-
print("(This test should fail)")
26+
print("(This test should fail)") # due to image now seen
1427
self.check_window(name="helloworld", level=3)
1528

16-
def test_python_home_change(self):
17-
self.open("https://python.org/")
18-
print('\nCreating baseline in "visual_baseline" folder.')
19-
self.check_window(name="python_home", baseline=True)
20-
# Remove the "Donate" button
21-
self.remove_element("a.donate-button")
22-
print("(This test should fail)")
23-
self.check_window(name="python_home", level=3)
24-
2529
def test_xkcd_logo_change(self):
2630
self.open("https://xkcd.com/554/")
2731
print('\nCreating baseline in "visual_baseline" folder.')
2832
self.check_window(name="xkcd_554", baseline=True)
2933
# Change height: (83 -> 110) , Change width: (185 -> 120)
3034
self.set_attribute('[alt="xkcd.com logo"]', "height", "110")
3135
self.set_attribute('[alt="xkcd.com logo"]', "width", "120")
32-
print("(This test should fail)")
36+
print("(This test should fail)") # due to a resized logo
3337
self.check_window(name="xkcd_554", level=3)

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ theme:
4545
# - navigation.sections
4646
- navigation.expand
4747
# - navigation.tabs
48+
- navigation.top
4849
- navigation.tracking
4950
- navigation.instant
5051
palette:

mkdocs_build/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ lunr==0.6.1;python_version>="3.6"
2121
nltk==3.6.5;python_version>="3.6"
2222
watchdog==2.1.6;python_version>="3.6"
2323
mkdocs==1.2.3;python_version>="3.6"
24-
mkdocs-material==8.0.2;python_version>="3.6"
24+
mkdocs-material==8.0.3;python_version>="3.6"
2525
mkdocs-exclude-search==0.5.4;python_version>="3.6"
2626
mkdocs-simple-hooks==0.1.3
2727
mkdocs-material-extensions==1.0.3;python_version>="3.6"

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.2.5"
2+
__version__ = "2.2.6"

seleniumbase/config/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
# Called after self.open(url) or self.open_url(url), NOT self.driver.open(url)
5555
WAIT_FOR_RSC_ON_PAGE_LOADS = True
5656
# Called after self.click(selector), NOT element.click()
57-
WAIT_FOR_RSC_ON_CLICKS = True
57+
WAIT_FOR_RSC_ON_CLICKS = False
5858

5959
"""
6060
This adds wait_for_angularjs() after various browser actions.

seleniumbase/fixtures/base_case.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ def open(self, url):
139139
""" Navigates the current browser window to the specified page. """
140140
self.__check_scope()
141141
self.__check_browser()
142+
pre_action_url = None
143+
try:
144+
pre_action_url = self.driver.current_url
145+
except Exception:
146+
pass
142147
if type(url) is str:
143148
url = url.strip() # Remove leading and trailing whitespace
144149
if (type(url) is not str) or not self.__looks_like_a_page_url(url):
@@ -170,6 +175,11 @@ def open(self, url):
170175
self.driver.get(url)
171176
else:
172177
raise Exception(e.msg)
178+
if (
179+
self.driver.current_url == pre_action_url
180+
and pre_action_url != url
181+
):
182+
time.sleep(0.1) # Make sure load happens
173183
if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
174184
self.wait_for_ready_state_complete()
175185
self.__demo_mode_pause_if_active()
@@ -9555,12 +9565,15 @@ def __process_visual_baseline_logs(self):
95559565
test_logpath = os.path.join(self.log_path, self.__get_test_id())
95569566
for baseline_copy_tuple in self.__visual_baseline_copies:
95579567
baseline_path = baseline_copy_tuple[0]
9558-
baseline_copy_path = baseline_copy_tuple[1]
9559-
b_c_alt_path = baseline_copy_tuple[2]
9568+
baseline_copy_name = baseline_copy_tuple[1]
9569+
b_c_alt_name = baseline_copy_tuple[2]
95609570
latest_png_path = baseline_copy_tuple[3]
9561-
latest_copy_path = baseline_copy_tuple[4]
9562-
l_c_alt_path = baseline_copy_tuple[5]
9563-
9571+
latest_copy_name = baseline_copy_tuple[4]
9572+
l_c_alt_name = baseline_copy_tuple[5]
9573+
baseline_copy_path = os.path.join(test_logpath, baseline_copy_name)
9574+
b_c_alt_path = os.path.join(test_logpath, b_c_alt_name)
9575+
latest_copy_path = os.path.join(test_logpath, latest_copy_name)
9576+
l_c_alt_path = os.path.join(test_logpath, l_c_alt_name)
95649577
if len(self.__visual_baseline_copies) == 1:
95659578
baseline_copy_path = b_c_alt_path
95669579
latest_copy_path = l_c_alt_path
@@ -9798,19 +9811,14 @@ def check_window(
97989811
out_file.writelines(json.dumps(level_3))
97999812
out_file.close()
98009813

9801-
test_logpath = os.path.join(self.log_path, self.__get_test_id())
98029814
baseline_path = os.path.join(visual_baseline_path, baseline_png)
98039815
baseline_copy_name = "baseline_%s.png" % name
9804-
baseline_copy_path = os.path.join(test_logpath, baseline_copy_name)
98059816
b_c_alt_name = "baseline.png"
9806-
b_c_alt_path = os.path.join(test_logpath, b_c_alt_name)
98079817
latest_copy_name = "baseline_diff_%s.png" % name
9808-
latest_copy_path = os.path.join(test_logpath, latest_copy_name)
98099818
l_c_alt_name = "baseline_diff.png"
9810-
l_c_alt_path = os.path.join(test_logpath, l_c_alt_name)
98119819
baseline_copy_tuple = (
9812-
baseline_path, baseline_copy_path, b_c_alt_path,
9813-
latest_png_path, latest_copy_path, l_c_alt_path,
9820+
baseline_path, baseline_copy_name, b_c_alt_name,
9821+
latest_png_path, latest_copy_name, l_c_alt_name,
98149822
)
98159823
self.__visual_baseline_copies.append(baseline_copy_tuple)
98169824

seleniumbase/fixtures/js_utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ def wait_for_css_query_selector(
247247

248248

249249
def highlight_with_js(driver, selector, loops, o_bs):
250+
try:
251+
# This closes any pop-up alerts
252+
driver.execute_script("")
253+
except Exception:
254+
pass
250255
script = (
251256
"""document.querySelector('%s').style.boxShadow =
252257
'0px 0px 6px 6px rgba(128, 128, 128, 0.5)';"""
@@ -308,6 +313,11 @@ def highlight_with_js(driver, selector, loops, o_bs):
308313

309314

310315
def highlight_with_jquery(driver, selector, loops, o_bs):
316+
try:
317+
# This closes any pop-up alerts
318+
driver.execute_script("")
319+
except Exception:
320+
pass
311321
script = (
312322
"""jQuery('%s').css('box-shadow',
313323
'0px 0px 6px 6px rgba(128, 128, 128, 0.5)');"""
@@ -689,6 +699,11 @@ def post_messenger_error_message(driver, message, msg_dur):
689699

690700

691701
def highlight_with_js_2(driver, message, selector, o_bs, msg_dur):
702+
try:
703+
# This closes any pop-up alerts
704+
driver.execute_script("")
705+
except Exception:
706+
pass
692707
if selector == "html":
693708
selector = "body"
694709
script = (

0 commit comments

Comments
 (0)