cfme.fixtures.pytest_selenium module

Provides a number of useful functions for integrating with selenium.

The aim is that no direct calls to selenium be made at all. One reason for this it to ensure that all function calls to selenium wait for the ajax response which is needed in CFME.

Members of this module are available in the the pytest.sel namespace, e.g.:

pytest.sel.click(locator)
var ajax_wait_js:
 A Javascript function for ajax wait checking
var class_selector:
 Regular expression to detect simple CSS locators
class cfme.fixtures.pytest_selenium.ByText(text)[source]

Bases: utils.pretty.Pretty

pretty_attrs = ['text']
class cfme.fixtures.pytest_selenium.ByValue(value)[source]

Bases: utils.pretty.Pretty

pretty_attrs = ['value']
class cfme.fixtures.pytest_selenium.ContextWrapper[source]

Bases: dict

Dict that provides .attribute access + dumps all keys when not found.

cfme.fixtures.pytest_selenium.ScreenShot

alias of screenshot

class cfme.fixtures.pytest_selenium.Select(loc, multi=False, none=None)[source]

Bases: selenium.webdriver.support.select.Select, utils.pretty.Pretty

A proxy class for the real selenium Select() object.

We differ in one important point, that we can instantiate the object without it being present on the page. The object is located at the beginning of each function call.

Can hadle patternfly selectpicker kind of select. It alters the behaviour slightly, it does not use move_to_element() and uses JavaScript more extensively.

Parameters:loc – A locator.

Returns: A cfme.web_ui.Select object.

class Option

Bases: tuple

Option(text, value)

text

Alias for field number 0

value

Alias for field number 1

Select.all_options[source]

Returns a list of tuples of all the options in the Select

Select.all_selected_options[source]

Fast variant of the original all_selected_options.

Selenium’s all_selected_options iterates over ALL of the options, this directly returns only those that are selected.

Select.classes[source]
Select.deselect_all()[source]

Fast variant of the original deselect_all.

Uses all_selected_options, mimics selenium’s exception behaviour.

Select.first_selected_option[source]

Fast variant of the original first_selected_option.

Uses all_selected_options, mimics selenium’s exception behaviour.

Select.first_selected_option_text[source]
Select.get_value_by_text(text)[source]
Select.is_patternfly[source]
Select.locate()[source]

Guards against passing wrong locator (not resolving to a select).

Select.none[source]
Select.observer_wait()[source]
Select.pretty_attrs = ['_loc', 'is_multiple']
Select.select_by_value(value)[source]
Select.select_by_visible_text(text)[source]

Dump all of the options if the required option is not present.

cfme.fixtures.pytest_selenium.ajax_timeout(*args, **kwds)[source]

Change the AJAX timeout in this context. Useful when something takes a long time.

Parameters:seconds – Numebr of seconnds to wait.
cfme.fixtures.pytest_selenium.base_url()[source]

Returns the base url.

Returns: base_url from env config yaml

cfme.fixtures.pytest_selenium.check(loc)[source]

Convenience function to check a checkbox

Parameters:loc – The locator of the element
cfme.fixtures.pytest_selenium.checkbox(loc, set_to=False)[source]

Checks or unchecks a given checkbox

Finds an element given by loc and checks it

Parameters:
  • loc – The locator of the element
  • value – The value the checkbox should represent as a bool (or None to do nothing)

Returns: Previous state of the checkbox

cfme.fixtures.pytest_selenium.classes(loc)[source]

Return a list of classes attached to the element.

cfme.fixtures.pytest_selenium.click(loc, wait_ajax=True, no_custom_handler=False)[source]

Clicks on an element.

If the element implements _custom_click_handler the control will be given to it. Then the handler decides what to do (eg. do not click under some circumstances).

Parameters:
  • loc – A locator, expects either a string, WebElement, tuple or an object implementing _custom_click_handler method.
  • wait_ajax – Whether to wait for ajax call to finish. Default True but sometimes it’s handy to not do that. (some toolbar clicks)
  • no_custom_handler – To prevent recursion, the custom handler sets this to True.
cfme.fixtures.pytest_selenium.click_fn(*els)[source]

Returns a function which successively clicks on a series of elements.

Parameters:els – An iterable of elements:

Returns: The click function

cfme.fixtures.pytest_selenium.current_url()[source]

Returns the current_url of the page

Returns: A url.

cfme.fixtures.pytest_selenium.deselect_by_text(select_element, txt)[source]

Works on a select element and deselects an option by the visible text.

Parameters:
  • loc – A locator, expects either a string, WebElement, tuple.
  • text – The select element option’s visible text.
cfme.fixtures.pytest_selenium.deselect_by_value(select_element, val)[source]

Works on a select element and deselects an option by the value attribute.

Parameters:
  • loc – A locator, expects either a string, WebElement, tuple.
  • value – The select element’s option value.
cfme.fixtures.pytest_selenium.detect_observed_field(loc)[source]

Detect observed fields; sleep if needed

Used after filling most form fields, this function will inspect the filled field for one of the known CFME observed field attribues, and if found, sleep long enough for the observed field’s AJAX request to go out, and then block until no AJAX requests are in flight.

Observed fields occasionally declare their own wait interval before firing their AJAX request. If found, that interval will be used instead of the default.

cfme.fixtures.pytest_selenium.double_click(loc, wait_ajax=True)[source]

Double-clicks on an element.

Parameters:
  • loc – A locator, expects either a string, WebElement, tuple.
  • wait_ajax – Whether to wait for ajax call to finish. Default True but sometimes it’s handy to not do that. (some toolbar clicks)
cfme.fixtures.pytest_selenium.drag_and_drop(source_element, dest_element)[source]

Drag and Drop element.

Parameters:
  • source_element – A locator, expects either a string, WebElement, tuple.
  • dest_element – A locator, expects either a string, WebElement, tuple.
  • wait_ajax – Whether to wait for ajax call to finish. Default True but sometimes it’s handy to not do that. (some toolbar clicks)
cfme.fixtures.pytest_selenium.drag_and_drop_by_offset(source_element, x=0, y=0)[source]

Drag and Drop element by offset

Parameters:
  • source_element – A locator, expects either a string, WebElement, tuple.
  • x – Distance in pixels on X axis to move it.
  • y – Distance in pixels on Y axis to move it.
cfme.fixtures.pytest_selenium.element(o, **kwargs)[source]

Convert o to a single matching WebElement.

Parameters:o – An object to be converted to a matching web element, expected string, WebElement, tuple.
Keywords:
_no_deeper: Whether this call of the function can call for something that can retrieve
elements too. Recursion protection.

Returns: A WebElement object

Raises:NoSuchElementException – When element is not found on page
cfme.fixtures.pytest_selenium.execute_script(script, *args, **kwargs)[source]

Wrapper for execute_script() to not have to pull browser() from somewhere.

It also provides our library which is stored in data/lib.js file.

cfme.fixtures.pytest_selenium.first_from(*locs, **kwargs)[source]

Goes through locators and first valid element received is returned.

Useful for things that could be located different way

Parameters:
  • *locs – Locators to pass through
  • **kwargs – Keyword arguments to pass to element()
Raises:

NoSuchElementException – When none of the locator could find the element.

Returns: WebElement

cfme.fixtures.pytest_selenium.force_navigate(page_name)[source]

Given a page name, attempt to navigate to that page no matter what breaks.

Parameters:page_name – Name a page from the current ui_navigate.nav_tree tree to navigate to.
cfme.fixtures.pytest_selenium.get(url)[source]

Changes page to the specified URL

Parameters:url – URL to navigate to.
cfme.fixtures.pytest_selenium.get_attribute(loc, attr)[source]

Returns the value of the HTML attribute of the given locator.

Parameters:
  • loc – A locator, expects eithera string, WebElement, tuple.
  • attr – An attribute name.

Returns: Text describing the attribute of the element.

cfme.fixtures.pytest_selenium.get_rails_error()[source]

Get displayed rails error. If not present, return None

cfme.fixtures.pytest_selenium.go_to(page_name)[source]

go_to task mark, used to ensure tests start on the named page, logged in as Administrator.

Parameters:page_name – Name a page from the current ui_navigate.nav_tree tree to navigate to.

Usage:

@pytest.sel.go_to('page_name')
def test_something_on_page_name():
    # ...
cfme.fixtures.pytest_selenium.go_to_fixture(fixtureconf, browser)[source]

“Private” implementation of go_to in fixture form.

Used by the go_to() decorator, this is the actual fixture that does the work set up by the go_to decorator. py.test fixtures themselves can’t have underscores in their name, so we can’t imply privacy with that convention.

Don’t use this fixture directly, use the go_to decorator instead.

cfme.fixtures.pytest_selenium.handle_alert(cancel=False, wait=30.0, squash=False)[source]

Handles an alert popup.

Parameters:
  • cancel – Whether or not to cancel the alert. Accepts the Alert (False) by default.
  • wait – Time to wait for an alert to appear. Default 30 seconds, can be set to 0 to disable waiting.
  • squash – Whether or not to squash errors during alert handling. Default False
Returns:

True if the alert was handled, False if exceptions were squashed, None if there was no alert.

No exceptions will be raised if squash is True.

Raises:
cfme.fixtures.pytest_selenium.in_flight()[source]

Check remaining (running) ajax requests

The element visibility check is complex because lightbox_div invokes visibility of spinner_div although it is not visible.

Returns:Dictionary of js-related keys and booleans as its values, depending on status. The keys are: jquery, prototype, miq, spinner and document. The values are: True if running, False otherwise.
cfme.fixtures.pytest_selenium.is_displayed(loc, _deep=0, **kwargs)[source]

Checks if a particular locator is displayed

Parameters:loc – A locator, expects either a string, WebElement, tuple.
Keywords:
move_to: Uses move_to_element() instead of element()

Returns: True if element is displayed, False if not

Raises:
  • NoSuchElementException – If element is not found on page
  • CFMEExceptionOccured – When there is a CFME rails exception on the page.
cfme.fixtures.pytest_selenium.is_displayed_text(text)[source]

Checks if a particular text is displayed

Parameters:text – A string.

Returns: A string containing the text

cfme.fixtures.pytest_selenium.move_to_element(loc, **kwargs)[source]

Moves to an element.

Parameters:loc – A locator, expects either a string, WebElement, tuple.

Returns: Returns the element it was moved to to enable chaining.

cfme.fixtures.pytest_selenium.move_to_fn(*els)[source]

Returns a function which successively moves through a series of elements.

Parameters:els – An iterable of elements:

Returns: The move function

cfme.fixtures.pytest_selenium.multi_check(locators)[source]

Mass-check and uncheck for checkboxes.

Parameters:locatorsdict or list or whatever iterable of tuples. Key is the locator, value bool with check status.

Returns: list of booleans indicating for each locator, whether any action was taken.

cfme.fixtures.pytest_selenium.on_cfme_page()[source]

Check whether we are on a CFME page and not another or blank page

cfme.fixtures.pytest_selenium.raw_click(loc, wait_ajax=True)[source]

Does raw selenium’s .click() call on element. Circumvents mouse move.

Parameters:
  • loc – Locator to click on.
  • wait_ajax – Whether to wait for ajax.
cfme.fixtures.pytest_selenium.refresh()[source]

Refreshes the current browser window.

cfme.fixtures.pytest_selenium.select_by_text(select_element, txt)[source]

Works on a select element and selects an option by the visible text.

Parameters:
  • loc – A locator, expects either a string, WebElement, tuple.
  • text – The select element option’s visible text.

Returns: previously selected text

cfme.fixtures.pytest_selenium.select_by_value(select_element, val)[source]

Works on a select element and selects an option by the value attribute.

Parameters:
  • loc – A locator, expects either a string, WebElement, tuple.
  • value – The select element’s option value.
cfme.fixtures.pytest_selenium.send_keys(loc, text)[source]

Sends the supplied keys to an element.

Parameters:
  • loc – A locator, expects either a string, WebElement, tuple.
  • text – The text to inject into the element.
cfme.fixtures.pytest_selenium.set_angularjs_value(loc, value)[source]

Sets value of an element managed by angularjs

Parameters:
  • loc – A locator, expects either a string, WebElement, tuple.
  • value – Value to set.
cfme.fixtures.pytest_selenium.set_attribute(loc, attr, value)[source]

Sets the attribute of an element.

This is usually not done, that’s why it is not implemented in selenium. But sometimes ...

Parameters:
  • loc – A locator, expects either a string, WebElement, tuple.
  • attr – Attribute name.
  • value – Value to set.
cfme.fixtures.pytest_selenium.tag(loc)[source]

Returns the tag name of an element

Parameters:loc – A locator, expects either a string, WebElement, tuple.

Returns: A string containing the tag element’s name.

cfme.fixtures.pytest_selenium.take_screenshot()[source]
cfme.fixtures.pytest_selenium.text(loc, **kwargs)[source]

Returns the text of an element.

Parameters:loc – A locator, expects eithera string, WebElement, tuple.

Returns: A string containing the text of the element.

cfme.fixtures.pytest_selenium.text_sane(loc, **kwargs)[source]

Returns text decoded from UTF-8 and stripped

Parameters:loc – A locator, expects eithera string, WebElement, tuple.

Returns: A string containing the text of the element, decoded and stripped.

cfme.fixtures.pytest_selenium.title()[source]
cfme.fixtures.pytest_selenium.uncheck(loc)[source]

Convenience function to uncheck a checkbox

Parameters:loc – The locator of the element
cfme.fixtures.pytest_selenium.unset_attribute(loc, attr)[source]

Removes an attribute of an element.

This is usually not done, that’s why it is not implemented in selenium. But sometimes ...

Parameters:
  • loc – A locator, expects either a string, WebElement, tuple.
  • attr – Attribute name.
cfme.fixtures.pytest_selenium.value(loc)[source]

Returns the value of an input element.

Parameters:loc – A locator, expects eithera string, WebElement, tuple.

Returns: A string containing the value of the input element.

cfme.fixtures.pytest_selenium.wait_for_ajax()[source]

Waits until all ajax timers are complete, in other words, waits until there are no more pending ajax requests, page load should be finished completely.

Raises:TimedOutError – when ajax did not load in time
cfme.fixtures.pytest_selenium.wait_for_element(*locs, **kwargs)[source]

Wrapper around wait_until, specific to an element.

Parameters:loc – A locator, expects either a string, WebElement, tuple.
Keywords:
all_elements: Whether to wait not for one, but all elements (Default False) timeout: How much time to wait
cfme.fixtures.pytest_selenium.wait_until(f, msg='Webdriver wait timed out', timeout=120.0)[source]

This used to be a wrapper around WebDriverWait from selenium.

Now it is just compatibility layer using utils.wait.wait_for()