Testing a user interface is a challenging task in programming. However, new tools have emerged to make this better feasible. Using the setup of an web app using the SAFE template, canopy is a testing library that enables UI testing in the browser.
One of the best programming practices is the use of a REPL (Run Evaluate Print Loop). F# uses script files and the FSI for this process. Normally I develop code in an script file run it in the REPL and continue until I have created a specific feature. Ideally, the same can be applied to setting up and running tests.
The first step is to import the needed libraries in the script file. With the pakket manager Paket, there is an option to have a script file generated that will reference all the needed libraries for a specific project. This can be done command line:
Or a directive can be added in the paket.dependencies file:
The resulting references script file can be loaded in the script file used to create the tests. First the project is started up for development. Then the script file with tests is run in the REPL. This will fire up a browser, load the application and run the UI tests:
The results look like: