David Seaward

Director of Trustworthy Services at Purism

Latest posts by David Seaward (see all)

Early this year Carlos Campos from Igalia implemented an automation mode in GNOME Web (sometimes known as Epiphany). This is especially useful for automated web testing, a subset of GUI testing. I decided it was time to take it for a spin. Carlos has covered the details in his post, here I will focus on the practical requirements to get things running in PureOS.

Minimum basic requirements

  • GNOME Web 3.31.4
  • Selenium 3.141.0

We will use the version of GNOME Web included in PureOS (currently 3.32.1.2) and the Python-based Selenium driver.

sudo apt install epiphany-browser # already installed, so not strictly neccessary
sudo apt install webkit2gtk-driver # required for browser integration
sudo apt install python3 pipenv # basic Python tools, don't leave home without 'em
mkdir webtest
cd webtest
pipenv install selenium # get latest version from PyPI

Using Pipenv

You’ll note that we’re using Pipenv to isolate our Python packages. This helps when sharing the tests between developers and machines. The upshot is that to access the Python libraries we must:

  1. be in the project folder (cd webtest)
  2. start Python invocations with pipenv run python

Basic implementation

Now create a simple Python file called web.py. I really liked Carlos’ encapsulation of GNOME Web as a Selenium driver:

from selenium import webdriver

class Epiphany(webdriver.WebKitGTK):
    def __init__(self):
        options = webdriver.WebKitGTKOptions()
        options.binary_location = 'epiphany'
        options.add_argument('--automation-mode')
        options.set_capability('browserName', 'Epiphany')
        options.set_capability('version', '3.32')

        webdriver.WebKitGTK.__init__(self, options=options, desired_capabilities={})

# Simple test
ephy = Epiphany()
ephy.get('https://pureos.net')
ephy.quit()

Now invoke the code:

pipenv run python web.py

An orange-bordered web window will briefly appear, load the page and then close:

Orange-bordered web window displaying the PureOS website

Running tests

We can now set up a testing skeleton. Let’s keep the Epiphany class, but remove everything from # Simple test onwards. Instead we’ll create a new file called test_web.py:

from web import Epiphany

def test_load():
    ephy = Epiphany()
    ephy.get('https://pureos.net')
    ephy.quit()

Before we can use this file we need to install a testing framework:

pipenv install pytest

And now we can run the tests:

pipenv run pytest

Web testing

Finally we will perform a simple web test using the Selenium API. Expand test_web.py as follows:

from web import Epiphany

def test_load():
    ephy = Epiphany()
    ephy.get('https://pureos.net')
    ephy.quit()

def test_title():
    ephy = Epiphany()
    ephy.get('https://puri.sm')
    assert 'Purism' in ephy.title
    ephy.quit()

Now invoke pytest again. You should get a result with 2 passed.

For more details on the Selenium API, see https://www.selenium.dev/selenium/docs/api/py/

With that, you are ready to create web tests using the default PureOS browser.

Recent Posts

Related Content

Tags