Skip to content

Instantly share code, notes, and snippets.

@renoirb
Last active October 4, 2018 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renoirb/7d9d8079aff00304254277004078a842 to your computer and use it in GitHub Desktop.
Save renoirb/7d9d8079aff00304254277004078a842 to your computer and use it in GitHub Desktop.
Setting up automated-tests-web into Vagrant

Setup instructions

Alternatively, you can try running the same test system with a Vagrant VM setup using Ansible

Start the VM

mkdir headless
cd headless
git clone https://gist.github.com/7d9d8079aff00304254277004078a842.git .

Make sure setup.sh has the right IP (see 192.168.99.100, adjust). This’ll be parametrized (TODO).

Boot the VM

vagrant up

If Vagrant throws an error sudo rm -rf /opt/vagrant/embedded/bin/curl source on StackOverflow. Because vagrant distributes its own version of curl.

... wait

Clone integration-testing

(TODO: make reference to that code prototype somewhere accessible.)

Configure integration-testing config to point to IP, replace <password> and 192.168.99.100 accordingly

vi default-test-config.json

Go into the new VM

integration-testing code is in /vagrant/integration-testing, go on.

cd ..
vagrant ssh
cd /vagrant/integration-testing
make

Finish up manually what'll be automated pretty soon...

source bin/activate
cd api.common/
pip install -r requirements.txt
cd ..

Run the tests

PYTHONPATH="$(pwd)/" bin/pytest tests/features/login/test_login.py

Using it looks like the following screenshot.

Running WebDriver with PyTest, Splinter, Google Chrome and WebDriver, Headlessly

bin/:
$(info No VirtualEnv found, setting one up)
virtualenv .
virtualenv . --relocatable
( \
. ./bin/activate; \
pip install -r requirements.txt; \
pip install flask_cache; \
)
.PHONY: clean
clean: bin/
$(info Cleaning stuff up)
@find . -type f -name '*.pyc' -exec rm {} \;
@rm -rf .cache/ lib/
#!/bin/bash
set -e
apt-get remove -y --purge puppet puppet-common chef-zero chef
sh -c "echo '192.168.99.100 localhost.docker' >> /etc/hosts"
apt-get install -y python-pip python-dev python-pycryptopp \
libmysqlclient-dev libpq-dev \
build-essential libssl-dev libffi-dev xvfb
pip install virtualenv
## Reference
## * http://askubuntu.com/questions/621246/configure-xvfb-for-vivid-15-04-as-a-service-using-systemd
## * http://upstart.ubuntu.com/cookbook/#run-a-job-as-a-different-user
(cat <<- '_EOF_'
# Xvfb - X11 Virtual Frame Buffer
description "X11 Virtual Frame Buffer"
start on runlevel [2345]
stop on runlevel [06]
expect fork
respawn
script
. /etc/default/xvfb
exec Xvfb $XVFB_OPTIONS
end script
_EOF_
) > /etc/init/xvfb.conf
(cat <<- _EOF_
XVFB_OPTIONS=":1 -ac -screen 0 1024x768x16 -noreset -nolisten tcp +render"
_EOF_
) > /etc/default/xvfb
(cat <<- _EOF_
export DISPLAY=:1
_EOF_
) > /etc/profile.d/xvfb.sh
service xvfb start
mkdir -p /vagrant/pkgs/
# https://www.google.ca/chrome/browser/thankyou.html?platform=linux
if [[ ! -f /vagrant/pkgs/google-chrome-stable_current_amd64.deb ]]; then
curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /vagrant/pkgs/google-chrome-stable_current_amd64.deb
fi
apt-get install -y libnss3 libgconf-2-4 libxss1 libnspr4 libnss3-nssdb
apt-get install -y libgtk2.0-0 libpango1.0-0 fonts-liberation libappindicator1 xdg-utils
dpkg -i /vagrant/pkgs/google-chrome-stable_current_amd64.deb
if [[ ! -f /vagrant/pkgs/chromedriver_linux64.zip ]]; then
curl https://chromedriver.storage.googleapis.com/2.25/chromedriver_linux64.zip -o /vagrant/pkgs/chromedriver_linux64.zip
fi
sudo apt-get -f install -y
sudo apt-get autoremove -y
sudo apt-get install -y unzip
cd /vagrant/pkgs/
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/bin/
echo Done
# Define VM memory usage through environment variables
MEMORY = ENV.fetch("VAGRANT_MEMORY", "1024")
RELEASE = ENV.fetch("VAGRANT_UBUNTU_RELEASE", "trusty")
Vagrant.configure(2) do |config|
if RELEASE == "xenial"
## Either use this one
config.vm.box = "ubuntu/xenial64"
config.vm.box_check_update = false
else
config.vm.box = "trusty-cloud"
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
end
config.ssh.forward_agent = true
# ref: https://github.com/mitchellh/vagrant/issues/1673
config.vm.provision "fix-no-tty", type: "shell" do |s|
s.privileged = false
s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
end
config.vm.network "private_network", type: "dhcp"
if Vagrant.has_plugin?("vagrant-cachier")
# Configure cached packages to be shared between instances of the same base box.
# More info on http://fgrehm.viewdocs.io/vagrant-cachier/usage
config.cache.scope = :box
config.cache.enable :apt
if RELEASE == "xenial"
config.cache.synced_folder_opts = {
owner: "_apt",
group: "_apt"
}
end
end
config.vm.synced_folder ".", "/vagrant"
config.vm.provider "virtualbox" do |v|
v.name = config.vm.hostname
# ref: http://www.virtualbox.org/manual/ch08.html
v.customize ["modifyvm", :id, "--memory", MEMORY]
v.customize ["modifyvm", :id, "--description", "Vagrant VM in " + File.dirname(__FILE__) ]
v.customize ["modifyvm", :id, "--ostype", "Ubuntu_64"]
v.customize ["modifyvm", :id, "--pae", "on"]
end
config.vm.provision "setup", type: "shell" do |s|
s.inline = "/bin/bash /vagrant/setup.sh"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment