title: Headless Testing Against Real Web Browsers author: name: Mike Ball url: https://github.com/mdb output: index.html style: style.css
- slides are at github.com/mdb/testing-with-xvfb
- TravisCI compiles the slides, executes crude tests using Xvfb, and auto-deploys
master
to mdb.github.io/testing-with-xvfb
Submit a PR fixing the fix-my-code branch based on its failing tests!
- ensure software works as it should
- help team move fast
- help us understand how change impacts the larger system
- help ensure customer quality
- ensures a codebase's health is continuously monitored with each change
- methodically consistent, easily repeatable
- as fast and cheap as possible, while still honoring its responsibilities
- feedback cycle!
Growth means increased responsibility...
- more and more of the full stack
- build, deploy, release operations
- production support operations
- quality
- phantomjs
- EnvJS
- Rhino
- RubyRacer
- Node.js
- etc.
- Flash
- NW.js
- Electron
- Google Polymer web-component-tester
Google technology for authoring applications with web components
github.com/Polymer/web-component-tester
web-component-tester
assumes a GUI.
And a real web browser(s).
And virtualized CI build agents don't have a display.
- TravisCI
- Sauce Labs
docs.travis-ci.com/user/gui-and-headless-browsers
- Xvfb
- Firefox
- little-known TravisCI feature
- many Polymer projects overlooked CI altogether
...hence my JSConf 2015 talk.
Much more common!
language: node_js
before_script:
- npm install -g bower web-component-tester
- bower install
addons:
firefox: '46.0'
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
script:
- xvfb-run wct
- Selenium cloud
- Access to over 100 device/OS/browser combos
- SLA
- budget
- networking/firewall/security restrictions
AKA Xvfb
run GUI applications (like web browsers) with no display!
(how TravisCI runs web browsers)
How GUI displays are rendered on UNIX/UNIX-like systems
- current release of the X Window System
- windowing system for bitmap displays used to build GUIs
- how visual elements are rendered on a screen and made available for user interaction via a GUI in Mac OS & Linux, etc.
- like any other X server, yet no graphical output is shown
- performs graphical operations in memory; no screen ouput shown
- does not require the computer running it to have a display
Set up your own Ubuntu VM for testing with Xvfb!
github.com/mdb/polymer-testing-box
- Xvfb
- ansible
- Google Chrome
- Firefox (46)
- Node.js
- bower
- web-component-tester
- provision a Vagrant Ubuntu box
ansible
will install and configure all necessary dependencies- we'll execute tests against a Polymer web component
(not JavaScript)
- built on VirtualBox
- tool to spin up lightweight, headless VMs
- the "provider"
(not JavaScript)
...
config.vm.network 'forwarded_port', guest: 5900, host: 5901
config.vm.provision :ansible do |ansible|
ansible.playbook = 'playbook.yml'
end
...
(not JavaScript)
- install and run Xvfb on display port 0
- install Node.js, bower, web-component-tester
- install Google Chrome & Firefox
cd /vagrant
git clone https://github.com/PolymerElements/iron-ajax.git
cd core-ajax
bower install
How do we know Chrome and Firefox really ran?
And what about debugging?
sudo apt-get install x11vnc
x11vnc -display :0 &
brew install Caskroom/cask/tigervnc-viewer
...start Tiger VNC Viewer on localhost:5901
remmber this from the Vagrantfile
?
...
config.vm.network 'forwarded_port', guest: 5900, host: 5901
...
github.com/mdb/polymer-testing-box
VMs are cool but what about containers?
(not JavaScript)
- container engine
- "sandbox" with everything code needs to run
- code, runtime, system tools, system libraries
- layer of Linux OS-level abstraction beyond VM
- increasingly common
- TravisCI utilizes Docker workers
- more lightweight than Ansible-provisioned VM
Execute wct
in a Docker container running Xvfb!
Dockerfile
specs out how to build the Docker image.
FROM nodesource/trusty:latest
RUN apt-get update;
# install Chrome
RUN apt-get install -y curl
RUN curl -sL https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo 'deb http://dl.google.com/linux/chrome/deb/ stable main' >> /etc/apt/sources.list.d/google.list
RUN apt-get update
RUN apt-get install -y google-chrome-stable
# install Firefox 46
RUN apt-get install -y wget tar
RUN wget -O /usr/local/firefox-46.0.1.tar.bz2 http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/46.0.1/linux-x86_64/en-US/firefox-46.0.1.tar.bz2
RUN tar xvjf /usr/local/firefox-46.0.1.tar.bz2 -C /usr/local
RUN ln -s /usr/local/firefox/firefox /usr/bin/firefox
# install xvfb
RUN apt-get install -y xvfb;
# install java; needed by selenium
RUN apt-get install -y default-jre
# install web-component-tester & bower globally
RUN npm install -g web-component-tester
RUN npm install -g bower
# configure bower
RUN echo '{ "allow_root": true }' > /root/.bowerrc
- Install & run Docker
- Download the image from DockerHub
- Run the image
github.com/mdb/docker-wct uses TravisCI.
- CI/tests serve as self-documenting quality checks
- Docker lends itself well to CI
- CI operates as living example of the tool's usage
So...read the .travis.yml
if you're confused.
And take a gander at its TravisCI builds.
docker pull clapclapexcitement/wct
...
docker run -it \
-v $(pwd)/iron-ajax:/usr/src/app \
--security-opt seccomp:unconfined \
clapclapexcitement/wct bash \
-c "bower install && xvfb-run wct --skip-selenium-install"
- mount
iron-ajax
repo from your Mac into container - pass a
security-opt
to deal with Chrome's use of seccomp sandboxing - declare the image to run
- declare the command we want the container to run
How do we know the browsers really ran?
And what about visual debugging?
I demo'd this for a VM, but what about a container?
VNC could work but let's get weird.
- Xquartz - Apple's X Window system
socat
- networking utility; expose the Mac's Xquartz socket to the container on a TCP port- declare the Xquartz
$DISPLAY
as the container's$DISPLAY
- Run socat to expose Xquartz to the container
- use
-e DISPLAY=192.168.65.1:0
Docker option
(What's that weird IP? Docker on Mac requires VirtualBox; it's the VirtualBox host IP)
- spin up a cloud instance during your builds?
- collect remote screen captures?
- advanced web scraping?
- headless functional testing?
- more Docker images?
<iframe id="embedded-animation" src="http://mikeball.me/"></iframe>