On this page:
1.1 What is Delirium?
1.2 How does it work?
Version: 4.1.3.3

1 Introduction

1.1 What is Delirium?

Delirium is a tool for testing PLT web application user interfaces. It allows programmers to write tests with unprecedented clarity and speed. Delirium is built on top of SchemeUnit and the PLT Web Server.

Web interface testing is difficult because you need to control the server and the browser at the same time. Delirium gives you the ability to write a single SchemeUnit script that does both in a single test script. There is very little configuration involved and you won’t need to write a lick of Javascript.

Here is an example test case that tests a login page for a simple web application:

  (test-case "Users can log in via the login page"
    ; The test database starts off empty: we need a new user:
    (let ([user (make-user #:username "dave" #:password "password")]
          [now  (current-milliseconds)])
      ; Save the user to the database:
      (save! user)
      ; Open the login page in the browser:
      (open/wait "/login")
      ; Fill in the login form in the browser:
      (enter-text (node/id 'username-field) "dave")
      (enter-text (node/id 'password-field) "password")
      ; Click 'Submit' and wait for the page to refresh:
      (click/wait 'submit-button)
      ; Check the page title is 'Welcome, dave!'
      (check-equal? (title-ref) "Welcome, dave!")
      ; Check the login was recorded:
      (check > (user-last-login user) now)))

This is a standard SchemeUnit test-case being run inside Delirium. The code used comes from three sources:

Note that, like SchemeUnit tests, Delirium tests are all fully fledged Scheme code: you can use all the abstractions that you would expect, including loops, conditionals, procedures and macros.

1.2 How does it work?

Delirium only works on web applications created for the PLT Web Server. Applications are set up so they can be run in two different modes:

Here is an example start procedure from a test servlet:

  ; start : request -> response
  (define (start request)
    ; run-delirium : request schemeunit-test-suite -> response
    (run-delirium request my-ui-test-suite))

The test servlet is typically mapped to a URL like http://localhost:8080/test. When the servlet is invoked, run-delirium will send a test-page to the browser. The test-page contains an <iframe> in which the web application is loaded. All browser API calls like open/wait and enter-text are directed at the frame. All the test suite has to do is call open/wait to load part of the web application and start testing it.

Delirium uses continuations to maintain a REPL-style testing loop: