def test_settings(tmp_path, browser): # TODO fixture for driver? with get_webdriver(browser=browser) as driver: configure_extension(driver, port='12345', show_dots=False) driver.get('about:blank') open_extension_page(driver, page='options_page.html') hh = driver.find_element_by_id('host_id') assert hh.get_attribute('value') == 'http://localhost:12345'
def configure( driver, *, host: Optional[str] = LOCALHOST, port: Optional[str] = None, show_dots: bool = True, highlights: Optional[bool] = None, blacklist=None, notify_contexts: Optional[bool] = None, position: Optional[str] = None, verbose_errors: bool = True, ) -> None: def set_checkbox(cid: str, value: bool): cb = driver.find_element_by_id(cid) selected = cb.is_selected() if selected != value: cb.click() # TODO log properly print(f"Setting: port {port}, show_dots {show_dots}") open_extension_page(driver, page='options_page.html') sleep( 1 ) # err, wtf? otherwise not always interacts with the elements correctly assert not (host is None) ^ (port is None), (host, port) if host is not None: assert port is not None set_host(driver=driver, host=host, port=port) # dots = driver.find_element_by_id('dots_id') # if dots.is_selected() != show_dots: # dots.click() # assert dots.is_selected() == show_dots # TODO not sure, should be False for demos? set_checkbox('verbose_errors_id', verbose_errors) if highlights is not None: set_checkbox('highlight_id', highlights) if notify_contexts is not None: set_checkbox('contexts_popup_id', notify_contexts) if position is not None: set_position(driver, position) if blacklist is not None: bl = driver.find_element_by_id( 'blacklist_id') # .find_element_by_tag_name('textarea') bl.click() # ugh, that's hacky. presumably due to using Codemirror? bla = driver.switch_to_active_element() bla.send_keys('\n'.join(blacklist)) save_settings(driver)
def test_backend_status(tmp_path, browser): with get_webdriver(browser=browser) as driver: open_extension_page(driver, page='options_page.html') sleep(1) # ugh. for some reason pause here seems necessary.. set_host(driver=driver, host='https://nosuchhost.com', port='1234') driver.find_element_by_id('backend_status_id').click() sleep(1 + 0.5) # needs enough time for timeout to trigger... alert = driver.switch_to.alert assert 'ERROR' in alert.text sleep(0.5) # don't remember if needed? driver.switch_to.alert.accept()
def test_backend_status(tmp_path, browser): browser.skip_ci_x() with get_webdriver(browser=browser) as driver: open_extension_page(driver, page='options_page.html') sleep(1) # ugh. for some reason pause here seems necessary.. set_host(driver=driver, host='https://nosuchhost.com', port='1234') driver.find_element_by_id('backend_status_id').click() sleep(1 + 0.5) # needs enough time for timeout to trigger... alert = driver.switch_to.alert assert 'ERROR' in alert.text # TODO ugh, not sure why it just stucks on headless... # perhaps use policy instead? https://stackoverflow.com/a/43946973/706389 if not browser.headless: driver.switch_to.alert.accept() sleep(0.5) # ugh. extra alert... driver.switch_to.alert.accept()
def test_sidebar_bottom(browser): with get_webdriver(browser=browser) as driver: open_extension_page(driver, page='options_page.html') sleep(1) # ugh. for some reason pause here seems necessary.. # for some reason area.clear() caused # selenium.common.exceptions.ElementNotInteractableException: Message: Element <textarea> could not be scrolled into view settings = """ #promnesia-sidebar { --bottom: 1; --size: 20%; }""" set_position(driver, settings) save_settings(driver) driver.get(PYTHON_DOC_URL) trigger_command(driver, Command.ACTIVATE) confirm("You should see sidebar below")
def open_page(self, page: str) -> None: open_extension_page(self.driver, page)