def _execute(self, command, params=None): try: return RemoteWebDriver.execute(self, command, params) except ErrorInResponseException, e: # Legacy behavior: calling close() multiple times should not raise # an error if command != Command.CLOSE and command != Command.QUIT: raise e
def is_driver_responsive(driver: WebDriver) -> bool: responsive = False try: response = driver.execute(Command.STATUS) logging.debug(f"WebDriver Status: {response}") responsive = True except (socket.error, CannotSendRequest): logging.error(f"Remote browser driver became unresponsive!") return responsive
def dump_heap_profile(self, reason): """Dumps a heap profile. It works only on Linux and ChromeOS. We need an environment variable "HEAPPROFILE" set to a directory and a filename prefix, for example, "/tmp/prof". In a case of this example, heap profiles will be dumped into "/tmp/prof.(pid).0002.heap", "/tmp/prof.(pid).0003.heap", and so on. Nothing happens when this function is called without the env. Args: reason: A string which describes the reason for dumping a heap profile. The reason will be included in the logged message. Examples: 'To check memory leaking' 'For WebDriver tests' """ if self.IsLinux(): # IsLinux() also implies IsChromeOS(). params = {'reason': reason} RemoteWebDriver.execute(self, WebDriver._CHROME_DUMP_HEAP_PROFILE, params) else: raise WebDriverException('Heap-profiling is not supported in this OS.')
def install_extension(self, path): """Install the extension at the given path. Args: path: Path to packed or unpacked extension to install. Returns: The installed extension. """ params = {"path": path} id = RemoteWebDriver.execute(self, WebDriver._CHROME_INSTALL_EXTENSION, params)["value"] return Extension(self, id)
def install_extension(self, path): """Install the extension at the given path. Args: path: Path to packed or unpacked extension to install. Returns: The installed extension. """ params = {'path': path} id = RemoteWebDriver.execute(self, WebDriver._CHROME_INSTALL_EXTENSION, params)['value'] return Extension(self, id)
def save_screenshot(self, filename): """ Gets the screenshot of the current window. Returns False if there is any IOError, else returns True. Use full paths in your filename. """ png = RemoteWebDriver.execute(self, Command.SCREENSHOT)['value'] try: f = open(filename, 'wb') f.write(base64.decodestring(png)) f.close() except IOError: return False finally: del png return True
def get_installed_extensions(self): """Returns a list of installed extensions.""" ids = RemoteWebDriver.execute( self, WebDriver._CHROME_GET_EXTENSIONS)['value'] return map(lambda id: Extension(self, id), ids)