Pliant Computing
Flexible. Supple. Adaptable.
Testing Pliant Powered Websites
 
Working the Widgets

Testing websites is one of the most important tools in development of complex web applications. Fortunately, websites powered by pliant can be tested easily. Amazingly, for these tests a web-browser is not needed because the UI behaviour is completely server driven.

As well, this testing approach allows to batch tests and schedule to be re-run automatically as a cron job.

For example, this sample test script tries to login with a user "user1" into a pliant powered website:

ui_function test_login robot test
  arg_rw UITest test ; arg_rw UIRobot robot
  implicit test robot
    section_overwrite "output"
      plan_tests 2
      is get_button_label:"login_button" "sign in"
      click "login_button"
      set "login_username" "user1"
      set "login_password" "user1pass"
      click "login_submit_button"
      is get_button_label:"login_button" "logout user1"
      dump_html "file:/tmp/screen_after_login.html"
      test_summary
              

As you can see, the "robot" argument is passed to the "test_login" function. Using the robot's methods such as "set" and "click" we are able to work the login form and login ourselves into the system. After the login is successful the login button we have clicked originally must change its caption from "login" to "logout user1". We verify that in the test and know that the login was successful.

As well, please notice the "dump_html" call. This will save the current HTML content that is seen by the user. This HTML can be further analyzed by the test, or to be used as a development aid to help write the test script.

Finally, notice the "test" object that is passed as a second argument. It provides assertion methods "is" (aka "assertEquals"), and methods "plan_tests" and "test_summary".

Below is the code that initializes the "robot" by connecting it to the page we are interested in testing:

(var UITest test) context :> context
var UIRobot robot
robot open "tcp://"+test_server+"/mywebsite/index"
test_login robot test
robot close
              

Below is an output of a similar test.

 
Database

It is very usefull to reduce the database in test mode only to a few records. This allows to easily test that it is properly modified as a result of web application operation.

Cosider the following example code to be tested:

section "girls"
  each person mydb:data:people
    if person:is_female
      text person:name; eol
            

We would like to test that the code indeed outputs only girls' names. We reset the database and populate it with a controlled set of people.

# re-bind global handle with temporary file
mydb load "file:/tmp/testdb/"+generate_id+".pdb"

# create user records 
#   Anne, Sophie, Mary, 
#   Bob, Jack, Jimmy
#   ...
            

Later, in when viewing the screen containing section "girls",


ok (contains_text "girls" "Anne")
ok (contains_text "girls" "Sophie")
ok (contains_text "girls" "Mary")
ok not (contains_text "girls" "Bob")
ok not (contains_text "girls" "Jack")
ok not (contains_text "girls" "Jimmy")
              

Note: This is possible only when the test code and the application code run in the same process (same virtual computer). Thus, the "test_server" constant in previous section example must be the IP address and port of this logical computer.