Skip to content

Commit 47b0352

Browse files
authored
Merge pull request #826 from seleniumbase/improve-safari-and-more
Improve downloads, Safari automation, reliability, and more
2 parents 518d44c + 0052664 commit 47b0352

File tree

14 files changed

+185
-105
lines changed

14 files changed

+185
-105
lines changed

docs/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ regex>=2020.11.13
22
tqdm>=4.57.0
33
livereload==2.6.3;python_version>="3.6"
44
joblib==1.0.1;python_version>="3.6"
5-
Markdown==3.3.3
5+
Markdown==3.3.4
66
Jinja2==2.11.3
77
readme-renderer==29.0
88
pymdown-extensions==8.1.1
99
lunr==0.5.8
1010
mkdocs==1.1.2
11-
mkdocs-material==7.0.0
11+
mkdocs-material==7.0.1
1212
mkdocs-simple-hooks==0.1.2
1313
mkdocs-material-extensions==1.0.1
1414
mkdocs-minify-plugin==0.4.0

examples/handle_alert_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
class MyTestClass(BaseCase):
55

66
def test_alerts(self):
7+
if self.browser == "safari":
8+
self.skip("This test doesn't run on Safari! (alert issues)")
79
self.open("about:blank")
8-
self.execute_script('window.alert("ALERT!!!")')
10+
self.execute_script('window.alert("ALERT!!!");')
911
self.sleep(1) # Not needed (Lets you see the alert pop up)
1012
self.accept_alert()
1113
self.sleep(1) # Not needed (Lets you see the alert go away)

examples/offline_examples/handle_alert_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
class OfflineTestClass(BaseCase):
77

88
def test_alerts(self):
9+
if self.browser == "safari":
10+
self.skip("This test doesn't run on Safari! (alert issues)")
911
self.open("data:,")
10-
self.execute_script('window.alert("ALERT!!!")')
12+
self.execute_script('window.alert("ALERT!!!");')
1113
self.sleep(1) # Not needed (Lets you see the alert pop up)
1214
self.accept_alert()
1315
self.sleep(1) # Not needed (Lets you see the alert go away)

examples/proxy_test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ def test_proxy(self):
99
ip_address = self.get_text("div.home-ip-details span.value")[1:-1]
1010
print("\n\nMy IP Address = %s\n" % ip_address)
1111
print("Displaying Host Info:")
12-
print(self.get_text('div.home-ip-details').split('asn: ')[0])
12+
text = self.get_text('div.home-ip-details').split('asn:')[0]
13+
rows = text.split('\n')
14+
data = []
15+
for row in rows:
16+
if row.strip() != "":
17+
data.append(row.strip())
18+
print("\n".join(data).replace('\n"', ' '))
1319
print("\nThe browser will close automatically in 7 seconds...")
1420
time.sleep(7)

examples/test_download_files.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@ class DownloadTests(BaseCase):
66

77
def test_download_files(self):
88
self.open("https://pypi.org/project/seleniumbase/#files")
9-
pkg_header = self.get_text("h1.package-header__name")
9+
pkg_header = self.get_text("h1.package-header__name").strip()
1010
pkg_name = pkg_header.replace(" ", "-")
1111
whl_file = pkg_name + "-py2.py3-none-any.whl"
1212
tar_gz_file = pkg_name + ".tar.gz"
1313

1414
# Click the links to download the files
15-
self.click('div#files a[href$="%s"]' % whl_file)
16-
self.click('div#files a[href$="%s"]' % tar_gz_file)
15+
# (If using Safari, IE, or Chromium Guest Mode, download directly.)
16+
whl_selector = 'div#files a[href$="%s"]' % whl_file
17+
tar_selector = 'div#files a[href$="%s"]' % tar_gz_file
18+
if self.browser == "safari" or self.browser == "ie" or (
19+
self.is_chromium() and self.guest_mode and not self.headless):
20+
whl_href = self.get_attribute(whl_selector, "href")
21+
tar_href = self.get_attribute(tar_selector, "href")
22+
self.download_file(whl_href)
23+
self.download_file(tar_href)
24+
else:
25+
self.click(whl_selector)
26+
self.click(tar_selector)
1727

1828
# Verify that the downloaded files appear in the [Downloads Folder]
1929
# (This only guarantees that the exact file name is in the folder.)

examples/translations/chinese_test_1.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
class 我的测试类(硒测试用例):
66

77
def test_例子1(self):
8-
self.开启网址("https://xkcd.in/comic?lg=cn&id=353")
9-
self.断言标题("Python - XKCD中文站")
10-
self.断言元素("#content div.comic-body")
11-
self.断言文本("上漫画")
12-
self.单击("div.nextLink")
13-
self.断言文本("母亲的功绩", "#content h1")
14-
self.单击链接文本("下一篇")
15-
self.断言文本("敲打", "#content h1")
16-
self.断言文本("有时,最有趣的事也会显得无聊")
17-
self.回去()
18-
self.单击链接文本("兰德尔·门罗")
19-
self.断言文本("兰德尔·门罗", "#firstHeading")
20-
self.输入文本("#searchInput", "程式设计")
8+
self.开启("https://zh.wikipedia.org/wiki/")
9+
self.断言标题("维基百科,自由的百科全书")
10+
self.断言元素('a[title="首页"]')
11+
self.断言文本("新闻动态", "span#新闻动态")
12+
self.输入文本("#searchInput", "舞龍")
2113
self.单击("#searchButton")
22-
self.断言文本("程序设计", "#firstHeading")
14+
self.断言文本("舞龍", "#firstHeading")
15+
self.断言元素('img[src*="Chinese_draak.jpg"]')
16+
self.输入文本("#searchInput", "火鍋")
17+
self.单击("#searchButton")
18+
self.断言文本("火鍋", "#firstHeading")
19+
self.断言元素('td:contains("火鍋的各種食材")')
20+
self.输入文本("#searchInput", "精武英雄")
21+
self.单击("#searchButton")
22+
self.断言元素('img[src*="Fist_of_legend.jpg"]')
23+
self.断言文本("李连杰", 'li a[title="李连杰"]')

examples/translations/english_test_1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def test_example_1(self):
88
self.open(url)
99
self.type("input.search-input", "xkcd book\n")
1010
self.assert_text("xkcd: volume 0", "h3")
11-
self.click("li.checkout-link")
11+
self.click("li.checkout-link a")
1212
self.assert_text("Shopping Cart", "#page-title")
1313
self.assert_element("div#umbrella")
1414
self.open("https://xkcd.com/353/")

help_docs/method_summary.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,13 @@ self.save_data_as(data, file_name, destination_folder=None)
300300

301301
self.get_downloads_folder()
302302

303-
self.get_path_of_downloaded_file(file)
303+
self.get_browser_downloads_folder()
304304

305-
self.is_downloaded_file_present(file)
305+
self.get_path_of_downloaded_file(file, browser=False)
306306

307-
self.assert_downloaded_file(file, timeout=None)
307+
self.is_downloaded_file_present(file, browser=False)
308+
309+
self.assert_downloaded_file(file, timeout=None, browser=False)
308310

309311
self.assert_true(expr, msg=None)
310312

@@ -322,6 +324,8 @@ self.assert_no_js_errors()
322324

323325
self.inspect_html()
324326

327+
self.is_chromium()
328+
325329
self.get_google_auth_password(totp_key=None)
326330

327331
self.convert_css_to_xpath(css)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ toml==0.10.2
7878
Pillow==6.2.2;python_version<"3.5"
7979
Pillow==7.2.0;python_version>="3.5" and python_version<"3.6"
8080
Pillow==8.1.0;python_version>="3.6"
81-
rich==9.11.1;python_version>="3.6" and python_version<"4.0"
81+
rich==9.12.0;python_version>="3.6" and python_version<"4.0"
8282
flake8==3.7.9;python_version<"3.5"
8383
flake8==3.8.4;python_version>="3.5"
8484
pyflakes==2.1.1;python_version<"3.5"

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__ = "1.55.7"
2+
__version__ = "1.56.0"

0 commit comments

Comments
 (0)