VNC Robot
October 8th, 2009
Today at work I had a interesting request. Make a screenshot of a Flash application and send this the customer by mail every 5 minutes or so. First I though that it would be best to utilize some Actionscript with PHP/GD. This was ok but the other guys seemed to prefer some other hack. So I came up with using something like Browsershots, or some CutyCapt/IECapt, Python, Django combination. This seemed too complicated though.
So I finally settled with using VNC Robot. This thing is actually really funny, its like (shudder) Windows Scripting Host in VNC. Perfect!.
Originally I also looked into Ruby/Mechanize and other alike but with Flash thats a problem these days...
Here is a sample script I created and other nifty examples can be found here.
# Open Firefox from start menu
Mouse move to=x:145,y:755 wait=1000
Mouse click count=1
# Go to location bar
Mouse move to=x:262,y:65 wait=1000
Mouse click count=1
# Go to webpage
# Press Ctrl+l wait=1000
Press Backspace count=20
Type "http://10.0.0.9" wait=1000
Press Enter wait=6000
# Go to login form
Press Tab wait=1000
Type "usernamewashere" wait=1000
Press Tab wait=1000
Type "passwordwashere" wait=1000
# Skip over the "Do you want to remember password question"
Press Enter wait=1000
Press Enter wait=1000
Wait 10000
# Take a screenshot and send it to John
Screenshot /tmp/stock.jpg
Sendmail subject="XYZ Application stock on {_DATE}" from="root@yourmachine" to="foobar@blahblubb.org"
server="localhost" attach="/tmp/stock.jpg"
# Close the browser so that we can rerun the script safely
Press Alt+F4 wait=500
Press Alt+F4 wait=500
The result looks like this (scaled down).
Sorry, comments are closed for this article.