|
14 | 14 | class PopupTest(pbtest.PBSeleniumTest):
|
15 | 15 | """Make sure the popup works correctly."""
|
16 | 16 |
|
| 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 | + |
17 | 59 | def open_popup(self, close_overlay=True):
|
18 | 60 | """Open popup and optionally close overlay."""
|
19 | 61 | self.load_url(self.popup_url, wait_on_site=1)
|
|
0 commit comments