Skip to content

Commit dd573ab

Browse files
committed
Add the "test_shadow_dom" example test
1 parent ea96f3e commit dd573ab

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

examples/test_shadow_dom.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
""" Shadow DOM test.
2+
First download files from PyPI.
3+
Then search for them on a multi-layered Shadow DOM page.
4+
This uses the "::shadow" selector for piercing shadow-root elements.
5+
Here's the URL that contains Shadow DOM: chrome://downloads/ """
6+
7+
8+
from seleniumbase import BaseCase
9+
10+
11+
class ShadowDomTests(BaseCase):
12+
13+
def download_tar_file_from_pypi(self, package):
14+
self.open("https://pypi.org/project/%s/#files" % package)
15+
pkg_header = self.get_text("h1.package-header__name").strip()
16+
pkg_name = pkg_header.replace(" ", "-")
17+
tar_file = pkg_name + ".tar.gz"
18+
tar_selector = 'div#files a[href$="%s"]' % tar_file
19+
self.click(tar_selector)
20+
return tar_file
21+
22+
def test_shadow_dom(self):
23+
if self.browser != "chrome":
24+
print("\n This test is for Google Chrome only!")
25+
self.skip('This test is for Google Chrome only!')
26+
if self.headless:
27+
print("\n This test does not run in headless mode!")
28+
self.skip('This test does not run in headless mode!')
29+
30+
file_name_1 = self.download_tar_file_from_pypi("sbase")
31+
file_name_2 = self.download_tar_file_from_pypi("tensorpy")
32+
33+
self.open("chrome://downloads/")
34+
search_icon = (
35+
"downloads-manager::shadow downloads-toolbar::shadow"
36+
" cr-toolbar::shadow cr-toolbar-search-field::shadow"
37+
" cr-icon-button")
38+
search_input = (
39+
"downloads-manager::shadow downloads-toolbar::shadow"
40+
" cr-toolbar::shadow cr-toolbar-search-field::shadow"
41+
" #searchInput")
42+
clear_search_icon = (
43+
"downloads-manager::shadow downloads-toolbar::shadow"
44+
" cr-toolbar::shadow cr-toolbar-search-field::shadow"
45+
" #clearSearch")
46+
file_link = (
47+
"downloads-manager::shadow #downloadsList"
48+
" downloads-item::shadow #file-link")
49+
remove_button = (
50+
"downloads-manager::shadow #downloadsList"
51+
" downloads-item::shadow #remove")
52+
no_downloads_area = "downloads-manager::shadow #no-downloads"
53+
54+
self.assert_element(search_icon)
55+
self.type(search_input, "sbase")
56+
self.assert_text(file_name_1, file_link)
57+
print("\n Download 1: %s" % self.get_text(file_link))
58+
self.type(search_input, "tensorpy")
59+
self.assert_text(file_name_2, file_link)
60+
print(" Download 2: %s" % self.get_text(file_link))
61+
self.click(clear_search_icon)
62+
self.click(remove_button)
63+
self.click(remove_button)
64+
self.assert_text("Files you download appear here", no_downloads_area)

0 commit comments

Comments
 (0)