POM Documentation Release 1.0.2 Sergei Chipiga September 23, 2016
Contents 1 Annotation 1 2 Architecture 3 3 How to start 5 4 Supported components 7 4.1 App (base application class)....................................... 7 4.2 Page (base page class).......................................... 7 4.3 UI (base element class).......................................... 7 4.4 Button.................................................. 8 4.5 CheckBox................................................ 8 4.6 ComboBox................................................ 9 4.7 TextField................................................. 9 4.8 IntegerField................................................ 9 4.9 FileField................................................. 9 4.10 Form................................................... 9 4.11 Link.................................................... 9 4.12 List.................................................... 10 4.13 Table................................................... 10 4.14 Row.................................................... 10 4.15 Header.................................................. 10 4.16 Body................................................... 10 4.17 Footer................................................... 11 i
ii
CHAPTER 1 Annotation POM is Page-Object-Model microframework to develop web UI tests easy, quickly and with pleasure. 1
POM Documentation, Release 1.0.2 2 Chapter 1. Annotation
CHAPTER 2 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. 3
POM Documentation, Release 1.0.2 4 Chapter 2. Architecture
CHAPTER 3 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') 5
POM Documentation, Release 1.0.2 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. 6 Chapter 3. How to start
CHAPTER 4 Supported components 4.1 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. 4.2 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. 4.3 UI (base element class) class pom.ui.base.ui(*locator, **index) Base class of ui element. 7
POM Documentation, Release 1.0.2 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. 4.4 Button class pom.ui.button.button(*locator, **index) Button. 4.5 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. 8 Chapter 4. Supported components
POM Documentation, Release 1.0.2 4.6 ComboBox class pom.ui.combobox.combobox(*locator, **index) Combobox. value Combobox value. values Combobox values. 4.7 TextField class pom.ui.fields.textfield(*locator, **index) Text field. value Value of text field. 4.8 IntegerField class pom.ui.fields.integerfield(*locator, **index) Integer field. value Value of integer field. 4.9 FileField class pom.ui.fields.filefield(*locator, **index) File field. value Value of text field. 4.10 Form class pom.ui.form.form(*locator, **index) Form. submit(*args, **kwgs) Submit form. 4.11 Link class pom.ui.link.link(*locator, **index) Link. 4.6. ComboBox 9
POM Documentation, Release 1.0.2 href URL of link. 4.12 List class pom.ui.table.list(*locator, **index) List. row(content) Get row of table. row_cls alias of Row 4.13 Table class pom.ui.table.table(*locator, **index) Table. row(**kwgs) Get row of table. row_cls alias of Row rows Table rows. 4.14 Row class pom.ui.table.row(*locator, **index) Row of table. cell_cls alias of Block 4.15 Header class pom.ui.table.header(*locator, **index) Header of table. cell_cls alias of Block 4.16 Body class pom.ui.table.body(*locator, **index) Table body. 10 Chapter 4. Supported components
POM Documentation, Release 1.0.2 columns Table columns. row(**kwgs) Get row of table. row_cls Row table class. row_xpath Row xpath. 4.17 Footer class pom.ui.table.footer(*locator, **index) Table footer. 4.17. Footer 11
POM Documentation, Release 1.0.2 12 Chapter 4. Supported components
Index A App (class in pom.base), 7 B back() (pom.base.page method), 7 Body (class in pom.ui.table), 10 Button (class in pom.ui.button), 8 C cell_cls (pom.ui.table.header attribute), 10 cell_cls (pom.ui.table.row attribute), 10 CheckBox (class in pom.ui.checkbox), 8 click() (pom.ui.base.ui method), 7 clone() (pom.ui.base.ui method), 8 columns (pom.ui.table.body attribute), 10 ComboBox (class in pom.ui.combobox), 9 current_page (pom.base.app attribute), 7 D double_click() (pom.ui.base.ui method), 8 F FileField (class in pom.ui.fields), 9 Footer (class in pom.ui.table), 11 Form (class in pom.ui.form), 9 forward() (pom.base.page method), 7 G get_attribute() (pom.ui.base.ui method), 8 H Header (class in pom.ui.table), 10 href (pom.ui.link.link attribute), 9 I IntegerField (class in pom.ui.fields), 9 is_enabled (pom.ui.base.ui attribute), 8 is_present (pom.ui.base.ui attribute), 8 is_selected (pom.ui.checkbox.checkbox attribute), 8 L Link (class in pom.ui.link), 9 List (class in pom.ui.table), 10 O open() (pom.base.app method), 7 open() (pom.base.page method), 7 P Page (class in pom.base), 7 Q quit() (pom.base.app method), 7 R refresh() (pom.base.page method), 7 right_click() (pom.ui.base.ui method), 8 Row (class in pom.ui.table), 10 row() (pom.ui.table.body method), 11 row() (pom.ui.table.list method), 10 row() (pom.ui.table.table method), 10 row_cls (pom.ui.table.body attribute), 11 row_cls (pom.ui.table.list attribute), 10 row_cls (pom.ui.table.table attribute), 10 row_xpath (pom.ui.table.body attribute), 11 rows (pom.ui.table.table attribute), 10 S select() (pom.ui.checkbox.checkbox method), 8 submit() (pom.ui.form.form method), 9 T Table (class in pom.ui.table), 10 TextField (class in pom.ui.fields), 9 U UI (class in pom.ui.base), 7 unselect() (pom.ui.checkbox.checkbox method), 8 13
POM Documentation, Release 1.0.2 V value (pom.ui.base.ui attribute), 8 value (pom.ui.combobox.combobox attribute), 9 value (pom.ui.fields.filefield attribute), 9 value (pom.ui.fields.integerfield attribute), 9 value (pom.ui.fields.textfield attribute), 9 values (pom.ui.combobox.combobox attribute), 9 W wait_for_absence() (pom.ui.base.ui method), 8 wait_for_presence() (pom.ui.base.ui method), 8 webdriver (pom.ui.base.ui attribute), 8 webelement (pom.ui.base.ui attribute), 8 14 Index