Skip to content

Commit 6748aee

Browse files
committed
Add open_url_and_popup and close_popup_overlay
1 parent db8fa81 commit 6748aee

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/selenium/popup_test.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,48 @@
1414
class PopupTest(pbtest.PBSeleniumTest):
1515
"""Make sure the popup works correctly."""
1616

17+
def open_url_and_popup(self, url, close_overlay=True):
18+
self.load_url(self.bg_url)
19+
20+
js_src = """/**
21+
* open a page, wait, then open the popup for it
22+
*/
23+
(() => {
24+
let url = "%s";
25+
chrome.tabs.create({url}, tab => {
26+
setTimeout(() => utils.openPopupForTab(tab), 2000);
27+
});
28+
})();
29+
""" % url
30+
before_handles = len(self.driver.window_handles)
31+
self.js(js_src)
32+
while len(self.driver.window_handles) < before_handles + 2:
33+
time.sleep(0.1)
34+
for w in self.driver.window_handles:
35+
self.driver.switch_to.window(w)
36+
if 'popup.html' in self.driver.current_url:
37+
break
38+
if close_overlay:
39+
self.close_popup_overlay(ignore_missing_overlay=True)
40+
41+
def close_popup_overlay(self, ignore_missing_overlay=False):
42+
# Click 'X' element to close overlay.
43+
try:
44+
close_element = self.find_el_by_css('#fittslaw')
45+
except (NoSuchElementException, TimeoutException) as e:
46+
if ignore_missing_overlay:
47+
return
48+
self.fail("Unable to find element to close popup overlay")
49+
close_element.click()
50+
51+
# Element will fade out so wait for it to disappear.
52+
try:
53+
WebDriverWait(self.driver, 5).until(
54+
expected_conditions.invisibility_of_element_located(
55+
(By.ID, "fittslaw")))
56+
except TimeoutException:
57+
self.fail("Unable to close popup overlay")
58+
1759
def open_popup(self, close_overlay=True):
1860
"""Open popup and optionally close overlay."""
1961
self.load_url(self.popup_url, wait_on_site=1)

0 commit comments

Comments
 (0)