Created
November 4, 2013 14:09
-
-
Save thomi137/7302971 to your computer and use it in GitHub Desktop.
Monkey Runner example script for the Tricentis Accelerate Conference 7. November 2013
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage | |
# Get a device | |
device = MonkeyRunner.waitForConnection() | |
def main(): | |
# Install Package | |
device.installPackage("C:\\Users\\t.prosser\\workspace\\CensusApp\\bin\\CensusApp.apk") | |
package = 'com.newthinktank.censusapp' | |
main_activity = 'com.newthinktank.censusapp.ContactListActivity' | |
# Start Application | |
runComponent = package + '/' + main_activity | |
device.startActivity(component=runComponent) | |
snapper = Photographer(device) | |
MonkeyRunner.sleep(1) | |
snapper.get_picture() | |
device.touch(200, 200, 'DOWN_AND_UP') | |
MonkeyRunner.sleep(1) | |
snapper.get_picture() | |
snapper.dump_pictures() | |
class Photographer: | |
def __init__(self, device): | |
self.device = device | |
self.results = [] | |
def get_picture(self): | |
self.results.append(self.device.takeSnapshot()) | |
def dump_pictures(self): | |
for i in range(len(self.results)): | |
self.results[i].writeToFile('shot' + str(i) + '.png', 'png') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment