Epiphany automation mode

Last week I finally found some time to add the automation mode to Epiphany, that allows to run automated tests using WebDriver. It’s important to note that the automation mode is not expected to be used by users or applications to control the browser remotely, but only by WebDriver automated tests. For that reason, the automation mode is incompatible with a primary user profile. There are a few other things affected by the auotmation mode:

  • There’s no persistency. A private profile is created in tmp and only ephemeral web contexts are used.
  • URL entry is not editable, since users are not expected to interact with the browser.
  • An info bar is shown to notify the user that the browser is being controlled by automation.
  • The window decoration is orange to make it even clearer that the browser is running in automation mode.

So, how can I write tests to be run in Epiphany? First, you need to install a recently enough selenium. For now, only the python API is supported. Selenium doesn’t have an Epiphany driver, but the WebKitGTK driver can be used with any WebKitGTK+ based browser, by providing the browser information as part of session capabilities.

from selenium import webdriver

options = webdriver.WebKitGTKOptions()
options.binary_location = 'epiphany'
options.add_argument('--automation-mode')
options.set_capability('browserName', 'Epiphany')
options.set_capability('version', '3.31.4')

ephy = webdriver.WebKitGTK(options=options, desired_capabilities={})
ephy.get('http://www.webkitgtk.org')
ephy.quit()

This is a very simple example that just opens Epiphany in automation mode, loads http://www.webkitgtk.org and closes Epiphany. A few comments about the example:

  • Version 3.31.4 will be the first one including the automation mode.
  • The parameter desired_capabilities shouldn’t be needed, but there’s a bug in selenium that has been fixed very recently.
  • WebKitGTKOptions.set_capability was added in selenium 3.14, if you have an older version you can use the following snippet instead
from selenium import webdriver

options = webdriver.WebKitGTKOptions()
options.binary_location = 'epiphany'
options.add_argument('--automation-mode')
capabilities = options.to_capabilities()
capabilities['browserName'] = 'Epiphany'
capabilities['version'] = '3.31.4'

ephy = webdriver.WebKitGTK(desired_capabilities=capabilities)
ephy.get('http://www.webkitgtk.org')
ephy.quit()

To simplify the driver instantation you can create your own Epiphany driver derived from the WebKitGTK one:

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.31.4')

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

ephy = Epiphany()
ephy.get('http://www.webkitgtk.org')
ephy.quit()

The same for selenium < 3.14

from selenium import webdriver

class Epiphany(webdriver.WebKitGTK):
    def __init__(self):
        options = webdriver.WebKitGTKOptions()
        options.binary_location = 'epiphany'
        options.add_argument('--automation-mode')
        capabilities = options.to_capabilities()
        capabilities['browserName'] = 'Epiphany'
        capabilities['version'] = '3.31.4'

        webdriver.WebKitGTK.__init__(self, desired_capabilities=capabilities)

ephy = Epiphany()
ephy.get('http://www.webkitgtk.org')
ephy.quit()

6 comments

    • You can run the WebDriver process in the remote box, using –port and –host command line parameters. Then in the local side you can use webdriver.remote.webdriver.WebDriver() passing command_executor=’host:ip’ and options=the ephy WebKitGTK options

      • Thank you for replying so fast!
        Ok, interesting, I must be doing something wrong.

        I’m basically trying this (python 3, selenium 3.141.56)

        options = webdriver.WebKitGTKOptions()
        options.binary_location = ‘epiphany’
        options.add_argument(‘–automation-mode’)
        options.set_capability(‘browserName’, ‘Epiphany’)
        options.set_capability(‘version’, ‘3.32.3’)
        browser = webdriver.Remote(command_executor=selenium_server_url,
        options=options, desired_capabilities={})

        However the selenium server on the host cannot spawn a session.

        Any ideas?

        Thanks again for replying and all the help!

        • Does it work locally? It’s failing for me even locally, I think we are failing to start ephy in automation mode from the driver, because I see error tabs in my main ephy instance. I’ll investigate. Thanks!

          • Thank you very much! Please do let me know how you get on.

            Locally for me it works fine, the below code spawns a session for me (when running locally).

            options = webdriver.WebKitGTKOptions()
            options.binary_location = ‘epiphany’
            options.add_argument(‘–automation-mode’)
            options.set_capability(‘browserName’, ‘Epiphany’)
            options.set_capability(‘version’, ‘3.32.3’)
            browser = webdriver.WebKitGTK(options=options, desired_capabilities={})

            Thought I’d also mention this in case you weren’t already aware.
            If I try and full screen the browser window the session won’t start for me at all, for example using any of the below:

            .fullscreen_window()
            .maximize_window()
            I even tried the –Kiosk mode from Chrome

            Cheers!
            David

          • It’s indeed working for me. This is what I’m doing to test it locally:

            1- Run the server in localhost with a port

            WebKitWebDriver --host=127.0.0.1 --port=4444
            

            2- Run the following script:

            import sys
            from selenium import webdriver
            
            class RemoteEpiphany(webdriver.Remote):
                def __init__(self, url):
                    options = webdriver.WebKitGTKOptions()
                    options.binary_location = 'epiphany'
                    options.add_argument('--automation-mode')
                    options.set_capability('browserName', 'Epiphany')
                    options.set_capability('version', '3.31.1')
            
                    webdriver.Remote.__init__(self, command_executor=url, options=options, desired_capabilities={})
            
            ephy = RemoteEpiphany(sys.argv[1])
            ephy.get('http://www.google.com')
            ephy.quit()
            

            Passing 127.0.0.1:4444 as only argument

Leave a Reply

Your email address will not be published. Required fields are marked *

*