cfme.web_ui package¶
Submodules¶
Module contents¶
Provides a number of objects to help with managing certain elements in the CFME UI.
Specifically there are two categories of objects, organizational and elemental.
- Organizational
Region
cfme.web_ui.menu
- Elemental
AngularCalendarInput
AngularSelect
Calendar
CheckboxTable
DriftGrid
Form
InfoBlock
Input
MultiFill
Select
StatusBox
Table
Tree
cfme.web_ui.accordion
cfme.web_ui.cfme_exception
cfme.web_ui.expression_editor
cfme.web_ui.flash
cfme.web_ui.form_buttons
cfme.web_ui.jstimelines
cfme.web_ui.listaccordion
cfme.web_ui.menu
cfme.web_ui.mixins
cfme.web_ui.paginator
cfme.web_ui.search
cfme.web_ui.tabstrip
cfme.web_ui.toolbar
-
class
cfme.web_ui.
AngularCalendarInput
(input_name, click_away_element)[source]¶ Bases:
cfme.utils.pretty.Pretty
-
input
¶
-
pretty_attrs
= ('input_name', 'click_away_element')¶
-
-
class
cfme.web_ui.
AngularSelect
(loc, none=None, multi=False, exact=False)[source]¶ Bases:
cfme.utils.pretty.Pretty
-
BUTTON
= "//button[@data-id='{}']"¶
-
all_options
¶
-
classes
¶ Combines class from the button and from select.
-
did
¶
-
first_selected_option
¶
-
first_selected_option_text
¶
-
is_broken
¶
-
is_open
¶
-
options
¶
-
pretty_attrs
= ['_loc', 'none', 'multi', 'exact']¶
-
select
¶
-
-
class
cfme.web_ui.
BootstrapTreeview
(tree_id)[source]¶ Bases:
object
A class representing the Bootstrap treeview used in newer builds.
Implements
expand_path
,click_path
,read_contents
. All are implemented in manner very similar to the originalTree
.Parameters: tree_id – Id of the tree, the closest div to the root ul
element.-
CHILD_ITEMS
= './ul/li[starts-with(@data-nodeid, {id}) and count(./span[contains(@class, "indent")])={indent}]'¶
-
CHILD_ITEMS_TEXT
= './ul/li[starts-with(@data-nodeid, {id}) and contains(normalize-space(.), {text}) and count(./span[contains(@class, "indent")])={indent}]'¶
-
INDENT
= './span[contains(@class, "indent")]'¶
-
IS_CHECKABLE
= './span[contains(@class, "check-icon")]'¶
-
IS_CHECKED
= './span[contains(@class, "check-icon") and contains(@class, "fa-check-square-o")]'¶
-
IS_EXPANDABLE
= './span[contains(@class, "expand-icon")]'¶
-
IS_EXPANDED
= './span[contains(@class, "expand-icon") and contains(@class, "fa-angle-down")]'¶
-
IS_LOADING
= './span[contains(@class, "expand-icon") and contains(@class, "fa-spinner")]'¶
-
ITEM_BY_NODEID
= './ul/li[@data-nodeid={}]'¶
-
ROOT_ITEMS
= './ul/li[not(./span[contains(@class, "indent")])]'¶
-
ROOT_ITEMS_WITH_TEXT
= './ul/li[not(./span[contains(@class, "indent")]) and contains(normalize-space(.), {text})]'¶
-
SELECTED_ITEM
= './ul/li[contains(@class, "node-selected")]'¶
-
check_node
(*path, **kwargs)[source]¶ Expands the passed path and checks a checkbox that is located at the node.
-
click_path
(*path, **kwargs)[source]¶ Expands the path and clicks the leaf node.
See
expand_path()
for more informations about synopsis.
-
collapse_node
(nodeid)[source]¶ Collapses a node given its nodeid. Must be visible
Parameters: nodeid – nodeId
of the nodeReturns: True
if it was possible to expand the node, otherwiseFalse
.
-
expand_node
(nodeid)[source]¶ Expands a node given its nodeid. Must be visible
Parameters: nodeid – nodeId
of the nodeReturns: True
if it was possible to expand the node, otherwiseFalse
.
-
expand_path
(*path, **kwargs)[source]¶ Expands given path and returns the leaf node.
The path items can be plain strings. In that case, exact string matching happens. Path items can also be compiled regexps, where the
match
method is used to determine if the node is the one we want. And finally, the path items can be 2-tuples, where the second item can be the string or regular expression and the first item is the image to be matched usingimage_getter()
method.Parameters: *path – The path (explained above) Returns: The leaf WebElement. Raises: exceptions.CandidateNotFound
when the node is not found in the tree.
-
find_path_to
(target, exact=False)[source]¶ Method used to look up the exact path to an item we know only by its regexp or partial description.
Expands whole tree during the execution.
Parameters: - target – Item searched for. Can be regexp made by
re.compile
, otherwise it is taken as a string for in matching. - exact – Useful in string matching. If set to True, it matches the exact string. Default is False.
Returns:
list
with path to that item.- target – Item searched for. Can be regexp made by
-
classmethod
image_getter
(item)[source]¶ Look up the image that is hidden in the style tag
Returns: The name of the image without the hash, path and extension.
-
selected_item
¶
-
-
class
cfme.web_ui.
CachedTableHeaders
(table)[source]¶ Bases:
object
the internal cache of headers
This allows columns to be moved and the Table updated. The
headers
stores the header cache element and the list of headers are stored in _headers. The attribute header_indexes is then created, before finally creating the items attribute.
-
class
cfme.web_ui.
Calendar
(name)[source]¶ Bases:
cfme.utils.pretty.Pretty
A CFME calendar form field
Calendar fields are readonly, and managed by the dxhtmlCalendar widget. A Calendar field will accept any object that can be coerced into a string, but the value may not match the format expected by dhtmlxCalendar or CFME. For best results, either a
datetime.date
ordatetime.datetime
object should be used to create a valid date field.Parameters: name – “name” property of the readonly calendar field. Usage:
calendar = web_ui.Calendar("miq_date_1") web_ui.fill(calendar, date(2000, 1, 1)) web_ui.fill(calendar, '1/1/2001')
-
class
cfme.web_ui.
CheckboxTable
(table_locator, header_offset=0, body_offset=0, header_checkbox_locator=None, body_checkbox_locator=None)[source]¶ Bases:
cfme.web_ui.Table
Table
with support for checkboxesParameters: - table_locator – See
cfme.web_ui.Table
- header_checkbox_locator – Locator of header checkbox (default None) Specify in case the header checkbox is not part of the header row
- body_checkbox_locator – Locator for checkboxes in body rows
- header_offset – See
cfme.web_ui.Table
- body_offset – See
cfme.web_ui.Table
-
deselect_row
(header, value)[source]¶ Deselect a single row specified by column header and cell value
Parameters: - header – See
Table.find_row()
- value – See
Table.find_row()
Returns: True if successful, False otherwise
- header – See
-
deselect_row_by_cells
(cells, partial_check=False)[source]¶ Deselect the first row matched by
cells
Parameters: cells – See Table.find_rows_by_cells()
-
deselect_rows
(cell_map)[source]¶ Deselect multiple rows
Parameters: cell_map – See Table.click_cells()
Raises: NotAllCheckboxesFound
– If some cells were unable to be found
-
deselect_rows_by_cells
(cells, partial_check=False)[source]¶ Deselect the rows matched by
cells
Parameters: cells – See Table.find_rows_by_cells()
-
deselect_rows_by_indexes
(*indexes)[source]¶ Deselect rows specified by row indexes (starting with 0)
-
header_checkbox
¶ Checkbox used to select/deselect all rows
-
select_row
(header, value)[source]¶ Select a single row specified by column header and cell value
Parameters: - header – See
Table.find_row()
- value – See
Table.find_row()
Returns: True if successful, False otherwise
- header – See
-
select_row_by_cells
(cells, partial_check=False)[source]¶ Select the first row matched by
cells
Parameters: cells – See Table.find_rows_by_cells()
-
select_rows
(cell_map)[source]¶ Select multiple rows
Parameters: cell_map – See Table.click_cells()
Raises: NotAllCheckboxesFound
– If some cells were unable to be found
-
select_rows_by_cells
(cells, partial_check=False)[source]¶ Select the rows matched by
cells
Parameters: cells – See Table.find_rows_by_cells()
- table_locator – See
-
class
cfme.web_ui.
CheckboxTree
(locator)[source]¶ Bases:
cfme.web_ui.Tree
Tree that has a checkbox on each node, adds methods to check/uncheck them
-
check_node
(*path)[source]¶ Convenience function to check a node
Parameters: *path – The path as multiple positional string arguments denoting the course to take.
-
node_checkbox
= "../span[@class='dynatree-checkbox']"¶
-
-
class
cfme.web_ui.
DriftGrid
(loc="//div[@id='compare-grid']")[source]¶ Bases:
cfme.utils.pretty.Pretty
Class representing the table (grid) specific to host drift analysis comparison page
-
cell_indicates_change
(row_text, col_index)[source]¶ Finds out if a cell, specified by column index and row text, indicates change
Parameters: - row_text – Title text of the cell’s row
- col_index – Column index of the cell
Note
col_index of 0 is used for the 2nd actual column in the drift grid, because the 1st column does not contain headers, only row descriptions.
Returns: True
if there is a change present,False
otherwise
-
expand_all_sections
()[source]¶ Expands all sections to make the row elements found therein available
-
get_cell
(row_text, col_index)[source]¶ Finds cell element of the grid specified by column index and row text
Parameters: - row_text – Title text of the cell’s row
- col_index – Column index of the cell, starting with 0 for 1st data-containing column
Note
col_index of 0 is used for the 2nd actual column in the drift grid, because the 1st column does not contain headers, only row descriptions.
Returns: Selenium element of the cell.
-
-
class
cfme.web_ui.
Form
(fields=None, identifying_loc=None)[source]¶ Bases:
cfme.web_ui.Region
A class for interacting with Form elements on pages.
The Form class takes a set of locators and binds them together to create a unified Form object. This Form object has a defined field order so that the user does not have to worry about which order the information is provided. This enables the data to be provided as a dict meaning it can be passed directly from yamls. It inherits the base Region class, meaning that locators can still be referenced in the same way a Region’s locators can. You can also add one more field which will be a
dict
of metadata, determining mostly field validity. Seefield_valid()
Parameters: - fields – A list of field name/locator tuples. The argument not only defines the order of the elements but also which elements comprise part of the form.
- identifying_loc – A locator which should be present if the form is visible.
Usage:
provider_form = web_ui.Form( fields=[ ('type_select', "//*[@id='server_emstype']"), ('name_text', "//*[@id='name']"), ('hostname_text', "//*[@id='hostname']"), ('ipaddress_text', "//*[@id='ipaddress']"), ('amazon_region_select', "//*[@id='hostname']"), ('api_port', "//*[@id='port']"), ])
Forms can then be filled in like so.:
provider_info = { 'type_select': "OpenStack", 'name_text': "RHOS-01", 'hostname_text': "RHOS-01", 'ipaddress_text': "10.0.0.0", 'api_port': "5000", } web_ui.fill(provider_form, provider_info)
Note
Using supertuples in a list, although ordered due to the properties of a List, will not overide the field order defined in the Form.
-
pretty_attrs
= ['fields']¶
-
class
cfme.web_ui.
InfoBlock
(title)[source]¶ Bases:
cfme.utils.pretty.Pretty
-
DETAIL
= 'detail'¶
-
FORM
= 'form'¶
-
class
Member
(ib, name)[source]¶ Bases:
cfme.utils.pretty.Pretty
-
container
¶
-
element
¶
-
elements
¶
-
icon_href
¶
-
pair
¶
-
pair_locator
¶
-
pretty_attrs
= ('name', 'ib')¶
-
text
¶
-
title
¶
-
-
InfoBlock.
PF
= 'patternfly'¶
-
InfoBlock.
by_member_icon
(icon)[source]¶ In case you want to find the item by icon in the value field (like OS infra diff.)
-
InfoBlock.
pretty_attrs
= ['title']¶
-
InfoBlock.
root
¶
-
InfoBlock.
type
¶
-
-
class
cfme.web_ui.
Input
(*names, **kwargs)[source]¶ Bases:
cfme.utils.pretty.Pretty
Class designed to handle things about
<input>
tags that have name attr in one place.Also applies on
textarea
, which is basically input with multiple lines (if it has name).Parameters: *names – Possible values (or) of the name
attribute.- Keywords:
- use_id: Whether to use
id
instead ofname
. Useful if there is some input that does - not have
name
attribute present.
- use_id: Whether to use
-
angular_help_block
¶ Returns the first visible angular helper text (like ‘Required’).
-
names
¶
-
pretty_attrs
= ['_names', '_use_id']¶
-
class
cfme.web_ui.
PagedTable
(table_locator, header_offset=0, body_offset=0, hidden_locator=None)[source]¶ Bases:
cfme.web_ui.Table
Table
with support for paginatorParameters: - table_locator – See
cfme.web_ui.Table
- header_checkbox_locator – Locator of header checkbox (default None) Specify in case the header checkbox is not part of the header row
- body_checkbox_locator – Locator for checkboxes in body rows
- header_offset – See
cfme.web_ui.Table
- body_offset – See
cfme.web_ui.Table
-
find_row_by_cell_on_all_pages
(cells)[source]¶ Find the first row containing cells on all pages
Parameters: cells – See Table.find_rows_by_cells()
Returns: The first matching row found on any page
- table_locator – See
-
class
cfme.web_ui.
Region
(locators=None, title=None, identifying_loc=None, **kwargs)[source]¶ Bases:
cfme.utils.pretty.Pretty
Base class for all UI regions/pages
Parameters: - locators – A dict of locator objects for the given region
- title – A string containing the title of the page, or a versioned dict of page title strings
- identifying_loc – Single locator key from locators used by
Region.is_displayed()
to check if the region is currently visible
Usage:
page = Region(locators={ 'configuration_button': (By.CSS_SELECTOR, "div.dhx_toolbar_btn[title='Configuration']"), 'discover_button': (By.CSS_SELECTOR, "tr[title='Discover Cloud Providers']>td.td_btn_txt>" "div.btn_sel_text") }, title='Cloud Providers', identifying_loc='discover_button' )
The elements can then accessed like so:
page.configuration_button
Locator attributes will return the locator tuple for that particular element, and can be passed on to other functions, such as
element()
andclick()
.Note
When specifying a region title, omit the “Cloudforms Management Engine: ” or “ManageIQ: ” prefix. They are included on every page, and different for the two versions of the appliance, and
is_displayed()
strips them off before checking for equality.-
is_displayed
()[source]¶ Checks to see if the region is currently displayed.
Returns: A boolean describing if the region is currently displayed
-
pretty_attrs
= ['title']¶
-
title
¶
-
class
cfme.web_ui.
Table
(table_locator, header_offset=0, body_offset=0, hidden_locator=None)[source]¶ Bases:
cfme.utils.pretty.Pretty
Helper class for Table/List objects
Turns CFME custom Table/Lists into iterable objects using a generator.
Parameters: - table_locator – locator pointing to a table element with child thead and tbody elements representing that table’s header and body row containers
- header_offset – In the case of a padding table row above the header, the row offset
can be used to skip rows in
<thead>
to locate the correct header row. This offset is 1-indexed, not 0-indexed, so an offset of 1 is the first child row element - body_offset – In the case of a padding table row above the body rows, the row offset
can be used to skip rows in
<ttbody>
to locate the correct header row. This offset is 1-indexed, not 0-indexed, so an offset of 1 is the first child row element - hidden_locator – If the table can disappear, you probably want ot set this param as it
instructs the table that if it cannot find the table on the page but the element
represented by
hidden_locator
is visible, it assumes no data and returns no rows.
-
header_indexes
¶ A dict of header names related to their int index as a column.
Usage:
table = Table('//div[@id="prov_pxe_img_div"]//table')
The HTML code for the table looks something like this:
<div id="prov_pxe_img_div"> <table> <thead> <tr> <th>Name</th> <th>Animal</th> <th>Size</th> </tr> </thead> <tbody> <tr> <td>John</td> <td>Monkey</td> <td>Small</td> </tr> <tr> <td>Mike</td> <td>Tiger</td> <td>Large</td> </tr> </tbody> </table> </div>
We can now click on an element in the list like so, by providing the column name and the value that we are searching for:
table.click_cell('name', 'Mike')
We can also perform the same, by using the index of the column, like so:
table.click_cell(1, 'Tiger')
Additionally, the rows of a table can be iterated over, and that row’s columns can be accessed by name or index (left to right, 0-index):
for row in table.rows() # Get the first cell in the row row[0] # Get the row's contents for the column with header 'Row Name' # All of these will work, though the first is preferred row.row_name, row['row_name'], row['Row Name']
When doing bulk opererations, such as selecting rows in a table based on their content, the
*_by_cells
methods are able to find matching row much more quickly than iterating, as the work can be done with fewer selenium calls.Note
A table is defined by the containers of the header and data areas, and offsets to them. This allows a table to include one or more padding rows above the header row. In the example above, there is no padding row, as our offset values are set to 0.
-
class
Row
(row_element, parent_table)[source]¶ Bases:
cfme.utils.pretty.Pretty
An object representing a row in a Table.
The Row object returns a dymanically addressable attribute space so that the tables headers are automatically generated.
Parameters: - row_element – A table row
WebElement
- parent_table –
Table
containingrow_element
Notes
Attributes are dynamically generated. The index/key accessor is more flexible than the attr accessor, as it can operate on int indices and header names.
-
columns
¶ A list of WebElements corresponding to the
<td>
elements in this row
-
pretty_attrs
= ['row_element', 'table']¶
- row_element – A table row
-
Table.
body
¶ Property representing the
<tbody>
element that contains body rows
-
Table.
click_cell
(header, value)[source]¶ Clicks on a cell defined in the row.
Uses the header identifier and a value to determine which cell to click on.
Parameters: - header – A string or int, describing which column to inspect.
- value – The value to be compared when trying to identify the correct cell to click the cell in.
Returns:
True
if item was found and clicked, elseFalse
.
-
Table.
click_cells
(cell_map)[source]¶ Submits multiple cells to be clicked on
Parameters: cell_map – A mapping of header names and values, representing cells to click. As an example,
{'name': ['wing', 'nut']}, {'age': ['12']}
would click on the cells which hadwing
andnut
in the name column and12
in the age column. The yaml example for this would be as follows:list_items: name: - wing - nut age: - 12
Raises: NotAllItemsClicked
– If some cells were unable to be found.
-
Table.
click_row_by_cells
(cells, click_column=None, partial_check=False)[source]¶ Click the cell at
click_column
in the first row matched bycells
Parameters: - cells – See
Table.find_rows_by_cells()
- click_column – See
Table.click_rows_by_cells()
- cells – See
-
Table.
click_rows_by_cells
(cells, click_column=None, partial_check=False)[source]¶ Click the cell at
click_column
in the rows matched bycells
Parameters: - cells – See
Table.find_rows_by_cells()
- click_column – Which column in the row to click, defaults to None, which will attempt to click the row element
Note
The value of click_column can be a string or an int, and will be passed directly to the item accessor (
__getitem__
) forTable.Row
- cells – See
-
Table.
create_row_from_element
(row_element)[source]¶ Given a row element in this table, create a
Table.Row
Parameters: row_element – A table row ( <tr>
) WebElement representing a row in this table.Returns: A
Table.Row
forrow_element
-
Table.
find_cell
(header, value)[source]¶ Finds an item in the Table by iterating through each visible item, this work used to be done by the :py:meth::click_cell method but has not been abstracted out to be called separately.
Parameters: - header – A string or int, describing which column to inspect.
- value – The value to be compared when trying to identify the correct cell to click.
Returns: WebElement of the element if item was found, else
None
.
-
Table.
find_row
(header, value)[source]¶ Finds a row in the Table by iterating through each visible item.
Parameters: - header – A string or int, describing which column to inspect.
- value – The value to be compared when trying to identify the correct row to return.
Returns: Table.Row
containing the requested cell, elseNone
.
-
Table.
find_row_by_cells
(cells, partial_check=False)[source]¶ Find the first row containing cells
Parameters: cells – See Table.find_rows_by_cells()
Returns: The first matching row found, or None if no matching row was found
-
Table.
find_rows_by_cells
(cells, partial_check=False)[source]¶ A fast row finder, based on cell content.
If you pass a regexp as a value, then it will be used with its
.match()
method.Parameters: - cells – A dict of
header: value
pairs or a sequence of nested(header, value)
pairs. - partial_check – If to use the
in
operator rather than==
.
- Returns: A list of containing
Table.Row
objects whose contents - match all of the header: value pairs in
cells
- cells – A dict of
-
Table.
header_indexes
Dictionary of header name: column index for this table’s rows
Derived from
headers
-
Table.
header_row
¶ Property representing the
<tr>
element that contains header cells
-
Table.
headers
¶ List of
<td>
or<th>
elements inheader_row
-
Table.
pretty_attrs
= ['_loc']¶
-
class
cfme.web_ui.
Tree
(locator)[source]¶ Bases:
cfme.utils.pretty.Pretty
A class directed at CFME Tree elements
The Tree class aims to deal with all kinds of CFME trees
Parameters: locator – This is a locator object pointing to the <ul>
element which contains the rest of the table.Returns: A
Tree
object.A Tree object is set up by using a locator which contains the node elements. This element will usually be a
<ul>
in the case of a Dynatree.Usage:
tree = web_ui.Tree((By.XPATH, '//table//tr[@title="Datastore"]/../..'))
The path can then be navigated to return the last object in the path list, like so:
tree.click_path('Automation', 'VM Lifecycle Management (VMLifecycle)', 'VM Migrate (Migrate)')
Each path element will be expanded along the way, but will not be clicked.
When used in a
Form
, a list of path tuples is expected in the form fill data. The paths will be passed individually toTree.check_node()
:form = Form(fields=[ ('tree_field', List(locator)), ]) form_fill_data = { 'tree_field': [ ('Tree Node', 'Value'), ('Tree Node', 'Branch Node', 'Value'), ] ]
Note: Dynatrees, rely on a
<ul><li>
setup. We class a<li>
as a node.-
classmethod
browse
(tree, *path)[source]¶ Browse through tree via path.
If node not found, raises exception. If the browsing reached leaf(str), returns True if also the step was last, otherwise False. If the result of the path is a subtree, it is returned.
Parameters: - tree – List with tree.
- *path – Path to browse.
-
click_path
(*path, **kwargs)[source]¶ Exposes a path and then clicks it.
Parameters: *path – The path as multiple positional string arguments denoting the course to take. - Keywords:
- by_id: Whether to match ids instead of text.
Returns: The leaf web element.
-
expand_path
(*path, **kwargs)[source]¶ Exposes a path.
Parameters: *path – The path as multiple positional string arguments denoting the course to take. - Keywords:
- by_id: Whether to match ids instead of text.
Returns: The leaf web element.
-
find_path_to
(target, exact=False)[source]¶ Method used to look up the exact path to an item we know only by its regexp or partial description.
Expands whole tree during the execution.
Parameters: - target – Item searched for. Can be regexp made by
re.compile
, otherwise it is taken as a string for in matching. - exact – Useful in string matching. If set to True, it matches the exact string. Default is False.
Returns:
list
with path to that item.- target – Item searched for. Can be regexp made by
-
classmethod
flatten_level
(tree)[source]¶ Extracts just node names from current tree (top).
It makes:
["asd", "fgh", ("ijk", [...]), ("lmn", [...])]
to
["asd", "fgh", "ijk", "lmn"]
Useful for checking of contents of current tree level
-
pretty_attrs
= ['locator']¶
-
tree_id
¶
-
classmethod
-
cfme.web_ui.
browser_title
()[source]¶ Returns a title of the page.
Returns: str
if present,NoneType
otherwise.
-
cfme.web_ui.
controller_name
()[source]¶ Returns a title of the page.
Returns: str
if present,NoneType
otherwise.
-
cfme.web_ui.
fill_callable
(f, val)[source]¶ Fill in a Callable by just calling it with the value, allow for arbitrary actions