Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions appium/webdriver/extensions/execute_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@


class ExecuteDriver(CanExecuteCommands):
# TODO Inner class case
def execute_driver(self, script: str, script_type: str = 'webdriverio', timeout_ms: int | None = None) -> Any:
class Result:
"""The result of ``execute_driver``, containing ``result`` and ``logs``."""

result: Any
logs: dict[str, list[Any]]

def __init__(self, res: dict[str, Any]) -> None:
self.result = res['result']
self.logs = res['logs']

def execute_driver(
self, script: str, script_type: str = 'webdriverio', timeout_ms: int | None = None
) -> 'ExecuteDriver.Result':
"""Run a set of script against the current session, allowing execution of many commands in one Appium request.
Please read http://appium.io/docs/en/commands/session/execute-driver for more details about the acceptable
scripts and the output format.
Expand All @@ -43,18 +54,12 @@ def execute_driver(self, script: str, script_type: str = 'webdriverio', timeout_
Raises:
WebDriverException: If something error happens in the script. The message has the original error message.
"""

class Result:
def __init__(self, res: dict):
self.result = res['result']
self.logs = res['logs']

option: dict[str, str | int] = {'script': script, 'type': script_type}
if timeout_ms is not None:
option['timeout'] = timeout_ms

response = self.execute(Command.EXECUTE_DRIVER, option)['value']
return Result(response)
return ExecuteDriver.Result(response)

def _add_commands(self) -> None:
self.command_executor.add_command(Command.EXECUTE_DRIVER, 'POST', '/session/$sessionId/appium/execute_driver')
10 changes: 6 additions & 4 deletions appium/webdriver/extensions/screen_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ def stop_recording_screen(self, **options: Any) -> bytes:
headers (dict): [multipart/form-data requests] Headers mapping (Since Appium 1.18.0)

Usage:
payload = driver.stop_recording_screen()
with open('media.mp4', "wb") as fd:
import base64
fd.write(base64.b64decode(payload))
.. code-block:: python

payload = driver.stop_recording_screen()
with open('media.mp4', "wb") as fd:
import base64
fd.write(base64.b64decode(payload))

Returns:
bytes: Base-64 encoded content of the recorded media file or an empty string
Expand Down
9 changes: 4 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@
#
html_theme = 'sphinx_rtd_theme'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

add_module_names = False

autodoc_default_options = {
'exclude-members': 'T',
}
2 changes: 1 addition & 1 deletion docs/generate.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
rm -rf *rst _build
uv run sphinx-apidoc -F -H 'Appium python client' -o . ../appium/webdriver
uv run sphinx-apidoc -F -H 'Appium python client' -o . ../appium/webdriver ../appium/webdriver/mobilecommand.py
make html
4 changes: 1 addition & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
Appium python client documentation
==================================

Add your content using ``reStructuredText`` syntax. See the
`reStructuredText <https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html>`_
documentation for details.
API reference documentation for `Appium-Python-Client <https://github.com/appium/python-client>`_.


.. toctree::
Expand Down
9 changes: 1 addition & 8 deletions docs/webdriver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@ webdriver.locator\_converter module
:show-inheritance:
:undoc-members:

webdriver.mobilecommand module
------------------------------

.. automodule:: webdriver.mobilecommand
:members:
:show-inheritance:
:undoc-members:

webdriver.switch\_to module
---------------------------

Expand Down Expand Up @@ -124,3 +116,4 @@ Module contents
:members:
:show-inheritance:
:undoc-members:
:no-index:
2 changes: 2 additions & 0 deletions test/unit/webdriver/execute_driver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import httpretty

from appium.webdriver.extensions.execute_driver import ExecuteDriver
from test.unit.helper.test_helper import android_w3c_driver, appium_command, get_httpretty_request_body


Expand All @@ -40,6 +41,7 @@ def test_batch(self):
return [element, rect];
"""
response = driver.execute_driver(script=textwrap.dedent(script))
assert isinstance(response, ExecuteDriver.Result)
# Python client convert an element item as WebElement in the result
assert response.result[0].id == '39000000-0000-0000-D39A-000000000000'
assert response.result[1]['y'] == 237
Expand Down
Loading