7. Tool for the job
Dexy
• Open Source (mostly MIT, some AGPL)
• Written in Python
• Command Line, Text Based
• * Agnostic
• My Day Job and my Mission in Life
8. Demo
What we want to create:
• Install Guide
• User Guide
• Developer Docs
What we need:
• An App!
• Install Script
• Watir Script
13. index.html
$def with (todos, form)
<table>
<tr>
<th>What to do ?</th>
<th></th>
</tr>
$for todo in todos:
<tr>
<td>$todo.title</td>
<td>
<form action= "/del/$todo.id" method= "post" >
<input type= "submit" value= "Delete" />
</form>
</td>
</tr>
</table>
<form action= "" method= "post" >
$:form.render()
</form>
14. todo.py
""" Basic todo list using webpy 0.3 """
import web
import model
urls = (
’ / ’ , ’ Index ’ ,
’ /del/( d+) ’ , ’ Delete ’
)
render = web.template.render( ’ templates ’ , base= ’ base ’ )
15. todo.py
class Index:
form = web.form.Form(
web.form.Textbox( ’ title ’ , web.form.notnull,
description= " I need to: " , size=75),
web.form.Button( ’ Add todo ’ ),
)
16. todo.py
def GET(self):
""" Show page """
todos = model.get_todos()
form = self.form()
return render.index(todos, form)
17. todo.py
def POST(self):
""" Add new entry """
form = self.form()
if not form.validates():
todos = model.get_todos()
return render.index(todos, form)
model.new_todo(form.d.title)
raise web.seeother( ’ / ’ )
18. todo.py
class Delete:
def POST(self, id):
""" Delete based on ID """
id = int(id)
model.del_todo(id)
raise web.seeother( ’ / ’ )
22. install script
hg clone https://bitbucket.org/ananelson/dexy-examples
cd dexy-examples
cd webpy
sqlite3 todo.sqlite3 < schema.sql
python todo.py
23. install script
export UBUNTU_AMI= "ami-06ad526f" # natty
cd ~/.ec2
ec2run $UBUNTU_AMI -k $EC2_KEYPAIR
-t t1.micro -f ~/dev/dexy-examples/webpy/ubuntu-install.sh
(Make sure to allow access to port 8080 in security group.)
24. Now What
• We have an app and we have it running.
• We have an install script which we can use to create an install guide.
• Now we need a script to show how the app works.
25. Watir
• Watir lets us automate the web browser
• Can be integrated with functional tests
• For extra awesomeness, let’s use Watir to take screenshots
27. watir
We create a reference to the browser:
browser = Watir::Safari.new
And define a helper method to take screenshots:
def take_screenshot(filename)
sleep(1) # Make sure page is finished loading.
‘ screencapture #{ filename } ‘
‘ convert -crop 800x500+0+0 #{ filename } #{ filename } ‘
end
28. watir
Now we’re ready to go!
browser.goto(BASE)
take_screenshot( " dexy--index.png " )
29. watir
Let’s enter a TODO:
browser.text_field( :name , " title " ).set( " Prepare Refresh Austin Talk Demo
take_screenshot( " dexy--enter.png " )
30. watir
Click the ”Add todo” button to add it. We’ll verify that it was actually added.
browser.button( :name , " Add todo " ).click
raise unless browser.html.include?( " <td>Prepare Refresh Austin Talk Demo</td>
take_screenshot( " dexy--add.png " )
31. watir
And delete it again:
browser.form( :index , 1).submit
take_screenshot( " dexy--delete.png " )
32. • Now we have screenshots we can use in our documentation, and which
we can update any time.
• We also know that the steps described in our screenshots WORK.
• Note that we are also validating our install script.
• You will want to return your DB to its original state within your script, or
have a reset method in your app.