skip to navigation
skip to content

Not Logged In

holmium.core 0.6.2

selenium page objects and other utilities for test creation

Latest Version: 0.7.8



holmium.core provides utilities for simplifying the creation and maintenance of tests that rely on Selenium.

Nothing beats an example. Conventionally automated tests integrating with python-selenium are written similarly to the following code block (using

import selenium.webdriver
import unittest

class SeleniumHQTest(unittest.TestCase):
    def setUp(self):
        self.driver = selenium.webdriver.Firefox()
        self.url = ""

    def test_header_links(self):
        elements = self.driver.find_elements_by_css_selector("div#header ul>li")
        self.assertTrue(len(elements) > 0)
        for element in elements:
        expected_link_list = ["Projects", "Download", "Documentation",
                              "Support", "About"]
        actual_link_list = [el.text for el in elements]
        self.assertEquals(sorted(expected_link_list), sorted(actual_link_list))

    def test_about_selenium_heading(self):
        about_link = self.driver.find_element_by_css_selector(
            "div#header ul>li#menu_about>a"
        heading = self.driver.find_element_by_css_selector("#mainContent>h2")
        self.assertEquals(heading.text, "About Selenium")

    def tearDown(self):
        if self.driver:

if __name__ == "__main__":

The above example does what most selenium tests do:

  • initialize a webdriver upon setUp
  • query for one or more web elements using either class name, id, css_selector or xpath
  • assert on the number of occurrences / value of certain elements.
  • tear down the webdriver after each test case

It suffers from the typical web development problem of coupling the test case with the HTML plumbing of the page its testing rather than the functionality its meant to exercise. The concept of PageObjects reduces this coupling and allow for test authors to separate the layout of the page under test and the functional behavior being tested. This separation also results in more maintainable test code (i.e. if an element name changes - all tests don’t have to be updated, just the PageObject).

Lets take the above test case for a spin with holmium. Take note of the following:

  • The initialization and reset of the webdriver is delegated to the TestCase base class (alternatively the class could subclass unittest.TestCase and be run with the holmium nose plugin).
  • the page elements are accessed in the test only via Element & ElementMap.
from holmium.core import TestCase, Page, Element, Locators, ElementMap
import unittest

class SeleniumHQPage(Page):
    nav_links = ElementMap(Locators.CSS_SELECTOR
        , "div#header ul>li"
        , key=lambda element: element.find_element_by_tag_name("a").text
        , value=lambda element: element.find_element_by_tag_name("a")

    header_text = Element(Locators.CSS_SELECTOR, "#mainContent>h2")

class SeleniumHQTest(TestCase):
    def setUp(self): = SeleniumHQPage(self.driver, "")

    def test_header_links(self):
        self.assertTrue(len( > 0)
                ["Projects", "Download", "Documentation", "Support", "About"]
            , sorted(

    def test_about_selenium_heading(self):["About"].click()
        self.assertElementTextEqual(, "About Selenium")

if __name__ == "__main__":

Which can then be executed in a few different ways as shown below.

# if using TestCase as the base class run as:
HO_BROWSER=firefox nosetests
# or..
HO_BROWSER=firefox python
# if using unittest.TestCase as the base class run as:
nosetests --with-holmium --holmium-browser=firefox

Feature Summary

  • Automatic provisioning and configuration of webdriver instances based either on environment variables or nosetest arguments. (Unit test integration)
  • Shorthand assertions for web pages (TestCase)
  • Declarative model for defining pages, sections, page elements and element collections (Page Objects)
  • Built in cucumber step definitions for accessing and navigating pages (Cucumber Features)


0.6.2 2014-01-15

0.6.1 2013-12-23

  • Bug fix issue 18 for facet clobbering when page inheritance was involved
  • Bug fix issue 17 for case of no browser specified
  • new assertion for TestCase class : assertElementAttributeEqual

0.6 2013-12-14

  • Lazy driver initialization. The webdriver is created when the test first accesses it.
  • Support for using multiple browsers (drivers) in test cases. The original self.driver is still available along with a self.drivers list which lazily initializes new drivers as they are accessed via index. drivers[0] == driver.
  • New environment variable / nose option to force browser(s) to be shutdown and restarted between tests. (it is disabled by default, but cookies are still always cleared between tests)
  • New assertions added to the TestCase base class
  • Documentation cleanups
  • Bug fixes for default timeout/only_if arugment for Element/Elements/ElementMap

0.5.2 2013-12-09

  • PyPy support
  • Allow customization of WebElements by exposing ElementEnhancer

0.5.1 2013-12-01

  • Re-added python 2.6 support

0.5.0 2013-12-01

  • Python 3.3 now supported and tested.

0.4.2 2013-12-01

  • New parameter only_if (callable that accepts the webelement that was found) accepted by Element, Elements, ElementMap that allows for waiting for an element to become valid according to the response of only_if. The callable will be checked uptil the timeout parameter set on the Element.

0.4.1 2013-11-29

  • Bug fix for config module being reused between test runs.

0.4 2013-11-28

0.3.4 2013-11-21

  • Added support to ignore ssl certificate errors on chrome, firefox & phantomjs
  • code cleanup
  • improved test coverage

0.3.3 2013-10-29

  • Improved back reference access in Config object by allowing variable references without requiring a prefix of default or the environment name. The resolution order is current environment and then default.

    For example, the following config will resolve login_url as and profile_url as respectively, when holmium.environment is set to production

    config = { "default" : {
                    "login_url" : "{{url}}/login"
                    , "profile_url":"{{url}}/profiles/{{username}}"}
              , "production": {
                    "url": ""
                    , "username":"prod_user"}

0.3.2 2013-10-10

  • Fluent response from page objects only when page method returns None

0.3.1 2013-09-17

  • Allow indexing of Sections objects

0.3 2013-09-16

0.2 2013-09-11 2013-09-04

  • Bug Fix : installation via pip was failing due to missing HISTORY.rst file. 2013-08-12

  • Bug fix
    • improved error handling and logging for missing/malformed config file.

0.1.8 2013-03-18

  • Added iphone/android/phantomjs to supported browsers
  • Bug fix
    • fixed phantomjs build in travis
File Type Py Version Uploaded on Size
holmium.core-0.6.2-py2.7.egg (md5) Python Egg 2.7 2014-01-15 299KB
holmium.core-0.6.2.tar.gz (md5) Source 2014-01-15 264KB
  • Downloads (All Versions):
  • 320 downloads in the last day
  • 1313 downloads in the last week
  • 4740 downloads in the last month