I'm tired of taking new screenshots everytime I change my UI for my iPhone application. I would like to be able to run a script/program/whatever to load my binary on the simulator and then take a few screenshots.
The solution can be in any language... it doesn't matter to me.
Thanks!
"Right Side+Volume Buttons" or "Home+Sleep" A simple way to capture a screenshot of your iPhone or iPad is to press and hold the "Home" button and simultaneously press the "sleep/wake" button. A screenshot will be saved to your camera roll.
If you take a screenshot from within your app running on the simulator, and then save it to photos app on that simulator, then it is stored in some library folder of that specific Simulator.
Hidden within iOS is a scrolling screenshot feature that allows you to capture multiple pages with only a single screenshot. There are third-party apps you can use to stitch together individual screenshots and create a longer one, but a scrolling screenshot makes the process easier.
The simulator does a really lousy job of indicating app performance. In fact it doesn't try. For most things the simulator is much, much faster than an iOS device. It runs your code on an x86 processor, which is much faster than the ARM and has many times more memory.
With iPhone SDK 4 you can automate GUI tests, and it can take screenshots for you.
Basically, you write a Javascript script, and then Instruments (using Automation template) can run it on the device to test the UI, and can Log data, screenshot, etc., and also can alert if something's broken.
I couldn't find a reference guide for it, but in the SDK reference library search for UIA*
classes (like UIAElement
).
There's also a video demoing this from WWDC, session 306.
I have the same wish. I want to be able to save screenshots from a few screens in my app without all the manual work. I'm not there yet, but I have started.
The idea is to tail /var/log/system.log, where the output from the NSLog statements go. I pipe the output to a python program. The python program reads all the lines from stdin and when the line matches a specific pattern, it calls screencapture.
NSLog(@"screenshot mainmenu.png");
That will cause a screenshot named "XX. mainmenu YY.png" to be created every time it is called. XX is the number of the screenshot since the program started. YY is the number of the "mainmenu" screenshot.
I have even added some unnecessary features:
NSLog(@"screenshot -once mainmenu.png");
This will only save "XX. mainmenu.png" once.
NSLog(@"screenshot -T 4 mainmenu.png");
This will make the screenshot after a delay of 4 seconds.
After running an app with the right logging, screenshots with the following names could have been created:
00. SplashScreen.png 01. MainMenu 01.png 03. StartLevel 01.png 04. GameOver 01.png 05. MainMenu 02.png
Give it a try:
Add some NSLog statements to your code
$ tail -f -n0 /var/log/system.log | ./grab.py
Start your iPhone app in the Simulator
Play around with your app
Have a look at the screenshots showing up where you started the grab.py program
grab.py:
#!/usr/bin/python import re import os from collections import defaultdict def screenshot(filename, select_window=False, delay_s=0): flags = [] if select_window: flags.append('-w') if delay_s: flags.append('-T %d' % delay_s) command_line = 'screencapture %s "%s"' % (' '.join(flags), filename) #print command_line os.system(command_line) def handle_line(line, count=defaultdict(int)): params = parse_line(line) if params: filebase, fileextension, once, delay_s = params if once and count[filebase] == 1: print 'Skipping taking %s screenshot, already done once' % filebase else: count[filebase] += 1 number = count[filebase] count[None] += 1 global_count = count[None] file_count_string = (' %02d' % number) if not once else '' filename = '%02d. %s%s.%s' % (global_count, filebase, file_count_string, fileextension) print 'Taking screenshot: %s%s' % (filename, '' if delay_s == 0 else (' in %d seconds' % delay_s)) screenshot(filename, select_window=False, delay_s=delay_s) def parse_line(line): expression = r'.*screenshot\s*(?P<once>-once)?\s*(-delay\s*(?P<delay_s>\d+))?\s*(?P<filebase>\w+)?.?(?P<fileextension>\w+)?' m = re.match(expression, line) if m: params = m.groupdict() #print params filebase = params['filebase'] or 'screenshot' fileextension = params['fileextension'] or 'png' once = params['once'] is not None delay_s = int(params['delay_s'] or 0) return filebase, fileextension, once, delay_s else: #print 'Ignore: %s' % line return None def main(): try: while True: handle_line(raw_input()) except (EOFError, KeyboardInterrupt): pass if __name__ == '__main__': main()
Issues with this version:
If you want to take a screenshot of only the iPhone Simulator window, you have to click the iPhone Simulator window for every screenshot. screencapture refuses to capture single windows unless you are willing to interact with it, a strange design decision for a command line tool.
Update: Now iPhone simulator cropper (at http://www.curioustimes.de/iphonesimulatorcropper/index.html) works from command line. So instead of using the built in screencapture, download and use it instead. So now the process is completely automatic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With