Eric Radman : a Journal

Integration Testing with Selenium and PhantomJS

Writing integration tests for a web app is not very difficult to set up thanks to ghostdriver, which is built into phantomjs.

Prerequisites

On OpenBSD add the following packages

doas pkg_add jre phantomjs python-3.4.1p1 py3-pip

Then fetch Selenium and install the Python module:

doas pip3.4 install selenium
ftp $url

Runtime

The selenium server (port 4444) and an instance of phantomjs (port

8080) must be running first
java -jar selenium-server-standalone-2.42.2.jar &
phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://127.0.0.1:4444 &

Your First Test

#!/usr/local/bin/python3.3

from selenium import webdriver

browser = webdriver.PhantomJS(executable_path="/usr/local/bin/phantomjs")
browser.get("http://openbsd.org/")

assert "OpenBSD" in browser.title
print("DONE")

For further reading see the Selenium Documentation.

Last updated on March 08, 2017
eradman.com/source