def wait_for_page(self, url=None, timeout=10): """wait_for_page navigates to the url in webdriver wait until the renderer is loaded in browser. use the `server_url` if url is not provided. """ self.driver.get(self.server_url if url is None else url) try: self.wait_for_element_by_css_selector(self.dash_entry_locator, timeout=timeout) except TimeoutException: logger.exception("dash server is not loaded within %s seconds", timeout) logger.debug(self.get_logs()) raise DashAppLoadingError( "the expected Dash react entry point cannot be loaded" " in browser\n HTML => {}\n Console Logs => {}\n".format( self.driver.find_element_by_tag_name("body").get_property( "innerHTML"), "\n".join((str(log) for log in self.get_logs())), )) if self._pause: try: import pdb as pdb_ # pylint: disable=import-outside-toplevel except ImportError: import ipdb as pdb_ # pylint: disable=import-outside-toplevel pdb_.set_trace()
def wait_for_page(self, url=None, timeout=10): """wait_for_page navigates to the url in webdriver wait until the renderer is loaded in browser. use the `server_url` if url is not provided. """ self.driver.get(self.server_url if url is None else url) try: self.wait_for_element_by_css_selector(self.dash_entry_locator, timeout=timeout) except TimeoutException as exc: logger.exception("dash server is not loaded within %s seconds", timeout) logs = "\n".join((str(log) for log in self.get_logs())) logger.debug(logs) html = self.find_element("body").get_property("innerHTML") raise DashAppLoadingError( "the expected Dash react entry point cannot be loaded" f" in browser\n HTML => {html}\n Console Logs => {logs}\n" ) from exc if self._pause: import pdb # pylint: disable=import-outside-toplevel pdb.set_trace() # pylint: disable=forgotten-debug-statement
def start(self, app, start_timeout=3, **kwargs): """Start the app server in threading flavor.""" def _handle_error(): self.stop() app.server.errorhandler(500)(_handle_error) def run(): app.scripts.config.serve_locally = True app.css.config.serve_locally = True options = kwargs.copy() if "port" not in kwargs: options["port"] = self.port = BaseDashRunner._next_port BaseDashRunner._next_port += 1 else: self.port = options["port"] try: app.run(threaded=True, **options) except SystemExit: logger.info("Server stopped") except Exception as error: logger.exception(error) raise error retries = 0 while not self.started and retries < 3: try: if self.thread and self.thread.is_alive(): self.stop() self.thread = KillerThread(target=run) self.thread.daemon = True self.thread.start() # wait until server is able to answer http request wait.until(lambda: self.running_and_accessible(self.url), timeout=start_timeout) self.started = self.thread.is_alive() except Exception as err: # pylint: disable=broad-except logger.exception(err) self.started = False retries += 1 BaseDashRunner._next_port += 1 self.started = self.thread.is_alive() if not self.started: raise DashAppLoadingError("threaded server failed to start")
def wait_for_page(self, url=None, timeout=10): self.driver.get(self.server_url if url is None else url) try: self.wait_for_element_by_css_selector(self.dash_entry_locator, timeout=timeout) except TimeoutException: logger.exception("dash server is not loaded within %s seconds", timeout) logger.debug(self.get_logs()) raise DashAppLoadingError( "the expected Dash react entry point cannot be loaded" " in browser\n HTML => {}\n Console Logs => {}\n".format( self.driver.find_element_by_tag_name("body").get_property( "innerHTML"), "\n".join((str(log) for log in self.get_logs())), ))
def running_and_accessible(self, url): if self.thread.is_alive(): return self.accessible(url) raise DashAppLoadingError("Thread is not alive.")