Skip to main content

Mobly Android Screen Recorder service for using Python code to screencast the Android devices in Mobly tests.

Project description

Mobly Android Screen Recorder

Mobly Android Screen Recorder service for using Python code to screencast the Android devices in Mobly tests (https://github.com/google/mobly).

This tool is upgraded to scrcpy v3.3 and adds audio recording feature.

Responsible Use

This tool is designed for legitimate testing and debugging purposes within the context of Mobly. It should only be used in situations where you have:

  • Explicit consent: Obtain clear and informed consent from any individuals
  • whose screens might be recorded.
  • Legitimate purpose: Use the tool for legitimate testing, debugging,
  • or development activities related to Mobly.
  • Data security: Handle recorded screen data responsibly. Store it
  • securely and delete it when it's no longer needed.
  • Transparency: Be transparent about how the tool is being used and what
  • data is being collected.

Misuse of this tool for unauthorized surveillance or any other malicious activity is strictly prohibited.

Remember: Recording someone's screen without their knowledge or consent is a serious breach of privacy and may have legal consequences.

Requirements

  • Python 3.11+
  • Mobly 1.12.2+
  • FFMPEG 6.1.1+

Please make sure your FFMPEG support H.264 (run ffmpeg -codecs and look for libx264 encoder in the output) and the OpenCV in Python built with the H.264 encoder(print(cv2.getBuildInformation()) then look at the Video I/O section).

Note: To use the audio recording feature, you must have ffmpeg installed and available in your system's PATH.

Installation

pip install mobly-android-screen-recorder

Start to Use

After initializing the Android device, you can register the screen recorder service with the following code:

from mobly.controllers.android_device_lib.services import screen_recorder
...

self.dut = self.register_controller(android_device)[0]
# To enable audio recording, set `enable_audio=True` in the configs.
configs = screen_recorder.Configs(enable_audio=True)
self.dut.services.register('screen_recorder', screen_recorder.ScreenRecorder, configs=configs)

Then the screen recorder will start recording the screen when the test starts and stop recording when the test finishes. The screen recording will be saved to the test output folder as a video file during teardown process for each test case with create_output_excerpts_all for all registered Mobly services.

Example 1: Hello World!

Let's start with the simple example of posting "Hello World" on the Android device's screen. Create the following files: sample_config.yml

TestBeds:
  # A test bed where adb will find Android devices.
  - Name: SampleTestBed
    Controllers:
        AndroidDevice: '*'

hello_world_test.py

from mobly import base_test
from mobly import test_runner
from mobly.controllers import android_device
from mobly.controllers.android_device_lib.services import screen_recorder

class HelloWorldTest(base_test.BaseTestClass):

  def setup_class(self):
    # Registering android_device controller module declares the test's
    # dependency on Android device hardware. By default, we expect at least one
    # object is created from this.
    self.ads = self.register_controller(android_device)
    self.dut = self.ads[0]
    # Start Mobly Bundled Snippets (MBS).
    self.dut.load_snippet('mbs', android_device.MBS_PACKAGE)
    # Register screen recorder service, it will start recording when the test
    # starts and stop recording when the test finishes.
    # To enable audio recording, set `enable_audio=True` in the configs.
    configs = screen_recorder.Configs(enable_audio=True)
    self.dut.services.register('screen_recorder', screen_recorder.ScreenRecorder, configs=configs)

  def test_hello(self):
    self.dut.mbs.makeToast('Hello World!')

  def teardown_test(self):
    self.dut.services.create_output_excerpts_all(self.current_test_info)

if __name__ == '__main__':
  test_runner.main()

To execute:

$ python hello_world_test.py -c sample_config.yml

Expect:

A "Hello World!" toast notification appears on your device's screen. And a video file named video,{device_serial},{device_model},{timestamp}.mp4 is created in the test output folder.

Disclaimer

This tool, owned by Google and its developers, provides screen recording functionality for Android devices within the context of Mobly testing. It is essential to use this tool responsibly and ethically.

Privacy Warning: Screen recording can capture sensitive information. Always obtain explicit consent before recording anyone's screen. Unauthorized screen recording may violate privacy laws and ethical guidelines. Neither Google nor the developers of this tool are responsible for any misuse or illegal activity conducted with this software.

Users of this tool are solely responsible for ensuring compliance with all applicable laws and regulations regarding privacy and data protection.

Licensing

This project is licensed under the Apache License 2.0.

This project uses scrcpy, which is licensed under the Apache License 2.0. See the NOTICE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mobly_android_screen_recorder-1.0.4.tar.gz (3.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mobly_android_screen_recorder-1.0.4-py3-none-any.whl (3.7 MB view details)

Uploaded Python 3

File details

Details for the file mobly_android_screen_recorder-1.0.4.tar.gz.

File metadata

File hashes

Hashes for mobly_android_screen_recorder-1.0.4.tar.gz
Algorithm Hash digest
SHA256 22e41522a973582c5a4be4fa4e19d8fefa75e1c9cd43591839d38f9f0f31a724
MD5 3692c98e94ca453f27a2ba0020341036
BLAKE2b-256 0e78bd5836d72c20eb2b5694b85e6d30475d4d76fcfee481269d892de5a34032

See more details on using hashes here.

Provenance

The following attestation bundles were made for mobly_android_screen_recorder-1.0.4.tar.gz:

Publisher: publish-to-pypi.yml on google/mobly-android-screen-recorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mobly_android_screen_recorder-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for mobly_android_screen_recorder-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 753d5dcb466755783953888c3d5aeb682e72921937906b60069d2baecf81d15a
MD5 84e6d5c39a177e046c6eae89cb33bbbd
BLAKE2b-256 fc94d33d9fcb550b50c877921f57d683ef080376b1359124539daa55969c657a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mobly_android_screen_recorder-1.0.4-py3-none-any.whl:

Publisher: publish-to-pypi.yml on google/mobly-android-screen-recorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page