android-calculatorpp/app/misc/other/take_screenshots.py

65 lines
1.9 KiB
Python
Raw Permalink Normal View History

2012-11-22 16:19:14 -05:00
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
import time
import sys
outFolder = sys.argv[1]
outFilename = sys.argv[2]
print ''
print 'Screenshot will be located in ' + outFolder + ' with name ' + outFilename;
2012-11-25 15:13:15 -05:00
apk = '/home/serso/projects/java/android/calculatorpp/calculatorpp/misc/other/tmp/2012.11.25/calculatorpp.apk'
2012-11-22 16:19:14 -05:00
package = 'org.solovyev.android.calculator'
activity = 'org.solovyev.android.calculator.CalculatorActivity'
2012-11-25 15:00:30 -05:00
operatorsActivity = 'org.solovyev.android.calculator.math.edit.CalculatorOperatorsActivity'
deviceName = 'emulator-5580'
2012-11-22 16:19:14 -05:00
def takeScreenshot (folder, filename):
screenshot = device.takeSnapshot()
screenshot.writeToFile(folder + '/' + filename + '.png','png')
return
print 'Waiting for device ' + deviceName + '...'
device = MonkeyRunner.waitForConnection(100, deviceName)
2012-11-22 16:19:14 -05:00
if device:
print 'Device found, removing application if any ' + package + '...'
device.removePackage(package)
print 'Installing apk ' + apk + '...'
device.installPackage(apk)
runComponent = package + '/' + activity
print 'Starting activity ' + runComponent + '...'
device.startActivity(component=runComponent)
# sleep while application will be loaded
2012-11-25 15:00:30 -05:00
MonkeyRunner.sleep(15);
2012-11-22 16:19:14 -05:00
print 'Taking screenshot...'
#outFilename = outFilename + '_' + str(time.time())
takeScreenshot(outFolder, outFilename);
2012-11-22 16:19:14 -05:00
2012-11-25 15:00:30 -05:00
runComponent = package + '/' + operatorsActivity
print 'Starting activity ' + runComponent + '...'
device.startActivity(component=runComponent)
# sleep while application will be loaded
MonkeyRunner.sleep(4);
print 'Taking screenshot...'
#outFilename = outFilename + '_' + str(time.time())
takeScreenshot(outFolder, outFilename + '_operators');
2012-11-22 16:19:14 -05:00
print '#########'
print 'Finished!'
print '#########'
else:
print '#########'
print 'Failure!'
print '#########'