How do you test web applications? You can use Selenium, but Selenium is very heavy.
I tried wget.
To find out what exactly to send to the app, I started Firebug inside Firefox, went to the “Network” section and recorded what I would do, to see, whether the application works. Then I took the accessed URLs together with the parameters and first tried to send them manually from the command line. Observe, that Firebug lets you copy the exact POST/GET parameter as was sent by the browser, when you right click on the POST/GET command in the Firebug Network log. Once I managed to redo all the steps manuall from the commandline I transferred what I did into a script and edited it until it was nice and would run through:
$ history > test_my_web_app
test_my_web_app now looks as follows:
check availability of:
exit immediately if something goes wrong -> test fails)
echo “Testing \$url”
# save an error log in case there’s an error so that # we can analyse it further error_log=\$ cookies=\$
echo “In case the tests fail, you’ll find the error log under \$error_log” # send everything that goes to STDERR to the log exec 2>\$error_log
echo “Getting a cookie…” wget —save-cookies \$cookies “\$url”~~O /dev/null
we could put username/password directly into the script but we’re cautuous and don’t echo
n “please enter user for \$url:”; read user echon “please enter password for \$url:”; read ~~s pass echo
echo “Logging in…” # if we logged in successfully, then the webapp will send us an html page # that contains the following string: to_verify=“You’re logged in” # POST to the webapp: wget —load-cookies \$cookies —post-data “login=Login&user_login=\$user&user_password=\$pass” —save-cookies \$cookies —keep-session-cookies “\$url/login” ~~O - | grep ~~q “\$to_verify”
# now we’re logged in
echo “Query component DB…” # First search the DB num_components_found=\$
echo “Make sure that the app found something…” [ \$num_components_found~~gt 0 ]
echo “Generate and get picture…” wget —load-cookies \$cookies —save-cookies \$cookies —post-data ‘index=0’ “\$url/get-pic” -O /dev/null
echo “Hooray, \$url successfully tested”
rm \$error_log rm \$cookiesSurprisingly easy, isn’t it?