Best Python code snippet using fMBT_python
xwalkdriver.py
Source:xwalkdriver.py  
1# Copyright 2013 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4import command_executor5from command_executor import Command6from webelement import WebElement7class XwalkDriverException(Exception):8  pass9class NoSuchElement(XwalkDriverException):10  pass11class NoSuchFrame(XwalkDriverException):12  pass13class UnknownCommand(XwalkDriverException):14  pass15class StaleElementReference(XwalkDriverException):16  pass17class UnknownError(XwalkDriverException):18  pass19class JavaScriptError(XwalkDriverException):20  pass21class XPathLookupError(XwalkDriverException):22  pass23class NoSuchWindow(XwalkDriverException):24  pass25class InvalidCookieDomain(XwalkDriverException):26  pass27class ScriptTimeout(XwalkDriverException):28  pass29class InvalidSelector(XwalkDriverException):30  pass31class SessionNotCreatedException(XwalkDriverException):32  pass33class NoSuchSession(XwalkDriverException):34  pass35def _ExceptionForResponse(response):36  exception_class_map = {37    6: NoSuchSession,38    7: NoSuchElement,39    8: NoSuchFrame,40    9: UnknownCommand,41    10: StaleElementReference,42    13: UnknownError,43    17: JavaScriptError,44    19: XPathLookupError,45    23: NoSuchWindow,46    24: InvalidCookieDomain,47    28: ScriptTimeout,48    32: InvalidSelector,49    33: SessionNotCreatedException50  }51  status = response['status']52  msg = response['value']['message']53  return exception_class_map.get(status, XwalkDriverException)(msg)54class XwalkDriver(object):55  """Starts and controls a single Xwalk instance on this machine."""56  def __init__(self, server_url, xwalk_binary=None, android_package=None,57               android_activity=None, android_process=None,58               android_use_running_app=None, xwalk_switches=None,59               xwalk_extensions=None, xwalk_log_path=None,60               debugger_address=None, browser_log_level=None,61               performance_log_level=None, mobile_emulation=None,62               experimental_options=None, download_dir=None,63	       debug_port=None):64    self._executor = command_executor.CommandExecutor(server_url)65    options = {}66    if experimental_options:67      assert isinstance(experimental_options, dict)68      options = experimental_options.copy()69    if android_package:70      options['androidPackage'] = android_package71      if android_activity:72        options['androidActivity'] = android_activity73      if android_process:74        options['androidProcess'] = android_process75      if android_use_running_app:76        options['androidUseRunningApp'] = android_use_running_app77    elif xwalk_binary:78      options['binary'] = xwalk_binary79    if xwalk_switches:80      assert type(xwalk_switches) is list81      options['args'] = xwalk_switches82    if mobile_emulation:83      assert type(mobile_emulation) is dict84      options['mobileEmulation'] = mobile_emulation85    if xwalk_extensions:86      assert type(xwalk_extensions) is list87      options['extensions'] = xwalk_extensions88    if xwalk_log_path:89      assert type(xwalk_log_path) is str90      options['logPath'] = xwalk_log_path91    if debugger_address:92      assert type(debugger_address) is str93      options['debuggerAddress'] = debugger_address94    if debug_port:95      options['debugPort'] = debug_port96    logging_prefs = {}97    log_levels = ['ALL', 'DEBUG', 'INFO', 'WARNING', 'SEVERE', 'OFF']98    if browser_log_level:99      assert browser_log_level in log_levels100      logging_prefs['browser'] = browser_log_level101    if performance_log_level:102      assert performance_log_level in log_levels103      logging_prefs['performance'] = performance_log_level104    download_prefs = {}105    if download_dir:106      if 'prefs' not in options:107        options['prefs'] = {}108      if 'download' not in options['prefs']:109        options['prefs']['download'] = {}110      options['prefs']['download']['default_directory'] = download_dir111    params = {112      'desiredCapabilities': {113        'xwalkOptions': options,114        'loggingPrefs': logging_prefs115      }116    }117    response = self._ExecuteCommand(Command.NEW_SESSION, params)118    self._session_id = response['sessionId']119    self.capabilities = self._UnwrapValue(response['value'])120  def _WrapValue(self, value):121    """Wrap value from client side for xwalkdriver side."""122    if isinstance(value, dict):123      converted = {}124      for key, val in value.items():125        converted[key] = self._WrapValue(val)126      return converted127    elif isinstance(value, WebElement):128      return {'ELEMENT': value._id}129    elif isinstance(value, list):130      return list(self._WrapValue(item) for item in value)131    else:132      return value133  def _UnwrapValue(self, value):134    """Unwrap value from xwalkdriver side for client side."""135    if isinstance(value, dict):136      if (len(value) == 1 and 'ELEMENT' in value137          and isinstance(value['ELEMENT'], basestring)):138        return WebElement(self, value['ELEMENT'])139      else:140        unwraped = {}141        for key, val in value.items():142          unwraped[key] = self._UnwrapValue(val)143        return unwraped144    elif isinstance(value, list):145      return list(self._UnwrapValue(item) for item in value)146    else:147      return value148  def _ExecuteCommand(self, command, params={}):149    params = self._WrapValue(params)150    response = self._executor.Execute(command, params)151    if response['status'] != 0:152      raise _ExceptionForResponse(response)153    return response154  def ExecuteCommand(self, command, params={}):155    params['sessionId'] = self._session_id156    response = self._ExecuteCommand(command, params)157    return self._UnwrapValue(response['value'])158  def GetWindowHandles(self):159    return self.ExecuteCommand(Command.GET_WINDOW_HANDLES)160  def SwitchToWindow(self, handle_or_name):161    self.ExecuteCommand(Command.SWITCH_TO_WINDOW, {'name': handle_or_name})162  def GetCurrentWindowHandle(self):163    return self.ExecuteCommand(Command.GET_CURRENT_WINDOW_HANDLE)164  def CloseWindow(self):165    self.ExecuteCommand(Command.CLOSE)166  def Load(self, url):167    self.ExecuteCommand(Command.GET, {'url': url})168  def LaunchApp(self, app_id):169    self.ExecuteCommand(Command.LAUNCH_APP, {'id': app_id})170  def ExecuteScript(self, script, *args):171    converted_args = list(args)172    return self.ExecuteCommand(173        Command.EXECUTE_SCRIPT, {'script': script, 'args': converted_args})174  def ExecuteAsyncScript(self, script, *args):175    converted_args = list(args)176    return self.ExecuteCommand(177        Command.EXECUTE_ASYNC_SCRIPT,178        {'script': script, 'args': converted_args})179  def SwitchToFrame(self, id_or_name):180    self.ExecuteCommand(Command.SWITCH_TO_FRAME, {'id': id_or_name})181  def SwitchToFrameByIndex(self, index):182    self.SwitchToFrame(index)183  def SwitchToMainFrame(self):184    self.SwitchToFrame(None)185  def SwitchToParentFrame(self):186    self.ExecuteCommand(Command.SWITCH_TO_PARENT_FRAME)187  def GetSessions(self):188    return self.ExecuteCommand(Command.GET_SESSIONS)189  def GetTitle(self):190    return self.ExecuteCommand(Command.GET_TITLE)191  def GetPageSource(self):192    return self.ExecuteCommand(Command.GET_PAGE_SOURCE)193  def FindElement(self, strategy, target):194    return self.ExecuteCommand(195        Command.FIND_ELEMENT, {'using': strategy, 'value': target})196  def FindElements(self, strategy, target):197    return self.ExecuteCommand(198        Command.FIND_ELEMENTS, {'using': strategy, 'value': target})199  def SetTimeout(self, type, timeout):200    return self.ExecuteCommand(201        Command.SET_TIMEOUT, {'type' : type, 'ms': timeout})202  def GetCurrentUrl(self):203    return self.ExecuteCommand(Command.GET_CURRENT_URL)204  def GoBack(self):205    return self.ExecuteCommand(Command.GO_BACK)206  def GoForward(self):207    return self.ExecuteCommand(Command.GO_FORWARD)208  def Refresh(self):209    return self.ExecuteCommand(Command.REFRESH)210  def MouseMoveTo(self, element=None, x_offset=None, y_offset=None):211    params = {}212    if element is not None:213      params['element'] = element._id214    if x_offset is not None:215      params['xoffset'] = x_offset216    if y_offset is not None:217      params['yoffset'] = y_offset218    self.ExecuteCommand(Command.MOUSE_MOVE_TO, params)219  def MouseClick(self, button=0):220    self.ExecuteCommand(Command.MOUSE_CLICK, {'button': button})221  def MouseButtonDown(self, button=0):222    self.ExecuteCommand(Command.MOUSE_BUTTON_DOWN, {'button': button})223  def MouseButtonUp(self, button=0):224    self.ExecuteCommand(Command.MOUSE_BUTTON_UP, {'button': button})225  def MouseDoubleClick(self, button=0):226    self.ExecuteCommand(Command.MOUSE_DOUBLE_CLICK, {'button': button})227  def TouchDown(self, x, y):228    self.ExecuteCommand(Command.TOUCH_DOWN, {'x': x, 'y': y})229  def TouchUp(self, x, y):230    self.ExecuteCommand(Command.TOUCH_UP, {'x': x, 'y': y})231  def TouchMove(self, x, y):232    self.ExecuteCommand(Command.TOUCH_MOVE, {'x': x, 'y': y})233  def TouchScroll(self, element, xoffset, yoffset):234    params = {'element': element._id, 'xoffset': xoffset, 'yoffset': yoffset}235    self.ExecuteCommand(Command.TOUCH_SCROLL, params)236  def TouchFlick(self, element, xoffset, yoffset, speed):237    params = {238        'element': element._id,239        'xoffset': xoffset,240        'yoffset': yoffset,241        'speed': speed242    }243    self.ExecuteCommand(Command.TOUCH_FLICK, params)244  def TouchPinch(self, x, y, scale):245    params = {'x': x, 'y': y, 'scale': scale}246    self.ExecuteCommand(Command.TOUCH_PINCH, params)247  def GetCookies(self):248    return self.ExecuteCommand(Command.GET_COOKIES)249  def GetCookie(self, name):250    return self.ExecuteCommand(Command.GET_COOKIE, {'name': name})251  def AddCookie(self, cookie):252    self.ExecuteCommand(Command.ADD_COOKIE, {'cookie': cookie})253  def DeleteCookie(self, name):254    self.ExecuteCommand(Command.DELETE_COOKIE, {'name': name})255  def DeleteAllCookies(self):256    self.ExecuteCommand(Command.DELETE_ALL_COOKIES)257  def IsAlertOpen(self):258    return self.ExecuteCommand(Command.GET_ALERT)259  def GetAlertMessage(self):260    return self.ExecuteCommand(Command.GET_ALERT_TEXT)261  def HandleAlert(self, accept, prompt_text=''):262    if prompt_text:263      self.ExecuteCommand(Command.SET_ALERT_VALUE, {'text': prompt_text})264    if accept:265      cmd = Command.ACCEPT_ALERT266    else:267      cmd = Command.DISMISS_ALERT268    self.ExecuteCommand(cmd)269  def IsLoading(self):270    return self.ExecuteCommand(Command.IS_LOADING)271  def GetWindowPosition(self):272    position = self.ExecuteCommand(Command.GET_WINDOW_POSITION,273                                   {'windowHandle': 'current'})274    return [position['x'], position['y']]275  def SetWindowPosition(self, x, y):276    self.ExecuteCommand(Command.SET_WINDOW_POSITION,277                        {'windowHandle': 'current', 'x': x, 'y': y})278  def GetWindowSize(self):279    size = self.ExecuteCommand(Command.GET_WINDOW_SIZE,280                               {'windowHandle': 'current'})281    return [size['width'], size['height']]282  def SetWindowSize(self, width, height):283    self.ExecuteCommand(284        Command.SET_WINDOW_SIZE,285        {'windowHandle': 'current', 'width': width, 'height': height})286  def MaximizeWindow(self):287    self.ExecuteCommand(Command.MAXIMIZE_WINDOW, {'windowHandle': 'current'})288  def Quit(self):289    """Quits the browser and ends the session."""290    self.ExecuteCommand(Command.QUIT)291  def GetLog(self, type):292    return self.ExecuteCommand(Command.GET_LOG, {'type': type})293  def GetAvailableLogTypes(self):294    return self.ExecuteCommand(Command.GET_AVAILABLE_LOG_TYPES)295  def IsAutoReporting(self):296    return self.ExecuteCommand(Command.IS_AUTO_REPORTING)297  def SetAutoReporting(self, enabled):298    self.ExecuteCommand(Command.SET_AUTO_REPORTING, {'enabled': enabled})299  def SetNetworkConditions(self, latency, download_throughput,300                           upload_throughput, offline=False):301    # Until http://crbug.com/456324 is resolved, we'll always set 'offline' to302    # False, as going "offline" will sever Xwalkdriver's connection to Xwalk.303    params = {304        'network_conditions': {305            'offline': offline,306            'latency': latency,307            'download_throughput': download_throughput,308            'upload_throughput': upload_throughput309        }310    }311    self.ExecuteCommand(Command.SET_NETWORK_CONDITIONS, params)312  def SetNetworkConditionsName(self, network_name):313    self.ExecuteCommand(314        Command.SET_NETWORK_CONDITIONS, {'network_name': network_name})315  def GetNetworkConditions(self):316    conditions = self.ExecuteCommand(Command.GET_NETWORK_CONDITIONS)317    return {318        'latency': conditions['latency'],319        'download_throughput': conditions['download_throughput'],320        'upload_throughput': conditions['upload_throughput'],321        'offline': conditions['offline']322    }323  def DeleteNetworkConditions(self):...chromedriver.py
Source:chromedriver.py  
1# Copyright 2013 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4import command_executor5from command_executor import Command6from webelement import WebElement7class ChromeDriverException(Exception):8  pass9class NoSuchElement(ChromeDriverException):10  pass11class NoSuchFrame(ChromeDriverException):12  pass13class UnknownCommand(ChromeDriverException):14  pass15class StaleElementReference(ChromeDriverException):16  pass17class UnknownError(ChromeDriverException):18  pass19class JavaScriptError(ChromeDriverException):20  pass21class XPathLookupError(ChromeDriverException):22  pass23class NoSuchWindow(ChromeDriverException):24  pass25class InvalidCookieDomain(ChromeDriverException):26  pass27class ScriptTimeout(ChromeDriverException):28  pass29class InvalidSelector(ChromeDriverException):30  pass31class SessionNotCreatedException(ChromeDriverException):32  pass33class NoSuchSession(ChromeDriverException):34  pass35class UnexpectedAlertOpen(ChromeDriverException):36  pass37def _ExceptionForResponse(response):38  exception_class_map = {39    6: NoSuchSession,40    7: NoSuchElement,41    8: NoSuchFrame,42    9: UnknownCommand,43    10: StaleElementReference,44    13: UnknownError,45    17: JavaScriptError,46    19: XPathLookupError,47    23: NoSuchWindow,48    24: InvalidCookieDomain,49    26: UnexpectedAlertOpen,50    28: ScriptTimeout,51    32: InvalidSelector,52    33: SessionNotCreatedException53  }54  status = response['status']55  msg = response['value']['message']56  return exception_class_map.get(status, ChromeDriverException)(msg)57class ChromeDriver(object):58  """Starts and controls a single Chrome instance on this machine."""59  def __init__(self, server_url, chrome_binary=None, android_package=None,60               android_activity=None, android_process=None,61               android_use_running_app=None, chrome_switches=None,62               chrome_extensions=None, chrome_log_path=None,63               debugger_address=None, browser_log_level=None,64               performance_log_level=None, mobile_emulation=None,65               experimental_options=None, download_dir=None):66    self._executor = command_executor.CommandExecutor(server_url)67    options = {}68    if experimental_options:69      assert isinstance(experimental_options, dict)70      options = experimental_options.copy()71    if android_package:72      options['androidPackage'] = android_package73      if android_activity:74        options['androidActivity'] = android_activity75      if android_process:76        options['androidProcess'] = android_process77      if android_use_running_app:78        options['androidUseRunningApp'] = android_use_running_app79    elif chrome_binary:80      options['binary'] = chrome_binary81    if chrome_switches:82      assert type(chrome_switches) is list83      options['args'] = chrome_switches84    if mobile_emulation:85      assert type(mobile_emulation) is dict86      options['mobileEmulation'] = mobile_emulation87    if chrome_extensions:88      assert type(chrome_extensions) is list89      options['extensions'] = chrome_extensions90    if chrome_log_path:91      assert type(chrome_log_path) is str92      options['logPath'] = chrome_log_path93    if debugger_address:94      assert type(debugger_address) is str95      options['debuggerAddress'] = debugger_address96    logging_prefs = {}97    log_levels = ['ALL', 'DEBUG', 'INFO', 'WARNING', 'SEVERE', 'OFF']98    if browser_log_level:99      assert browser_log_level in log_levels100      logging_prefs['browser'] = browser_log_level101    if performance_log_level:102      assert performance_log_level in log_levels103      logging_prefs['performance'] = performance_log_level104    download_prefs = {}105    if download_dir:106      if 'prefs' not in options:107        options['prefs'] = {}108      if 'download' not in options['prefs']:109        options['prefs']['download'] = {}110      options['prefs']['download']['default_directory'] = download_dir111    params = {112      'desiredCapabilities': {113        'chromeOptions': options,114        'loggingPrefs': logging_prefs115      }116    }117    response = self._ExecuteCommand(Command.NEW_SESSION, params)118    self._session_id = response['sessionId']119    self.capabilities = self._UnwrapValue(response['value'])120  def _WrapValue(self, value):121    """Wrap value from client side for chromedriver side."""122    if isinstance(value, dict):123      converted = {}124      for key, val in value.items():125        converted[key] = self._WrapValue(val)126      return converted127    elif isinstance(value, WebElement):128      return {'ELEMENT': value._id}129    elif isinstance(value, list):130      return list(self._WrapValue(item) for item in value)131    else:132      return value133  def _UnwrapValue(self, value):134    """Unwrap value from chromedriver side for client side."""135    if isinstance(value, dict):136      if (len(value) == 1 and 'ELEMENT' in value137          and isinstance(value['ELEMENT'], basestring)):138        return WebElement(self, value['ELEMENT'])139      else:140        unwraped = {}141        for key, val in value.items():142          unwraped[key] = self._UnwrapValue(val)143        return unwraped144    elif isinstance(value, list):145      return list(self._UnwrapValue(item) for item in value)146    else:147      return value148  def _ExecuteCommand(self, command, params={}):149    params = self._WrapValue(params)150    response = self._executor.Execute(command, params)151    if response['status'] != 0:152      raise _ExceptionForResponse(response)153    return response154  def ExecuteCommand(self, command, params={}):155    params['sessionId'] = self._session_id156    response = self._ExecuteCommand(command, params)157    return self._UnwrapValue(response['value'])158  def GetWindowHandles(self):159    return self.ExecuteCommand(Command.GET_WINDOW_HANDLES)160  def SwitchToWindow(self, handle_or_name):161    self.ExecuteCommand(Command.SWITCH_TO_WINDOW, {'name': handle_or_name})162  def GetCurrentWindowHandle(self):163    return self.ExecuteCommand(Command.GET_CURRENT_WINDOW_HANDLE)164  def CloseWindow(self):165    self.ExecuteCommand(Command.CLOSE)166  def Load(self, url):167    self.ExecuteCommand(Command.GET, {'url': url})168  def LaunchApp(self, app_id):169    self.ExecuteCommand(Command.LAUNCH_APP, {'id': app_id})170  def ExecuteScript(self, script, *args):171    converted_args = list(args)172    return self.ExecuteCommand(173        Command.EXECUTE_SCRIPT, {'script': script, 'args': converted_args})174  def ExecuteAsyncScript(self, script, *args):175    converted_args = list(args)176    return self.ExecuteCommand(177        Command.EXECUTE_ASYNC_SCRIPT,178        {'script': script, 'args': converted_args})179  def SwitchToFrame(self, id_or_name):180    self.ExecuteCommand(Command.SWITCH_TO_FRAME, {'id': id_or_name})181  def SwitchToFrameByIndex(self, index):182    self.SwitchToFrame(index)183  def SwitchToMainFrame(self):184    self.SwitchToFrame(None)185  def SwitchToParentFrame(self):186    self.ExecuteCommand(Command.SWITCH_TO_PARENT_FRAME)187  def GetSessions(self):188    return self.ExecuteCommand(Command.GET_SESSIONS)189  def GetTitle(self):190    return self.ExecuteCommand(Command.GET_TITLE)191  def GetPageSource(self):192    return self.ExecuteCommand(Command.GET_PAGE_SOURCE)193  def FindElement(self, strategy, target):194    return self.ExecuteCommand(195        Command.FIND_ELEMENT, {'using': strategy, 'value': target})196  def FindElements(self, strategy, target):197    return self.ExecuteCommand(198        Command.FIND_ELEMENTS, {'using': strategy, 'value': target})199  def SetTimeout(self, type, timeout):200    return self.ExecuteCommand(201        Command.SET_TIMEOUT, {'type' : type, 'ms': timeout})202  def GetCurrentUrl(self):203    return self.ExecuteCommand(Command.GET_CURRENT_URL)204  def GoBack(self):205    return self.ExecuteCommand(Command.GO_BACK)206  def GoForward(self):207    return self.ExecuteCommand(Command.GO_FORWARD)208  def Refresh(self):209    return self.ExecuteCommand(Command.REFRESH)210  def MouseMoveTo(self, element=None, x_offset=None, y_offset=None):211    params = {}212    if element is not None:213      params['element'] = element._id214    if x_offset is not None:215      params['xoffset'] = x_offset216    if y_offset is not None:217      params['yoffset'] = y_offset218    self.ExecuteCommand(Command.MOUSE_MOVE_TO, params)219  def MouseClick(self, button=0):220    self.ExecuteCommand(Command.MOUSE_CLICK, {'button': button})221  def MouseButtonDown(self, button=0):222    self.ExecuteCommand(Command.MOUSE_BUTTON_DOWN, {'button': button})223  def MouseButtonUp(self, button=0):224    self.ExecuteCommand(Command.MOUSE_BUTTON_UP, {'button': button})225  def MouseDoubleClick(self, button=0):226    self.ExecuteCommand(Command.MOUSE_DOUBLE_CLICK, {'button': button})227  def TouchDown(self, x, y):228    self.ExecuteCommand(Command.TOUCH_DOWN, {'x': x, 'y': y})229  def TouchUp(self, x, y):230    self.ExecuteCommand(Command.TOUCH_UP, {'x': x, 'y': y})231  def TouchMove(self, x, y):232    self.ExecuteCommand(Command.TOUCH_MOVE, {'x': x, 'y': y})233  def TouchScroll(self, element, xoffset, yoffset):234    params = {'element': element._id, 'xoffset': xoffset, 'yoffset': yoffset}235    self.ExecuteCommand(Command.TOUCH_SCROLL, params)236  def TouchFlick(self, element, xoffset, yoffset, speed):237    params = {238        'element': element._id,239        'xoffset': xoffset,240        'yoffset': yoffset,241        'speed': speed242    }243    self.ExecuteCommand(Command.TOUCH_FLICK, params)244  def TouchPinch(self, x, y, scale):245    params = {'x': x, 'y': y, 'scale': scale}246    self.ExecuteCommand(Command.TOUCH_PINCH, params)247  def GetCookies(self):248    return self.ExecuteCommand(Command.GET_COOKIES)249  def AddCookie(self, cookie):250    self.ExecuteCommand(Command.ADD_COOKIE, {'cookie': cookie})251  def DeleteCookie(self, name):252    self.ExecuteCommand(Command.DELETE_COOKIE, {'name': name})253  def DeleteAllCookies(self):254    self.ExecuteCommand(Command.DELETE_ALL_COOKIES)255  def IsAlertOpen(self):256    return self.ExecuteCommand(Command.GET_ALERT)257  def GetAlertMessage(self):258    return self.ExecuteCommand(Command.GET_ALERT_TEXT)259  def HandleAlert(self, accept, prompt_text=''):260    if prompt_text:261      self.ExecuteCommand(Command.SET_ALERT_VALUE, {'text': prompt_text})262    if accept:263      cmd = Command.ACCEPT_ALERT264    else:265      cmd = Command.DISMISS_ALERT266    self.ExecuteCommand(cmd)267  def IsLoading(self):268    return self.ExecuteCommand(Command.IS_LOADING)269  def GetWindowPosition(self):270    position = self.ExecuteCommand(Command.GET_WINDOW_POSITION,271                                   {'windowHandle': 'current'})272    return [position['x'], position['y']]273  def SetWindowPosition(self, x, y):274    self.ExecuteCommand(Command.SET_WINDOW_POSITION,275                        {'windowHandle': 'current', 'x': x, 'y': y})276  def GetWindowSize(self):277    size = self.ExecuteCommand(Command.GET_WINDOW_SIZE,278                               {'windowHandle': 'current'})279    return [size['width'], size['height']]280  def SetWindowSize(self, width, height):281    self.ExecuteCommand(282        Command.SET_WINDOW_SIZE,283        {'windowHandle': 'current', 'width': width, 'height': height})284  def MaximizeWindow(self):285    self.ExecuteCommand(Command.MAXIMIZE_WINDOW, {'windowHandle': 'current'})286  def Quit(self):287    """Quits the browser and ends the session."""288    self.ExecuteCommand(Command.QUIT)289  def GetLog(self, type):290    return self.ExecuteCommand(Command.GET_LOG, {'type': type})291  def GetAvailableLogTypes(self):292    return self.ExecuteCommand(Command.GET_AVAILABLE_LOG_TYPES)293  def IsAutoReporting(self):294    return self.ExecuteCommand(Command.IS_AUTO_REPORTING)295  def SetAutoReporting(self, enabled):296    self.ExecuteCommand(Command.SET_AUTO_REPORTING, {'enabled': enabled})297  def SetNetworkConditions(self, latency, download_throughput,298                           upload_throughput, offline=False):299    # Until http://crbug.com/456324 is resolved, we'll always set 'offline' to300    # False, as going "offline" will sever Chromedriver's connection to Chrome.301    params = {302        'network_conditions': {303            'offline': offline,304            'latency': latency,305            'download_throughput': download_throughput,306            'upload_throughput': upload_throughput307        }308    }309    self.ExecuteCommand(Command.SET_NETWORK_CONDITIONS, params)310  def SetNetworkConditionsName(self, network_name):311    self.ExecuteCommand(312        Command.SET_NETWORK_CONDITIONS, {'network_name': network_name})313  def GetNetworkConditions(self):314    conditions = self.ExecuteCommand(Command.GET_NETWORK_CONDITIONS)315    return {316        'latency': conditions['latency'],317        'download_throughput': conditions['download_throughput'],318        'upload_throughput': conditions['upload_throughput'],319        'offline': conditions['offline']320    }321  def DeleteNetworkConditions(self):...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
