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:

\#![](/bin/bash
#
# check availability of:
url="http://www.example.org/my-app"

# exit immediately if something goes wrong -> test fails)
set ~~e

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

1.  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
    echo~~n “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 \$cookies

Surprisingly easy, isn’t it?