Skip to content

Commit c630307

Browse files
committed
Update example tests
1 parent efad563 commit c630307

File tree

6 files changed

+42
-21
lines changed

6 files changed

+42
-21
lines changed

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/")

0 commit comments

Comments
 (0)