Skip to content

Commit 63c29c4

Browse files
authored
Merge pull request #1445 from seleniumbase/handle-clicks-that-close-windows
Handle clicks that close the active window
2 parents 301a86b + c2bae48 commit 63c29c4

File tree

7 files changed

+72
-26
lines changed

7 files changed

+72
-26
lines changed

examples/proxy_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ def test_proxy(self):
1414
if row.strip() != "":
1515
data.append(row.strip())
1616
print("\n".join(data).replace('\n"', " "))
17-
print("\nThe browser will close automatically in 7 seconds...")
18-
self.sleep(7)
17+
if not self.headless:
18+
print("\nThe browser will close automatically in 7 seconds...")
19+
self.sleep(7)

examples/test_docs_site.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33

44
class DocsSiteTests(BaseCase):
55
def test_docs(self):
6-
self.open("https://seleniumbase.io/")
7-
self.assert_text("SeleniumBase", "h1")
8-
self.js_click('a[href="help_docs/features_list/"]')
9-
self.assert_exact_text("Features List", "h1")
10-
self.js_click('a[href="../../examples/ReadMe/"]')
6+
self.open("https://seleniumbase.io/examples/ReadMe/")
117
self.assert_exact_text("Running Example Tests", "h1")
128
self.js_click('a[href="../../help_docs/customizing_test_runs/"]')
139
self.assert_exact_text("Command Line Options", "h1")

mkdocs_build/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ livereload==2.6.3
99
joblib==1.1.0
1010
Markdown==3.3.7
1111
MarkupSafe==2.1.1
12-
pyparsing==3.0.9
1312
keyring==23.7.0
1413
pkginfo==1.8.3
1514
Jinja2==3.1.2

requirements.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
pip>=20.3.4;python_version<"3.6"
22
pip>=21.3.1;python_version>="3.6" and python_version<"3.7"
3-
pip>=22.2.1;python_version>="3.7"
3+
pip>=22.2.2;python_version>="3.7"
44
packaging>=20.9;python_version<"3.6"
55
packaging>=21.3;python_version>="3.6"
66
setuptools>=44.1.1;python_version<"3.6"
77
setuptools>=59.6.0;python_version>="3.6" and python_version<"3.7"
8-
setuptools>=63.3.0;python_version>="3.7"
8+
setuptools>=63.4.1;python_version>="3.7"
99
tomli>=1.2.3;python_version>="3.6" and python_version<"3.7"
1010
tomli>=2.0.1;python_version>="3.7"
1111
wheel>=0.37.1
@@ -22,6 +22,9 @@ filelock>=3.7.1;python_version>="3.7"
2222
platformdirs>=2.0.2;python_version<"3.6"
2323
platformdirs>=2.4.0;python_version>="3.6" and python_version<"3.7"
2424
platformdirs>=2.5.2;python_version>="3.7"
25+
pyparsing>=2.4.7;python_version<"3.6"
26+
pyparsing>=3.0.7;python_version>="3.6" and python_version<"3.7"
27+
pyparsing>=3.0.9;python_version>="3.7"
2528
six==1.16.0
2629
ipdb==0.13.4;python_version<"3.6"
2730
ipdb==0.13.9;python_version>="3.6"
@@ -123,10 +126,10 @@ coverage==6.4.2;python_version>="3.7"
123126
pytest-cov==2.12.1;python_version<"3.6"
124127
pytest-cov==3.0.0;python_version>="3.6"
125128
flake8==3.7.9;python_version<"3.6"
126-
flake8==5.0.2;python_version>="3.6"
129+
flake8==5.0.4;python_version>="3.6"
127130
mccabe==0.6.1;python_version<"3.6"
128131
mccabe==0.7.0;python_version>="3.6"
129132
pyflakes==2.1.1;python_version<"3.6"
130133
pyflakes==2.5.0;python_version>="3.6"
131134
pycodestyle==2.5.0;python_version<"3.6"
132-
pycodestyle==2.9.0;python_version>="3.6"
135+
pycodestyle==2.9.1;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__ = "3.5.9"
2+
__version__ = "3.5.10"

seleniumbase/fixtures/base_case.py

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -416,18 +416,32 @@ def click(
416416
)
417417
):
418418
self.__switch_to_newest_window_if_not_blank()
419+
elif (
420+
latest_window_count == pre_window_count - 1
421+
and latest_window_count > 0
422+
):
423+
# If a click closes the active window,
424+
# switch to the last one if it exists.
425+
self.switch_to_window(-1)
419426
if settings.WAIT_FOR_RSC_ON_CLICKS:
420-
self.wait_for_ready_state_complete()
427+
try:
428+
self.wait_for_ready_state_complete()
429+
except Exception:
430+
pass
421431
else:
422432
# A smaller subset of self.wait_for_ready_state_complete()
423-
self.wait_for_angularjs(timeout=settings.MINI_TIMEOUT)
424433
try:
425-
if self.driver.current_url != pre_action_url:
426-
self.__ad_block_as_needed()
434+
self.wait_for_angularjs(timeout=settings.MINI_TIMEOUT)
427435
except Exception:
428-
self.wait_for_ready_state_complete()
436+
pass
437+
try:
429438
if self.driver.current_url != pre_action_url:
430439
self.__ad_block_as_needed()
440+
except Exception:
441+
try:
442+
self.wait_for_ready_state_complete()
443+
except Exception:
444+
pass
431445
if self.browser == "safari":
432446
time.sleep(0.02)
433447
if self.demo_mode:
@@ -1218,8 +1232,18 @@ def click_link_text(self, link_text, timeout=None):
12181232
)
12191233
):
12201234
self.__switch_to_newest_window_if_not_blank()
1235+
elif (
1236+
latest_window_count == pre_window_count - 1
1237+
and latest_window_count > 0
1238+
):
1239+
# If a click closes the active window,
1240+
# switch to the last one if it exists.
1241+
self.switch_to_window(-1)
12211242
if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
1222-
self.wait_for_ready_state_complete()
1243+
try:
1244+
self.wait_for_ready_state_complete()
1245+
except Exception:
1246+
pass
12231247
if self.demo_mode:
12241248
if self.driver.current_url != pre_action_url:
12251249
self.__demo_mode_pause_if_active()
@@ -1355,8 +1379,18 @@ def click_partial_link_text(self, partial_link_text, timeout=None):
13551379
)
13561380
):
13571381
self.__switch_to_newest_window_if_not_blank()
1382+
elif (
1383+
latest_window_count == pre_window_count - 1
1384+
and latest_window_count > 0
1385+
):
1386+
# If a click closes the active window,
1387+
# switch to the last one if it exists.
1388+
self.switch_to_window(-1)
13581389
if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
1359-
self.wait_for_ready_state_complete()
1390+
try:
1391+
self.wait_for_ready_state_complete()
1392+
except Exception:
1393+
pass
13601394
if self.demo_mode:
13611395
if self.driver.current_url != pre_action_url:
13621396
self.__demo_mode_pause_if_active()
@@ -5104,7 +5138,17 @@ def js_click(
51045138
)
51055139
):
51065140
self.__switch_to_newest_window_if_not_blank()
5107-
self.wait_for_ready_state_complete()
5141+
elif (
5142+
latest_window_count == pre_window_count - 1
5143+
and latest_window_count > 0
5144+
):
5145+
# If a click closes the active window,
5146+
# switch to the last one if it exists.
5147+
self.switch_to_window(-1)
5148+
try:
5149+
self.wait_for_ready_state_complete()
5150+
except Exception:
5151+
pass
51085152
self.__demo_mode_pause_if_active()
51095153

51105154
def js_click_all(self, selector, by="css selector"):

setup.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
reply = str(input_method(confirm_text)).lower().strip()
3737
if reply == "yes":
3838
print("\n*** Checking code health with flake8:\n")
39-
os.system("python -m pip install 'flake8==5.0.2'")
39+
os.system("python -m pip install 'flake8==5.0.4'")
4040
flake8_status = os.system("flake8 --exclude=recordings,temp")
4141
if flake8_status != 0:
4242
print("\nWARNING! Fix flake8 issues before publishing to PyPI!\n")
@@ -126,12 +126,12 @@
126126
install_requires=[
127127
'pip>=20.3.4;python_version<"3.6"',
128128
'pip>=21.3.1;python_version>="3.6" and python_version<"3.7"',
129-
'pip>=22.2.1;python_version>="3.7"',
129+
'pip>=22.2.2;python_version>="3.7"',
130130
'packaging>=20.9;python_version<"3.6"',
131131
'packaging>=21.3;python_version>="3.6"',
132132
'setuptools>=44.1.1;python_version<"3.6"',
133133
'setuptools>=59.6.0;python_version>="3.6" and python_version<"3.7"',
134-
'setuptools>=63.3.0;python_version>="3.7"',
134+
'setuptools>=63.4.1;python_version>="3.7"',
135135
'tomli>=1.2.3;python_version>="3.6" and python_version<"3.7"',
136136
'tomli>=2.0.1;python_version>="3.7"',
137137
"wheel>=0.37.1",
@@ -148,6 +148,9 @@
148148
'platformdirs>=2.0.2;python_version<"3.6"',
149149
'platformdirs>=2.4.0;python_version>="3.6" and python_version<"3.7"',
150150
'platformdirs>=2.5.2;python_version>="3.7"',
151+
'pyparsing>=2.4.7;python_version<"3.6"',
152+
'pyparsing>=3.0.7;python_version>="3.6" and python_version<"3.7"',
153+
'pyparsing>=3.0.9;python_version>="3.7"',
151154
"six==1.16.0",
152155
'ipdb==0.13.4;python_version<"3.6"',
153156
'ipdb==0.13.9;python_version>="3.6"',
@@ -253,13 +256,13 @@
253256
# Usage: flake8
254257
"flake": [
255258
'flake8==3.7.9;python_version<"3.6"',
256-
'flake8==5.0.2;python_version>="3.6"',
259+
'flake8==5.0.4;python_version>="3.6"',
257260
'mccabe==0.6.1;python_version<"3.6"',
258261
'mccabe==0.7.0;python_version>="3.6"',
259262
'pyflakes==2.1.1;python_version<"3.6"',
260263
'pyflakes==2.5.0;python_version>="3.6"',
261264
'pycodestyle==2.5.0;python_version<"3.6"',
262-
'pycodestyle==2.9.0;python_version>="3.6"',
265+
'pycodestyle==2.9.1;python_version>="3.6"',
263266
],
264267
# pip install -e .[pdfminer]
265268
"pdfminer": [

0 commit comments

Comments
 (0)