| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 import sys | |
| 8 from optparse import OptionParser | |
| 9 from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice | |
| 10 | |
| 11 def main(argv): | |
| 12 # Parse options. | |
| 13 parser = OptionParser() | |
| 14 parser.add_option("--serial", dest="serial", | |
| 15 help="connect to device with specified SERIAL", | |
| 16 metavar="SERIAL") | |
| 17 parser.add_option("--file", dest="filename", | |
| 18 help="write screenshot to FILE", | |
| 19 metavar="FILE", default="Screenshot.png") | |
| 20 parser.add_option("--timeout", dest="timeout", | |
| 21 help="TIMEOUT in seconds for connecting to a device", | |
| 22 metavar="TIMEOUT", default=120) | |
| 23 (options, args) = parser.parse_args(argv) | |
| 24 | |
| 25 # Connect to the current device, returning a MonkeyDevice object. | |
| 26 # Monkeyrunner fails with a NullPointerException if options.serial is None. | |
| 27 if options.serial: | |
| 28 device = MonkeyRunner.waitForConnection(options.timeout, options.serial) | |
| 29 else: | |
| 30 device = MonkeyRunner.waitForConnection(options.timeout) | |
| 31 | |
| 32 if not device: | |
| 33 return 1 | |
| 34 | |
| 35 # Grab screenshot and write to disk. | |
| 36 result = device.takeSnapshot() | |
| 37 result.writeToFile(options.filename, 'png') | |
| 38 return 0 | |
| 39 | |
| 40 if __name__ == '__main__': | |
| 41 sys.exit(main(sys.argv)) | |
| OLD | NEW |