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:
cfme.utils.pretty.Pretty
-
pretty_attrs
= ['text']¶
-
-
class
cfme.fixtures.pytest_selenium.
ByValue
(value)[source]¶ Bases:
cfme.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
,cfme.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 usemove_to_element()
and uses JavaScript more extensively.Parameters: loc – A locator. Returns: A
cfme.web_ui.Select
object.-
class
Option
(text, value)¶ Bases:
tuple
-
__getnewargs__
()¶ Return self as a plain tuple. Used by copy and pickle.
-
__getstate__
()¶ Exclude the OrderedDict from pickling
-
__repr__
()¶ Return a nicely formatted representation string
-
text
¶ Alias for field number 0
-
value
¶ Alias for field number 1
-
-
Select.
all_options
¶ Returns a list of tuples of all the options in the Select
-
Select.
all_selected_options
¶ 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
¶
-
Select.
deselect_all
()[source]¶ Fast variant of the original deselect_all.
Uses all_selected_options, mimics selenium’s exception behaviour.
-
Select.
first_selected_option
¶ Fast variant of the original first_selected_option.
Uses all_selected_options, mimics selenium’s exception behaviour.
-
Select.
first_selected_option_text
¶
-
Select.
is_broken
= False¶
-
Select.
is_patternfly
¶
-
Select.
none
¶
-
Select.
pretty_attrs
= ['_loc', 'is_multiple']¶
-
class
-
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.
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.
dismiss_any_alerts
()[source]¶ Loops until there are no further alerts present to dismiss.
Useful for handling the cases where the alert pops up multiple times.
-
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.
elements
[source]¶ Convert object o to list of matching WebElements. Can be extended by registering the type of o to this function.
Parameters: o – An object to be converted to a matching web element, eg str, WebElement, tuple. Returns: A list of WebElement objects
-
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.
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.
handle_alert
(cancel=False, wait=30.0, squash=False, prompt=None, check_present=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
- prompt – If the alert is a prompt, specify the keys to type in here
- check_present – Does not squash
selenium.common.exceptions.NoAlertPresentException
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 andcheck_present
is False.Raises: utils.wait.TimedOutError
– If the alert popup does not appearselenium.common.exceptions.NoAlertPresentException
– If no alert is present when accepting or dismissing the alert.
-
cfme.fixtures.pytest_selenium.
in_flight
(script)[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.
Parameters: script – Script (string) to execute 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 ofelement()
Returns:
True
if element is displayed,False
if notRaises: NoSuchElementException
– If element is not found on pageCFMEExceptionOccured
– 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.
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.
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. Handles the file upload fields on background.
If it detects the element is and input of type file, it uses the LocalFileDetector so the file gets transferred properly. Otherwise it takes care of having UselessFileDetector.
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.
set_text
(loc, text)[source]¶ Clears the element and then sends the supplied keys.
Parameters: - loc – A locator, expects either a string, WebElement, tuple.
- text – The text to inject into the element.
Returns: Any text that might have been in the textbox element already
-
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.
text
(loc, **kwargs)[source]¶ Returns the text of an element. Always.
If the element is not visible and the text cannot be retrieved by usual means, JS is used.
Parameters: loc – A locator, expects eithera string, WebElement, tuple. Returns: A string containing the text of the element.
-
cfme.fixtures.pytest_selenium.
text_content
(loc, **kwargs)[source]¶ Retrieves the text content of the element using JavaScript.
Use if the element is not visible
Parameters: loc – A locator, expects either a string, WebElement or 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.
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