Integration tests are used to test application from top to bottom. That means simulating the browser across important workflows as if it was a real user. We will use Selenium as our headless browser.
Add the Selenium docker container to .devcontainer/docker-compose.yml
and restart your devcontainer. Note the No VNC and VNC comments, the selenium container allows us to connect via VNC to the container so we can actually see the browser as it performs the tests. The No VNC port means we don't even have to install VNC. You can connect with a browser to this port and use the No VNC browser client.
# Integration testing using a headless chrome browser
selenium:
image: selenium/standalone-chrome:4.1.1-20220121
shm_size: 2gb
environment:
VNC_NO_PASSWORD: 1
ports:
# VNC
- 5900:5900
# No VNC
- 7900:7900
We can write our tests in Rust using ThirtyFour which is a Selenium / WebDriver library for Rust, for automated website UI testing.
Add the following to bottom of app/Cargo.toml
.
[dev-dependencies]
# WebDriver Library for UI testing.
thirtyfour = { version = "0", default-features = false, features = [ "reqwest-rustls-tls", "tokio-runtime" ] }
We need a helper class to configure our selenium driver. Add the following to app/tests/config.rs
.
use env;
use *;
Create the following example test in app/tests/example_test.rs
.
use *;
// let's set up the sequence of steps we want the browser to take
async
async
Point your browser at http://localhost:7900
to view the tests. Run the test from the app
folder with cargo test
Production Example Cloak Integration Tests and Cloak docker-compose.yml