Holmium core is nose plugin that provides utilities for simplifying the creation and maintenance of tests that rely on Selenium. Holmium introduce concept of Page Objects reduces the coupling and allow test authors to separate the layout of the page under test and the functional behaviour being tested.This separation also results in more maintainable test code.
Check out Getting Started with Selenium Python – Part 1
Installation of the Holmium:
Assuming you have Nose module installed on the Machine. If not check out my Nose installation post.
1 | pip install holmium.core |
Importing Holmium in Project:
First you have to Import the the TestCase, Page , Element and Locators.
1 2 | from holmium.core import TestCase, Page, Element, Locators, ElementMap import unittest |
Adding Test Cases:
Lets add Login Test Cases into the project with the Login functionality. Create a class LoginPage ( A Page object class) with inherit the Page of the Holmium.core and will be used to get the elements on the that page and sending keys to them.
1 2 3 4 5 6 7 8 | class LoginPage(Page): userNameText = Element(Locators.NAME, 'userName') passwordText = Element(Locators.NAME, 'password') submitButton = Element(Locators.NAME, 'login')</pre> def login(self): self.userNameText.send_keys("techdutta") self.passwordText.send_keys("test123") self.submitButton.submit() |
Lets add another class LoginTest which inherit the Test Case from the Holmium.core and only be used to assert the desired functionality.
1 2 3 4 5 6 7 8 9 10 11 12 | class LoginTest(TestCase): def setUp(self): self.page = LoginPage(self.driver, "http://demoaut.com/") def test_Login(self): self.page.login() self.assertEqual(self.driver.title, "Find a Flight: Mercury Tours:") def tearDown(self): self.driver.close() |
Running the Code with the nose:
Final code with Running Test results.