From d31b0ee3c74f9aef6b93195ab4de4aca6317e268 Mon Sep 17 00:00:00 2001 From: LoveIsGrief Date: Fri, 22 Mar 2019 15:48:09 +0100 Subject: [PATCH] functional_tests: Allow provisioning VM for functional tests It's now possible to run the tests in the VM more easily without copy-pasting too much from HACKING.md. `vagrant provision --provisiion-with tests` will take care of the dependencies. freedombox/plinth#1521 - Provision VM to run function functional tests Reviewed-by: James Valleroy --- HACKING.md | 11 ++++++++++- Vagrantfile | 1 + functional_tests/install.sh | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 functional_tests/install.sh diff --git a/HACKING.md b/HACKING.md index c8d95b3c5..1afa68dd0 100644 --- a/HACKING.md +++ b/HACKING.md @@ -169,6 +169,9 @@ executed (red). ### Install Dependencies +**For running tests in the VM** run `vagrant provision --provision-with tests`. +Otherwise follow the instructions below. + ``` $ pip3 install splinter $ pip3 install pytest-splinter @@ -209,7 +212,13 @@ tests will create the required user using FreedomBox's first boot process. ### Run Functional Tests -Run +**When inside a VM you will need to target the guest VM** + +```bash +export FREEDOMBOX_URL=https://localhost +``` + +You will be running `py.test-3`. ``` $ py.test-3 --include-functional diff --git a/Vagrantfile b/Vagrantfile index 3b1baacd8..bdf3676f3 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -44,6 +44,7 @@ Vagrant.configure(2) do |config| # Install ncurses-term DEBIAN_FRONTEND=noninteractive apt-get install -y ncurses-term SHELL + config.vm.provision "tests", run: "never", type: "shell", path: "functional_tests/install.sh" config.vm.post_up_message = "FreedomBox virtual machine is ready for development. You can run the development version of Plinth using the following command. diff --git a/functional_tests/install.sh b/functional_tests/install.sh new file mode 100755 index 000000000..1596e3b28 --- /dev/null +++ b/functional_tests/install.sh @@ -0,0 +1,32 @@ +#!/bin/bash +set -euo pipefail +IFS=$'\n\t' + +echo "Installing requirements" +sudo apt-get install -yq --no-install-recommends \ + python3-pytest \ + python3-pip firefox \ + xvfb +pip3 install splinter pytest-splinter pytest-bdd pytest-xvfb + +echo "Installing geckodriver" +( + DL_DIR=/tmp/gecko + GECKO_VERSION="v0.24.0" + FILENAME="geckodriver-${GECKO_VERSION}-linux64.tar.gz" + GECKO_URL="https://github.com/mozilla/geckodriver/releases/download/$GECKO_VERSION/$FILENAME" + + test -e /usr/local/bin/geckodriver && echo "geckodriver already installed" && exit 0 + + mkdir -p $DL_DIR + cd $DL_DIR + if ! [[ -e $FILENAME ]] ; then + wget --no-clobber \ + --continue \ + --no-verbose \ + "$GECKO_URL" + fi + tar xf $FILENAME + sudo mv geckodriver /usr/local/bin/geckodriver + echo "Done" +)