Welcome to POM’s documentation!

Annotation

POM is Page-Object-Model microframework to develop web UI tests easy, quickly and with pleasure.

Architecture

POM provides API to manipulate with web UI elements and pages in browser. Under hood it uses selenium. Before to act with UI element POM waits for its visibility, because in user cases user can’t interact with UI element if it isn’t visible at display. POM provides tree hirarchy to request UI elements with UI caching mechanism at each level.

POM doesn’t use implicit_wait method to wait UI element, because implicit_wait waits until element is present at DOM even if it isn’t visible. And also implicit_wait has conflict with caching mechanism, that leads to long requests in some cases.

So POM has own implementation to wait element before interact. It leads to additinal webdriver request before interact with UI element, but provide reliable and simple architecture, without speed degradation.

How to start

Let imagine simple testcase:

  • Go to https://facebook.com
  • Fill login / password fields with 'admin' / 'admin' values
  • Click button login
  • Assert page to log in is opened
  • Assert alert message is opened

Its implementation with POM:

import unittest

import pom
from pom import ui
from selenium.webdriver.common.by import By


@ui.register_ui(field_login=ui.TextField(By.NAME, 'email'),
                field_password=ui.TextField(By.NAME, 'pass'))
class FormLogin(ui.Form):
    """Form to login."""


@ui.register_ui(form_login=FormLogin(By.ID, 'login_form'))
class PageMain(pom.Page):
    """Main page."""
    url = '/'


@ui.register_ui(
    alert_message=ui.Block(By.CSS_SELECTOR, 'div.uiContextualLayerPositioner'))
class PageLogin(pom.Page):
    """Login page."""
    url = '/login'


@pom.register_pages([PageMain, PageLogin])
class Facebook(pom.App):
    """Facebook web application."""
    def __init__(self):
        super(Facebook, self).__init__('https://www.facebook.com', 'firefox')
        self.webdriver.maximize_window()
        self.webdriver.set_page_load_timeout(30)


class TestCase(unittest.TestCase):

    def setUp(self):
        self.fb = Facebook()
        self.addCleanup(self.fb.quit)

    def test_facebook_invalid_login(self):
        """User with invalid credentials can't login to facebook."""
        self.fb.page_main.open()
        with self.fb.page_main.form_login as form:
            form.field_login.value = 'admin'
            form.field_password.value = 'admin'
            form.submit()
        assert self.fb.current_page == self.fb.page_login
        assert self.fb.page_login.alert_message.is_present

To launch example:

  • Save example code in file test_pom.py
  • Install POM framework pip install python-pom
  • Launch test example python -m unittest test_pom

Full example of usage is in https://github.com/sergeychipiga/horizon_autotests.

Supported components

App (base application class)

class pom.base.App(url, browser, *args, **kwgs)

Web application.

current_page

Define current page

open(url)

Open url.

Arguments:
  • url: string.
quit()

Close browser.

Page (base page class)

class pom.base.Page(app)

Page of web application.

back(*args, **kwgs)

Back.

forward(*args, **kwgs)

Forward.

open(*args, **kwgs)

Open page.

refresh(*args, **kwgs)

Refresh page.

UI (base element class)

class pom.ui.base.UI(*locator, **index)

Base class of ui element.

click(*args, **kwgs)

Click ui element.

clone()

Clone ui element.

double_click(*args, **kwgs)

Double click ui element.

get_attribute(*args, **kwgs)

Get attribute of ui element.

is_enabled

Define is ui element enabled.

is_present

Define is ui element present at display.

right_click(*args, **kwgs)

Right click ui element.

value

Get value of ui element.

wait_for_absence(*args, **kwgs)

Wait for ui element absence.

wait_for_presence(*args, **kwgs)

Wait for ui element presence.

webdriver

Get webdriver.

webelement

Get webelement.

Button

class pom.ui.button.Button(*locator, **index)

Button.

CheckBox

class pom.ui.checkbox.CheckBox(*locator, **index)

Checkbox.

is_selected

Define is checkbox selected.

select(*args, **kwgs)

Select checkbox if it isn’t selected.

unselect(*args, **kwgs)

Unselect checkbox if it is selected.

ComboBox

class pom.ui.combobox.ComboBox(*locator, **index)

Combobox.

value

Combobox value.

values

Combobox values.

TextField

class pom.ui.fields.TextField(*locator, **index)

Text field.

value

Value of text field.

IntegerField

class pom.ui.fields.IntegerField(*locator, **index)

Integer field.

value

Value of integer field.

FileField

class pom.ui.fields.FileField(*locator, **index)

File field.

value

Value of text field.

Form

class pom.ui.form.Form(*locator, **index)

Form.

submit(*args, **kwgs)

Submit form.

List

class pom.ui.table.List(*locator, **index)

List.

row(content)

Get row of table.

row_cls

alias of Row

Table

class pom.ui.table.Table(*locator, **index)

Table.

row(**kwgs)

Get row of table.

row_cls

alias of Row

rows

Table rows.

Row

class pom.ui.table.Row(*locator, **index)

Row of table.

cell_cls

alias of Block

Body

class pom.ui.table.Body(*locator, **index)

Table body.

columns

Table columns.

row(**kwgs)

Get row of table.

row_cls

Row table class.

row_xpath

Row xpath.