google / mobly

E2E test framework for tests with complex environment requirements.
https://github.com/google/mobly
Apache License 2.0
627 stars 175 forks source link

Support method "take_snapshot" in AndroidDevice #796

Closed johnklee closed 2 years ago

johnklee commented 2 years ago

From our user cases, we have to take screenshot of Phone quite a lot. Below is the code snippet for doing so:

      # take screenshot
      screenshot_path = 'sdcard/screenshot_{}.png'.format(current_time)
      device.adb.shell('screencap -p {}'.format(screenshot_path))
      device.adb.pull([screenshot_path, log_path])
      device.adb.shell('rm -rf {}'.format(screenshot_path))

I think it might be a good idea to let controller AndroidDevice to support it natively. Therefore, create this issue as feature request. Thanks!

xpconanfan commented 2 years ago

We already have take_screenshot in AndroidDevice right? https://github.com/google/mobly/blob/master/mobly/controllers/android_device.py#L1034

johnklee commented 2 years ago

Cool! Thanks for the reminder and it is of great help to us to learn that this useful method is already supported! I should check the source code first. Then this issue is no longer needed.

By the way, after checking the implementation, it seems we can only decide the prefix of the file name:

filename = self.generate_filename(prefix, extension_name='png')

Is there a reason why not let user to decide the full file name here? Otherwise, we may have to rename the output file from the return pic_path which is not bothering but we expect to be supported from the API. Thanks in advance!

Ps. From our code, we already handled the generation of appending timestamp of the filename and will use it to associate with other files (e.g. bugreport, log).

xpconanfan commented 2 years ago

"prefix" is the field that you can customize. The API handles addition of device identity and name de-dupe in filenames. It's probably better than trying to create yet another system to do the same thing with file names.

We recommend you use AndroidDevice#generate_filename for all your file names related to Android devices.

johnklee commented 2 years ago

Understood. Thanks for the explanation and feedback.