Skip to content

Commit

Permalink
[py] Pretty-printing code samples
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Jan 12, 2019
1 parent a80f06c commit e74164e
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 108 deletions.
16 changes: 10 additions & 6 deletions py/selenium/webdriver/chrome/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ def set_network_conditions(self, **network_conditions):
- network_conditions: A dict with conditions specification.
:Usage:
driver.set_network_conditions(
offline=False,
latency=5, # additional latency (ms)
download_throughput=500 * 1024, # maximal throughput
upload_throughput=500 * 1024) # maximal throughput
::
driver.set_network_conditions(
offline=False,
latency=5, # additional latency (ms)
download_throughput=500 * 1024, # maximal throughput
upload_throughput=500 * 1024) # maximal throughput
Note: 'throughput' can be used to set both (for download and upload).
"""
Expand All @@ -131,7 +133,9 @@ def execute_cdp_cmd(self, cmd, cmd_args):
- cmd_args: A dict, command args. empty dict {} if there is no command args
:Usage:
driver.execute_cdp_cmd('Network.getResponseBody', {'requestId': requestId})
::
driver.execute_cdp_cmd('Network.getResponseBody', {'requestId': requestId})
:Returns:
A dict, empty dict {} if there is no result to return.
Expand Down
8 changes: 6 additions & 2 deletions py/selenium/webdriver/firefox/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ def install_addon(self, path, temporary=None):
:param path: Absolute path to the addon that will be installed.
:Usage:
driver.install_addon('/path/to/firebug.xpi')
::
driver.install_addon('/path/to/firebug.xpi')
"""
payload = {"path": path}
if temporary is not None:
Expand All @@ -259,6 +261,8 @@ def uninstall_addon(self, identifier):
Uninstalls Firefox addon using its identifier.
:Usage:
driver.uninstall_addon('addon@foo.com')
::
driver.uninstall_addon('addon@foo.com')
"""
self.execute("UNINSTALL_ADDON", {"id": identifier})
28 changes: 20 additions & 8 deletions py/selenium/webdriver/remote/switch_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def active_element(self):
Returns the element with focus, or BODY if nothing has focus.
:Usage:
element = driver.switch_to.active_element
::
element = driver.switch_to.active_element
"""
if self._driver.w3c:
return self._driver.execute(Command.W3C_GET_ACTIVE_ELEMENT)['value']
Expand All @@ -49,7 +51,9 @@ def alert(self):
Switches focus to an alert on the page.
:Usage:
alert = driver.switch_to.alert
::
alert = driver.switch_to.alert
"""
alert = Alert(self._driver)
alert.text
Expand All @@ -60,7 +64,9 @@ def default_content(self):
Switch focus to the default frame.
:Usage:
driver.switch_to.default_content()
::
driver.switch_to.default_content()
"""
self._driver.execute(Command.SWITCH_TO_FRAME, {'id': None})

Expand All @@ -73,9 +79,11 @@ def frame(self, frame_reference):
or a webelement that is an (i)frame to switch to.
:Usage:
driver.switch_to.frame('frame_name')
driver.switch_to.frame(1)
driver.switch_to.frame(driver.find_elements_by_tag_name("iframe")[0])
::
driver.switch_to.frame('frame_name')
driver.switch_to.frame(1)
driver.switch_to.frame(driver.find_elements_by_tag_name("iframe")[0])
"""
if isinstance(frame_reference, basestring) and self._driver.w3c:
try:
Expand All @@ -94,7 +102,9 @@ def parent_frame(self):
level browsing context, the context remains unchanged.
:Usage:
driver.switch_to.parent_frame()
::
driver.switch_to.parent_frame()
"""
self._driver.execute(Command.SWITCH_TO_PARENT_FRAME)

Expand All @@ -106,7 +116,9 @@ def window(self, window_name):
- window_name: The name or window handle of the window to switch to.
:Usage:
driver.switch_to.window('main')
::
driver.switch_to.window('main')
"""
if self._driver.w3c:
self._w3c_window(window_name)
Expand Down

0 comments on commit e74164e

Please sign in to comment.