Skip to main content
.. _PageObjects: http://code.google.com/p/selenium/wiki/PageObjects
.. |travis-ci| image:: https://secure.travis-ci.org/alisaifee/holmium.core.png
:target: https://travis-ci.org/#!/alisaifee/holmium.core
.. |coverall| image:: https://coveralls.io/repos/alisaifee/holmium.core/badge.png?branch=master
:target: https://coveralls.io/r/alisaifee/holmium.core

holmium.core |travis-ci| |coverall|
-----------------------------------

Introduction
============
holmium.core provides utility classes to simplify writing pageobjects for webpages using selenium.

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

.. code-block:: python

import selenium.webdriver
import unittest

class SeleniumHQTest(unittest.TestCase):
def setUp(self):
self.driver = selenium.webdriver.Firefox()
self.url = "http://seleniumhq.org"
def test_header_links(self):
self.driver.get(self.url)
elements = self.driver.find_elements_by_css_selector("div#header ul>li")
self.assertTrue(len(elements) > 0)
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):
self.driver.get(self.url)
about_link = self.driver.find_element_by_css_selector("div#header ul>li#menu_about>a")
about_link.click()
heading = self.driver.find_element_by_css_selector("#mainContent>h2")
self.assertEquals(heading.text, "About Selenium")

def tearDown(self):
if self.driver:
self.driver.quit()

if __name__ == "__main__":
unittest.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 occurances / 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 excercise.
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 dont 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 HolmiumTestCase 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 PageElement & PageElementMap.


.. code-block:: python

from holmium.core import HolmiumTestCase, PageObject, PageElement, Locators, PageElementMap
import unittest

class SeleniumHQPage(PageObject):
nav_links = PageElementMap( 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 = PageElement(Locators.CSS_SELECTOR, "#mainContent>h2")


class SeleniumHQTest(HolmiumTestCase):
def setUp(self):
self.page = SeleniumHQPage(self.driver, "http://seleniumhq.org")

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

def test_about_selenium_heading(self):
self.page.nav_links["About"].click()
self.assertEquals(self.page.header_text.text, "About Selenium")

if __name__ == "__main__":
unittest.main()

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

.. code-block:: bash

# if using HolmiumTestCase as the base class run as:
export HO_BROWSER=firefox;nosetests test_selenium_hq.py
# or..
export HO_BROWSER=firefox;python test_selenium_hq.py
# if using unittest.TestCase as the base class run as:
nosetests test_selenium_hq.py --holmium-browser=firefox



.. :changelog:

History
-------

0.1.8.2 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

Metadata

Release files for holmium.core 0.1.8.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for holmium.core 0.1.8.2
File Size Uploaded
holmium.core-0.1.8.2.tar.gz 49.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for holmium.core 0.1.8.2
File Interpreter ABI Platform
holmium.core-0.1.8.2-py2.7.egg Legacy Egg format - - Details

Total release size: 84.5 kB

Release files / holmium.core-0.1.8.2.tar.gz

Download URL holmium.core-0.1.8.2.tar.gz
Size 49.3 kB
Tags Source
SHA-256 checksum
How to use checksums
be8f71a35d5916c8e270fcfa45f58a4bd439ae223f254094f15e7ed5857103ed
BLAKE2b-256 checksum
How to use checksums
d4e1a3113c8c17c4265c29d309c1ddbd3a1762d291b0758eb156815133e216a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / holmium.core-0.1.8.2-py2.7.egg

Download URL holmium.core-0.1.8.2-py2.7.egg
Size 35.2 kB
Tags Egg
SHA-256 checksum
How to use checksums
8236d4f5c77ce572dabe25215759cbe99e82acee09b62ad3993fe99d031b3556
BLAKE2b-256 checksum
How to use checksums
e05c37030bfac4c122d999243950ab0a80490facd56b319daef06db2397f0e1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.1.0

2 release files

1.0.0

3 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8

2 release files

0.7.9

2 release files

0.7.8

2 release files

0.7.7

2 release files

0.7.6

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3

2 release files

0.2

2 release files

This release

0.1.8.2 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page