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 py3-pip

Then fetch Selenium and install the Python module:

doas pip3.4 install selenium
ftp $url

Runtime

The selenium server listens on port 4444 and an instance of phantomjs on 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.4

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 January 23, 2018