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

1 Introduction

1.1 What is Delirium?

Delirium is a tool for testing PLT web application user interfaces. It allows programmers to write user interface tests for PLT web applications using the popular unit testing framework Schemeunit. Web user 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 of these things. There is very little configuration involved and you won’t need to write a line of Javascript (unless you want to, that is).

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)))

The code in this example 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 comprehensions, higher order procedures and macros.

1.2 How does it work?

Delirium runs on top of the PLT Web Server. This allows it to maintain a REPL-style communication with the web browser using continuations:

Delirium is typically used to test PLT web applications. These applications are set up so they can be run in two different modes:

Here is an example web application written using web-server/servlet-env and Delirium:

  ;  -> response
  (define (start request)
    ; Application code goes here...)
  (define tests
    (test-suite "Delirium tests"
      ; Test code goes here...))
  ; -> thunk
  (define (run-production)
    (serve/servlet start))
  ; -> thunk
  (define (run-tests)
    (serve/delirium start tests))

In this example, run-production runs the regular application on port 8000 using the PLT web server’s built-in serve/servlet produre. run-tests runs the same application using the serve/delirium wrapper procedure. serve/delirium configures the web server to run the application as normal except for the following caveats:

Opening the URL /test loads a Delirium test page into the browser. Application web pages are loaded into an iframe on the test page, allowing Delirium to remote-control the application using Javascript. Once the iframe has been created, Delirium invokes the test suite and continues as described above.