diff --git a/src/SeleniumLibrary/__init__.py b/src/SeleniumLibrary/__init__.py index 96aab4e78..9adda6998 100644 --- a/src/SeleniumLibrary/__init__.py +++ b/src/SeleniumLibrary/__init__.py @@ -82,10 +82,10 @@ class SeleniumLibrary(DynamicCore): By default locators are considered to use the keyword specific default locator strategy. All keywords support finding elements based on ``id`` - and ``name`` attributes, but some keywords support additional _key - attributes_ that make sense in their context. For example, `Click Link` - supports the link text and the ``href`` attribute in addition to the - normal ``id`` and ``name``. + and ``name`` attributes, but some keywords support additional attributes + or other values that make sense in their context. For example, `Click + Link` supports the ``href`` attribute and the link text and addition + to the normal ``id`` and ``name``. Examples: diff --git a/src/SeleniumLibrary/keywords/element.py b/src/SeleniumLibrary/keywords/element.py index bb41d5f87..c212fc7a8 100644 --- a/src/SeleniumLibrary/keywords/element.py +++ b/src/SeleniumLibrary/keywords/element.py @@ -609,8 +609,8 @@ def click_link(self, locator): """Clicks a link identified by ``locator``. See the `Locating elements` section for details about the locator - syntax. Key attributes for links are ``id``, ``name``, ``href`` and - link text. + syntax. When using the default locator strategy, links are searched + using ``id``, ``name``, ``href`` and the link text. """ self.info("Clicking link '%s'." % locator) self.find_element(locator, tag='link').click() @@ -629,8 +629,8 @@ def mouse_down_on_link(self, locator): """Simulates a mouse down event on a link identified by ``locator``. See the `Locating elements` section for details about the locator - syntax. Key attributes for links are ``id``, ``name``, ``href`` and - link text. + syntax. When using the default locator strategy, links are searched + using ``id``, ``name``, ``href`` and the link text. """ element = self.find_element(locator, tag='link') action = ActionChains(self.browser) @@ -641,8 +641,8 @@ def page_should_contain_link(self, locator, message=None, loglevel='INFO'): """Verifies link identified by ``locator`` is found from current page. See the `Locating elements` section for details about the locator - syntax. Key attributes for links are ``id``, ``name``, ``href`` and - link text. + syntax. When using the default locator strategy, links are searched + using ``id``, ``name``, ``href`` and the link text. See `Page Should Contain Element` for explanation about ``message`` and ``loglevel`` arguments. @@ -654,8 +654,8 @@ def page_should_not_contain_link(self, locator, message=None, loglevel='INFO'): """Verifies link identified by ``locator`` is not found from current page. See the `Locating elements` section for details about the locator - syntax. Key attributes for links are ``id``, ``name``, ``href`` and - link text. + syntax. When using the default locator strategy, links are searched + using ``id``, ``name``, ``href`` and the link text. See `Page Should Contain Element` for explanation about ``message`` and ``loglevel`` arguments. @@ -667,7 +667,8 @@ def click_image(self, locator): """Clicks an image identified by ``locator``. See the `Locating elements` section for details about the locator - syntax. Key attributes for images are ``id``, ``src`` and ``alt``. + syntax. When using the default locator strategy, images are searched + using ``id``, ``name``, ``src`` and ``alt``. """ self.info("Clicking image '%s'." % locator) element = self.find_element(locator, tag='image', required=False) @@ -681,7 +682,8 @@ def mouse_down_on_image(self, locator): """Simulates a mouse down event on an image identified by ``locator``. See the `Locating elements` section for details about the locator - syntax. Key attributes for images are ``id``, ``src`` and ``alt``. + syntax. When using the default locator strategy, images are searched + using ``id``, ``name``, ``src`` and ``alt``. """ element = self.find_element(locator, tag='image') action = ActionChains(self.browser) @@ -692,7 +694,8 @@ def page_should_contain_image(self, locator, message=None, loglevel='INFO'): """Verifies image identified by ``locator`` is found from current page. See the `Locating elements` section for details about the locator - syntax. Key attributes for images are ``id``, ``src`` and ``alt``. + syntax. When using the default locator strategy, images are searched + using ``id``, ``name``, ``src`` and ``alt``. See `Page Should Contain Element` for explanation about ``message`` and ``loglevel`` arguments. @@ -704,7 +707,8 @@ def page_should_not_contain_image(self, locator, message=None, loglevel='INFO'): """Verifies image identified by ``locator`` is found from current page. See the `Locating elements` section for details about the locator - syntax. Key attributes for images are ``id``, ``src`` and ``alt``. + syntax. When using the default locator strategy, images are searched + using ``id``, ``name``, ``src`` and ``alt``. See `Page Should Contain Element` for explanation about ``message`` and ``loglevel`` arguments. diff --git a/src/SeleniumLibrary/keywords/formelement.py b/src/SeleniumLibrary/keywords/formelement.py index 2c9a27dfa..913e4df2c 100644 --- a/src/SeleniumLibrary/keywords/formelement.py +++ b/src/SeleniumLibrary/keywords/formelement.py @@ -25,11 +25,12 @@ class FormElementKeywords(LibraryComponent): @keyword def submit_form(self, locator=None): - """Submits a form identified by `locator`. + """Submits a form identified by ``locator``. - If `locator` is empty, first form in the page will be submitted. - Key attributes for forms are `id` and `name`. See `introduction` for - details about locating elements. + If ``locator`` is not given, first form on the page is submitted. + + See the `Locating elements` section for details about the locator + syntax. """ self.info("Submitting form '%s'." % locator) if is_noney(locator): @@ -39,10 +40,10 @@ def submit_form(self, locator=None): @keyword def checkbox_should_be_selected(self, locator): - """Verifies checkbox identified by `locator` is selected/checked. + """Verifies checkbox ``locator`` is selected/checked. - Key attributes for checkboxes are `id` and `name`. See `introduction` - for details about locating elements. + See the `Locating elements` section for details about the locator + syntax. """ self.info("Verifying checkbox '%s' is selected." % locator) element = self._get_checkbox(locator) @@ -52,10 +53,10 @@ def checkbox_should_be_selected(self, locator): @keyword def checkbox_should_not_be_selected(self, locator): - """Verifies checkbox identified by `locator` is not selected/checked. + """Verifies checkbox ``locator`` is not selected/checked. - Key attributes for checkboxes are `id` and `name`. See `introduction` - for details about locating elements. + See the `Locating elements` section for details about the locator + syntax.. """ self.info("Verifying checkbox '%s' is not selected." % locator) element = self._get_checkbox(locator) @@ -65,35 +66,36 @@ def checkbox_should_not_be_selected(self, locator): @keyword def page_should_contain_checkbox(self, locator, message=None, loglevel='INFO'): - """Verifies checkbox identified by `locator` is found from current page. + """Verifies checkbox ``locator`` is found from current page. - See `Page Should Contain Element` for explanation about `message` and - `loglevel` arguments. + See `Page Should Contain Element` for explanation about ``message`` + and ``loglevel`` arguments. - Key attributes for checkboxes are `id` and `name`. See `introduction` - for details about locating elements. + See the `Locating elements` section for details about the locator + syntax. """ self.assert_page_contains(locator, 'checkbox', message, loglevel) @keyword def page_should_not_contain_checkbox(self, locator, message=None, loglevel='INFO'): - """Verifies checkbox identified by `locator` is not found from current page. + """Verifies checkbox ``locator`` is not found from current page. - See `Page Should Contain Element` for explanation about `message` and - `loglevel` arguments. + See `Page Should Contain Element` for explanation about ``message`` + and ``loglevel`` arguments. - Key attributes for checkboxes are `id` and `name`. See `introduction` - for details about locating elements. + See the `Locating elements` section for details about the locator + syntax. """ self.assert_page_not_contains(locator, 'checkbox', message, loglevel) @keyword def select_checkbox(self, locator): - """Selects checkbox identified by `locator`. + """Selects checkbox identified by ``locator``. + + Does nothing if checkbox is already selected. - Does nothing if checkbox is already selected. Key attributes for - checkboxes are `id` and `name`. See `introduction` for details about - locating elements. + See the `Locating elements` section for details about the locator + syntax. """ self.info("Selecting checkbox '%s'." % locator) element = self._get_checkbox(locator) @@ -102,11 +104,12 @@ def select_checkbox(self, locator): @keyword def unselect_checkbox(self, locator): - """Removes selection of checkbox identified by `locator`. + """Removes selection of checkbox identified by ``locator``. - Does nothing if the checkbox is not checked. Key attributes for - checkboxes are `id` and `name`. See `introduction` for details about - locating elements. + Does nothing if the checkbox is not selected. + + See the `Locating elements` section for details about the locator + syntax. """ self.info("Unselecting checkbox '%s'." % locator) element = self._get_checkbox(locator) @@ -115,35 +118,36 @@ def unselect_checkbox(self, locator): @keyword def page_should_contain_radio_button(self, locator, message=None, loglevel='INFO'): - """Verifies radio button identified by `locator` is found from current page. + """Verifies radio button ``locator`` is found from current page. - See `Page Should Contain Element` for explanation about `message` and - `loglevel` arguments. + See `Page Should Contain Element` for explanation about ``message`` + and ``loglevel`` arguments. - Key attributes for radio buttons are `id`, `name` and `value`. See - `introduction` for details about locating elements. + See the `Locating elements` section for details about the locator + syntax. When using the default locator strategy, radio buttons are + searched using ``id``, ``name`` and ``value``. """ self.assert_page_contains(locator, 'radio button', message, loglevel) @keyword def page_should_not_contain_radio_button(self, locator, message=None, loglevel='INFO'): - """Verifies radio button identified by `locator` is not found from current page. + """Verifies radio button ``locator`` is not found from current page. - See `Page Should Contain Element` for explanation about `message` and - `loglevel` arguments. + See `Page Should Contain Element` for explanation about ``message`` + and ``loglevel`` arguments. - Key attributes for radio buttons are `id`, `name` and `value`. See - `introduction` for details about locating elements. + See the `Locating elements` section for details about the locator + syntax. When using the default locator strategy, radio buttons are + searched using ``id``, ``name`` and ``value``. """ self.assert_page_not_contains(locator, 'radio button', message, loglevel) @keyword def radio_button_should_be_set_to(self, group_name, value): - """Verifies radio button group identified by `group_name` has its selection set to `value`. + """Verifies radio button group ``group_name`` is set to ``value``. - See `Select Radio Button` for information about how radio buttons are - located. + ``group_name`` is the ``name`` of the radio button group. """ self.info("Verifying radio button '%s' has selection '%s'." % (group_name, value)) @@ -156,10 +160,9 @@ def radio_button_should_be_set_to(self, group_name, value): @keyword def radio_button_should_not_be_selected(self, group_name): - """Verifies radio button group identified by `group_name` has no selection. + """Verifies radio button group ``group_name`` has no selection. - See `Select Radio Button` for information about how radio buttons are - located. + ``group_name`` is the ``name`` of the radio button group. """ self.info("Verifying radio button '%s' has no selection." % group_name) elements = self._get_radio_buttons(group_name) @@ -171,18 +174,16 @@ def radio_button_should_not_be_selected(self, group_name): @keyword def select_radio_button(self, group_name, value): - """Sets selection of radio button group identified by `group_name` to `value`. + """Sets radio button group ``group_name`` to ``value``. The radio button to be selected is located by two arguments: - - `group_name` is used as the name of the radio input - - `value` is used for the value attribute or for the id attribute - - The XPath used to locate the correct radio button then looks like this: - //input[@type='radio' and @name='group_name' and (@value='value' or @id='value')] + - ``group_name`` is the name of the radio button group. + - ``value`` is the ``id`` or ``value`` attribute of the actual + radio button. Examples: - | Select Radio Button | size | XL | # Matches HTML like XL | - | Select Radio Button | size | sizeXL | # Matches HTML like XL | + | `Select Radio Button` | size | XL | + | `Select Radio Button` | contact | email | """ self.info("Selecting '%s' from radio button '%s'." % (value, group_name)) @@ -192,14 +193,14 @@ def select_radio_button(self, group_name, value): @keyword def choose_file(self, locator, file_path): - """Inputs the `file_path` into file input field found by `locator`. + """Inputs the ``file_path`` into file input field ``locator``. This keyword is most often used to input files into upload forms. - The file specified with `file_path` must be available on the same host - where the Selenium Server is running. + The file specified with ``file_path`` must be available on machine + where tests are executed. Example: - | Choose File | my_upload_field | /home/user/files/trades.csv | + | `Choose File` | my_upload_field | ${CURDIR}/trades.csv | """ if not os.path.isfile(file_path): raise ValueError("File '%s' does not exist on the local file " @@ -207,57 +208,77 @@ def choose_file(self, locator, file_path): self.find_element(locator).send_keys(file_path) @keyword - def input_password(self, locator, text): - """Types the given password into text field identified by `locator`. + def input_password(self, locator, password): + """Types the given password into text field identified by ``locator``. + + See the `Locating elements` section for details about the locator + syntax. + + Difference compared to `Input Text` is that this keyword does not + log the given password on the INFO level. Notice that if you use + the keyword like + + | Input Password | password_field | password | - Difference between this keyword and `Input Text` is that this keyword - does not log the given password. See `introduction` for details about - locating elements. + the password is shown as a normal keyword argument. A way to avoid + that is using variables like + + | Input Password | password_field | ${PASSWORD} | + + Notice also that SeleniumLibrary logs all the communication with + browser drivers using the DEBUG level, and the actual password can + be seen there. Additionally Robot Framework logs all arguments using + the TRACE level. Tests must thus not be executed using level below + INFO if password should not be logged in any format. """ self.info("Typing password into text field '%s'." % locator) - self._input_text_into_text_field(locator, text) + self._input_text_into_text_field(locator, password) @keyword def input_text(self, locator, text): - """Types the given `text` into text field identified by `locator`. + """Types the given ``text`` into text field identified by ``locator``. - See `introduction` for details about locating elements. + Use `Input Password` if you do not want the given ``text`` to be + logged. + + See the `Locating elements` section for details about the locator + syntax. """ self.info("Typing text '%s' into text field '%s'." % (text, locator)) self._input_text_into_text_field(locator, text) @keyword def page_should_contain_textfield(self, locator, message=None, loglevel='INFO'): - """Verifies text field identified by `locator` is found from current page. + """Verifies text field ``locator`` is found from current page. - See `Page Should Contain Element` for explanation about `message` and - `loglevel` arguments. + See `Page Should Contain Element` for explanation about ``message`` + and ``loglevel`` arguments. - Key attributes for text fields are `id` and `name`. See `introduction` - for details about locating elements. + See the `Locating elements` section for details about the locator + syntax. """ self.assert_page_contains(locator, 'text field', message, loglevel) @keyword def page_should_not_contain_textfield(self, locator, message=None, loglevel='INFO'): - """Verifies text field identified by `locator` is not found from current page. + """Verifies text field ``locator`` is not found from current page. - See `Page Should Contain Element` for explanation about `message` and - `loglevel` arguments. + See `Page Should Contain Element` for explanation about ``message`` + and ``loglevel`` arguments. - Key attributes for text fields are `id` and `name`. See `introduction` - for details about locating elements. + See the `Locating elements` section for details about the locator + syntax. """ self.assert_page_not_contains(locator, 'text field', message, loglevel) @keyword def textfield_should_contain(self, locator, expected, message=None): - """Verifies text field identified by `locator` contains text `expected`. + """Verifies text field ``locator`` contains text ``expected``. - `message` can be used to override default error message. + ``message`` can be used to override the default error message. - Key attributes for text fields are `id` and `name`. See `introduction` - for details about locating elements. + See the `Locating elements` section for details about the locator + syntax. """ actual = self._get_value(locator, 'text field') if expected not in actual: @@ -269,12 +290,12 @@ def textfield_should_contain(self, locator, expected, message=None): @keyword def textfield_value_should_be(self, locator, expected, message=None): - """Verifies the value in text field identified by `locator` is exactly `expected`. + """Verifies text field ``locator`` has exactly text ``expected``. - `message` can be used to override default error message. + ``message`` can be used to override default error message. - Key attributes for text fields are `id` and `name`. See `introduction` - for details about locating elements. + See the `Locating elements` section for details about the locator + syntax. """ actual = self._get_value(locator, 'text field') if actual != expected: @@ -286,12 +307,12 @@ def textfield_value_should_be(self, locator, expected, message=None): @keyword def textarea_should_contain(self, locator, expected, message=None): - """Verifies text area identified by `locator` contains text `expected`. + """Verifies text area ``locator`` contains text ``expected``. - `message` can be used to override default error message. + ``message`` can be used to override default error message. - Key attributes for text areas are `id` and `name`. See `introduction` - for details about locating elements. + See the `Locating elements` section for details about the locator + syntax. """ actual = self._get_value(locator, 'text area') if expected not in actual: @@ -303,12 +324,12 @@ def textarea_should_contain(self, locator, expected, message=None): @keyword def textarea_value_should_be(self, locator, expected, message=None): - """Verifies the value in text area identified by `locator` is exactly `expected`. + """Verifies text area ``locator`` has exactly text ``expected``. - `message` can be used to override default error message. + ``message`` can be used to override default error message. - Key attributes for text areas are `id` and `name`. See `introduction` - for details about locating elements. + See the `Locating elements` section for details about the locator + syntax. """ actual = self._get_value(locator, 'text area') if expected != actual: @@ -320,10 +341,11 @@ def textarea_value_should_be(self, locator, expected, message=None): @keyword def click_button(self, locator): - """Clicks a button identified by `locator`. + """Clicks button identified by ``locator``. - Key attributes for buttons are `id`, `name` and `value`. See - `introduction` for details about locating elements. + See the `Locating elements` section for details about the locator + syntax. When using the default locator strategy, buttons are + searched using ``id``, ``name`` and ``value``. """ self.info("Clicking button '%s'." % locator) element = self.find_element(locator, tag='input', required=False) @@ -333,15 +355,14 @@ def click_button(self, locator): @keyword def page_should_contain_button(self, locator, message=None, loglevel='INFO'): - """Verifies button identified by `locator` is found from current page. - - This keyword searches for buttons created with either `input` or `button` tag. + """Verifies button ``locator`` is found from current page. - See `Page Should Contain Element` for explanation about `message` and - `loglevel` arguments. + See `Page Should Contain Element` for explanation about ``message`` + and ``loglevel`` arguments. - Key attributes for buttons are `id`, `name` and `value`. See - `introduction` for details about locating elements. + See the `Locating elements` section for details about the locator + syntax. When using the default locator strategy, buttons are + searched using ``id``, ``name`` and ``value``. """ try: self.assert_page_contains(locator, 'input', message, loglevel) @@ -350,15 +371,14 @@ def page_should_contain_button(self, locator, message=None, loglevel='INFO'): @keyword def page_should_not_contain_button(self, locator, message=None, loglevel='INFO'): - """Verifies button identified by `locator` is not found from current page. - - This keyword searches for buttons created with either `input` or `button` tag. + """Verifies button ``locator`` is not found from current page. - See `Page Should Contain Element` for explanation about `message` and - `loglevel` arguments. + See `Page Should Contain Element` for explanation about ``message`` + and ``loglevel`` arguments. - Key attributes for buttons are `id`, `name` and `value`. See - `introduction` for details about locating elements. + See the `Locating elements` section for details about the locator + syntax. When using the default locator strategy, buttons are + searched using ``id``, ``name`` and ``value``. """ self.assert_page_not_contains(locator, 'button', message, loglevel) self.assert_page_not_contains(locator, 'input', message, loglevel) diff --git a/src/SeleniumLibrary/keywords/javascript.py b/src/SeleniumLibrary/keywords/javascript.py index 4974cbafb..c8f4148b7 100644 --- a/src/SeleniumLibrary/keywords/javascript.py +++ b/src/SeleniumLibrary/keywords/javascript.py @@ -25,31 +25,30 @@ class JavaScriptKeywords(LibraryComponent): def execute_javascript(self, *code): """Executes the given JavaScript code. - `code` may contain multiple lines of code and may be divided into + ``code`` may contain multiple lines of code and may be divided into multiple cells in the test data. In that case, the parts are - catenated together without adding spaces. + concatenated together without adding spaces. - If `code` is an absolute path to an existing file, the JavaScript + If ``code`` is an absolute path to an existing file, the JavaScript to execute will be read from that file. Forward slashes work as a path separator on all operating systems. The JavaScript executes in the context of the currently selected - frame or window as the body of an anonymous function. Use _window_ to - refer to the window of your application and _document_ to refer to the - document object of the current frame or window, e.g. - _document.getElementById('foo')_. + frame or window as the body of an anonymous function. Use ``window`` + to refer to the window of your application and ``document`` to refer + to the document object of the current frame or window, e.g. + ``document.getElementById('example')``. - This keyword returns None unless there is a return statement in the - JavaScript. Return values are converted to the appropriate type in - Python, including WebElements. + This keyword returns whatever the executed JavaScript code returns. + Return values are converted to the appropriate Python types. Examples: - | Execute JavaScript | window.my_js_function('arg1', 'arg2') | | - | Execute JavaScript | ${CURDIR}/js_to_execute.js | | - | ${sum}= | Execute JavaScript | return 1 + 1; | - | Should Be Equal | ${sum} | ${2} | + | `Execute JavaScript` | window.myFunc('arg1', 'arg2') | + | `Execute JavaScript` | ${CURDIR}/js_to_execute.js | + | ${sum} = | `Execute JavaScript` | return 1 + 1; | + | `Should Be Equal` | ${sum} | ${2} | """ - js = self._get_javascript_to_execute(''.join(code)) + js = self._get_javascript_to_execute(code) self.info("Executing JavaScript:\n%s" % js) return self.browser.execute_script(js) @@ -66,28 +65,27 @@ def execute_async_javascript(self, *code): fail. See the `Timeouts` section for more information. Examples: - | Execute Async JavaScript | var callback = arguments[arguments.length - 1]; | window.setTimeout(callback, 2000); | - | Execute Async JavaScript | ${CURDIR}/async_js_to_execute.js | | - | ${retval}= | Execute Async JavaScript | | - | ... | var callback = arguments[arguments.length - 1]; | | - | ... | function answer(){callback("text");}; | | - | ... | window.setTimeout(answer, 2000); | | - | Should Be Equal | ${retval} | text | + | `Execute Async JavaScript` | var callback = arguments[arguments.length - 1]; window.setTimeout(callback, 2000); | + | `Execute Async JavaScript` | ${CURDIR}/async_js_to_execute.js | + | ${result} = | `Execute Async JavaScript` | + | ... | var callback = arguments[arguments.length - 1]; | + | ... | function answer(){callback("text");}; | + | ... | window.setTimeout(answer, 2000); | + | `Should Be Equal` | ${result} | text | """ - js = self._get_javascript_to_execute(''.join(code)) + js = self._get_javascript_to_execute(code) self.info("Executing Asynchronous JavaScript:\n%s" % js) return self.browser.execute_async_script(js) - def _get_javascript_to_execute(self, code): - codepath = code.replace('/', os.sep) - if not (os.path.isabs(codepath) and os.path.isfile(codepath)): - return code - self.info( - 'Reading JavaScript from file %s.'.format( - codepath.replace(os.sep, '/'), codepath), - html=True) - codefile = open(codepath) - try: - return codefile.read().strip() - finally: - codefile.close() + def _get_javascript_to_execute(self, lines): + code = ''.join(lines) + path = code.replace('/', os.sep) + if os.path.isabs(path) and os.path.isfile(path): + code = self._read_javascript_from_file(path) + return code + + def _read_javascript_from_file(self, path): + self.info('Reading JavaScript from file %s.' + .format(path.replace(os.sep, '/'), path), html=True) + with open(path) as file: + return file.read().strip() diff --git a/src/SeleniumLibrary/keywords/runonfailure.py b/src/SeleniumLibrary/keywords/runonfailure.py index cd5a7f1eb..d6f2b029d 100644 --- a/src/SeleniumLibrary/keywords/runonfailure.py +++ b/src/SeleniumLibrary/keywords/runonfailure.py @@ -15,7 +15,7 @@ # limitations under the License. from SeleniumLibrary.base import LibraryComponent, keyword -from SeleniumLibrary.utils import is_falsy, is_string +from SeleniumLibrary.utils import is_noney, is_string class RunOnFailureKeywords(LibraryComponent): @@ -24,18 +24,18 @@ class RunOnFailureKeywords(LibraryComponent): def register_keyword_to_run_on_failure(self, keyword): """Sets the keyword to execute when a SeleniumLibrary keyword fails. - `keyword` is the name of a keyword that will be executed if a + ``keyword`` is the name of a keyword that will be executed if a SeleniumLibrary keyword fails. It is possible to use any available keyword, including user keywords or keywords from other libraries, but the keyword must not take any arguments. - The initial keyword to use is set in `importing`, and the - keyword that is used by default is `Capture Page Screenshot`. + The initial keyword to use is set when `importing` the library, and + the keyword that is used by default is `Capture Page Screenshot`. Taking a screenshot when something failed is a very useful feature, but notice that it can slow down the execution. - It is possible to use string "Nothing" or "None", case-insensitively, - as well as any value considered false in Python to disable this + It is possible to use string ``NOTHING`` or ``NONE``, + case-insensitively, as well as Python ``None`` to disable this feature altogether. This keyword returns the name of the previously registered @@ -44,15 +44,15 @@ def register_keyword_to_run_on_failure(self, keyword): restore the original value later. Example: - | Register Keyword To Run On Failure | Log Source | # Run `Log Source` on failure. | - | ${previous kw}= | Register Keyword To Run On Failure | Nothing | # Disables run-on-failure functionality and stores the previous kw name in a variable. | - | Register Keyword To Run On Failure | ${previous kw} | # Restore to the previous keyword. | + | `Register Keyword To Run On Failure` | Log Source | + | ${previous kw}= | `Register Keyword To Run On Failure` | NONE | + | `Register Keyword To Run On Failure` | ${previous kw} | - Changes in version 3.0.0: - - Possible to use string "NONE" or any falsy value to disable the - feature. + Changes in SeleniumLibrary 3.0: + - Possible to use string ``NONE`` or Python ``None`` to disable the + functionality. - Return Python ``None`` when the functionality was disabled earlier. - In previous versions special value "No Keyword" was returned and + In previous versions special value ``No Keyword`` was returned and it could not be used to restore the original state. """ old_keyword = self.ctx.run_on_failure_keyword @@ -63,6 +63,6 @@ def register_keyword_to_run_on_failure(self, keyword): @staticmethod def resolve_keyword(name): - if is_falsy(name) or is_string(name) and name.upper() == 'NOTHING': + if is_noney(name) or is_string(name) and name.upper() == 'NOTHING': return None return name diff --git a/src/SeleniumLibrary/keywords/waiting.py b/src/SeleniumLibrary/keywords/waiting.py index cd1fb1caa..3a74b2109 100644 --- a/src/SeleniumLibrary/keywords/waiting.py +++ b/src/SeleniumLibrary/keywords/waiting.py @@ -25,20 +25,17 @@ class WaitingKeywords(LibraryComponent): @keyword def wait_for_condition(self, condition, timeout=None, error=None): - """Waits until the given ``condition`` is true or ``timeout`` expires. + """Waits until ``condition`` is true or ``timeout`` expires. - The ``condition`` can be arbitrary JavaScript expression but it + The condition can be arbitrary JavaScript expression but it must return a value to be evaluated. See `Execute JavaScript` for information about accessing content on pages. - ``error`` can be used to override the default error message. - - See `timeouts` for more information about using timeouts and their - default value. + Fails if the timeout expires before the condition becomes true. See + the `Timeouts` section for more information about using timeouts + and their default value. - See also `Wait Until Page Contains`, `Wait Until Page Contains - Element`, `Wait Until Element Is Visible` and BuiltIn keyword - `Wait Until Keyword Succeeds`. + ``error`` can be used to override the default error message. """ if 'return' not in condition: raise ValueError("Condition '%s' did not have mandatory 'return'." @@ -51,53 +48,44 @@ def wait_for_condition(self, condition, timeout=None, error=None): @keyword def wait_until_page_contains(self, text, timeout=None, error=None): - """Waits until `text` appears on current page. + """Waits until ``text`` appears on current page. - Fails if `timeout` expires before the text appears. See - `introduction` for more information about `timeout` and its - default value. + Fails if ``timeout`` expires before the text appears. See + the `Timeouts` section for more information about using timeouts + and their default value. - `error` can be used to override the default error message. - - See also `Wait Until Page Contains Element`, `Wait For Condition`, - `Wait Until Element Is Visible` and BuiltIn keyword `Wait Until - Keyword Succeeds`. + ``error`` can be used to override the default error message. """ self._wait_until(lambda: self.is_text_present(text), "Text '%s' did not appear in ." % text, timeout, error) @keyword - def wait_until_page_does_not_contain(self, text, timeout=None, error=None): - """Waits until `text` disappears from current page. + def wait_until_page_does_not_contain(self, text, timeout=None, + error=None): + """Waits until ``text`` disappears from current page. - Fails if `timeout` expires before the `text` disappears. See - `introduction` for more information about `timeout` and its - default value. + Fails if ``timeout`` expires before the text disappears. See + the `Timeouts` section for more information about using timeouts + and their default value. - `error` can be used to override the default error message. - - See also `Wait Until Page Contains`, `Wait For Condition`, - `Wait Until Element Is Visible` and BuiltIn keyword `Wait Until - Keyword Succeeds`. + ``error`` can be used to override the default error message. """ self._wait_until(lambda: not self.is_text_present(text), "Text '%s' did not disappear in ." % text, timeout, error) @keyword - def wait_until_page_contains_element(self, locator, timeout=None, error=None): - """Waits until element specified with `locator` appears on current page. - - Fails if `timeout` expires before the element appears. See - `introduction` for more information about `timeout` and its - default value. + def wait_until_page_contains_element(self, locator, timeout=None, + error=None): + """Waits until element ``locator`` appears on current page. - `error` can be used to override the default error message. + Fails if ``timeout`` expires before the element appears. See + the `Timeouts` section for more information about using timeouts and + their default value and the `Locating elements` section for details + about the locator syntax. - See also `Wait Until Page Contains`, `Wait For Condition`, - `Wait Until Element Is Visible` and BuiltIn keyword `Wait Until - Keyword Succeeds`. + ``error`` can be used to override the default error message. """ self._wait_until( lambda: self.find_element(locator, required=False) is not None, @@ -106,18 +94,16 @@ def wait_until_page_contains_element(self, locator, timeout=None, error=None): ) @keyword - def wait_until_page_does_not_contain_element(self, locator, timeout=None, error=None): - """Waits until element specified with `locator` disappears from current page. - - Fails if `timeout` expires before the element disappears. See - `introduction` for more information about `timeout` and its - default value. + def wait_until_page_does_not_contain_element(self, locator, timeout=None, + error=None): + """Waits until element ``locator`` disappears from current page. - `error` can be used to override the default error message. + Fails if ``timeout`` expires before the element disappears. See + the `Timeouts` section for more information about using timeouts and + their default value and the `Locating elements` section for details + about the locator syntax. - See also `Wait Until Page Contains`, `Wait For Condition`, - `Wait Until Element Is Visible` and BuiltIn keyword `Wait Until - Keyword Succeeds`. + ``error`` can be used to override the default error message. """ self._wait_until( lambda: self.find_element(locator, required=False) is None, @@ -126,18 +112,16 @@ def wait_until_page_does_not_contain_element(self, locator, timeout=None, error= ) @keyword - def wait_until_element_is_visible(self, locator, timeout=None, error=None): - """Waits until element specified with `locator` is visible. - - Fails if `timeout` expires before the element is visible. See - `introduction` for more information about `timeout` and its - default value. + def wait_until_element_is_visible(self, locator, timeout=None, + error=None): + """Waits until element ``locator`` is visible. - `error` can be used to override the default error message. + Fails if ``timeout`` expires before the element is visible. See + the `Timeouts` section for more information about using timeouts and + their default value and the `Locating elements` section for details + about the locator syntax. - See also `Wait Until Page Contains`, `Wait Until Page Contains - Element`, `Wait For Condition` and BuiltIn keyword `Wait Until Keyword - Succeeds`. + ``error`` can be used to override the default error message. """ self._wait_until( lambda: self.find_element(locator).is_displayed(), @@ -146,18 +130,16 @@ def wait_until_element_is_visible(self, locator, timeout=None, error=None): ) @keyword - def wait_until_element_is_not_visible(self, locator, timeout=None, error=None): - """Waits until element specified with `locator` is not visible. + def wait_until_element_is_not_visible(self, locator, timeout=None, + error=None): + """Waits until element ``locator`` is not visible. - Fails if `timeout` expires before the element is not visible. See - `introduction` for more information about `timeout` and its - default value. + Fails if ``timeout`` expires before the element is not visible. See + the `Timeouts` section for more information about using timeouts and + their default value and the `Locating elements` section for details + about the locator syntax. - `error` can be used to override the default error message. - - See also `Wait Until Page Contains`, `Wait Until Page Contains - Element`, `Wait For Condition` and BuiltIn keyword `Wait Until Keyword - Succeeds`. + ``error`` can be used to override the default error message. """ self._wait_until( lambda: not self.find_element(locator).is_displayed(), @@ -166,19 +148,18 @@ def wait_until_element_is_not_visible(self, locator, timeout=None, error=None): ) @keyword - def wait_until_element_is_enabled(self, locator, timeout=None, error=None): - """Waits until element specified with `locator` is enabled. + def wait_until_element_is_enabled(self, locator, timeout=None, + error=None): + """Waits until element ``locator`` is enabled. - Fails if `timeout` expires before the element is enabled. Element - is considered enabled if it is not disabled nor read-only. - See `introduction` for more information about `timeout` and its - default value. + Element is considered enabled if it is not disabled nor read-only. - `error` can be used to override the default error message. + Fails if ``timeout`` expires before the element is enabled. See + the `Timeouts` section for more information about using timeouts and + their default value and the `Locating elements` section for details + about the locator syntax. - See also `Wait Until Page Contains`, `Wait Until Page Contains - Element`, `Wait For Condition` and BuiltIn keyword `Wait Until Keyword - Succeeds`. + ``error`` can be used to override the default error message. Considering read-only elements to be disabled is a new feature in SeleniumLibrary 3.0. @@ -190,18 +171,16 @@ def wait_until_element_is_enabled(self, locator, timeout=None, error=None): ) @keyword - def wait_until_element_contains(self, locator, text, timeout=None, error=None): - """Waits until given element contains `text`. - - Fails if `timeout` expires before the text appears on given element. See - `introduction` for more information about `timeout` and its - default value. + def wait_until_element_contains(self, locator, text, timeout=None, + error=None): + """Waits until element ``locator`` contains ``text``. - `error` can be used to override the default error message. + Fails if ``timeout`` expires before the text appears. See + the `Timeouts` section for more information about using timeouts and + their default value and the `Locating elements` section for details + about the locator syntax. - See also `Wait Until Page Contains`, `Wait Until Page Contains Element`, `Wait For Condition`, - `Wait Until Element Is Visible` and BuiltIn keyword `Wait Until - Keyword Succeeds`. + ``error`` can be used to override the default error message. """ self._wait_until( lambda: text in self.find_element(locator).text, @@ -210,18 +189,16 @@ def wait_until_element_contains(self, locator, text, timeout=None, error=None): ) @keyword - def wait_until_element_does_not_contain(self, locator, text, timeout=None, error=None): - """Waits until given element does not contain `text`. + def wait_until_element_does_not_contain(self, locator, text, timeout=None, + error=None): + """Waits until element ``locator`` does not contain ``text``. - Fails if `timeout` expires before the text disappears from given element. See - `introduction` for more information about `timeout` and its - default value. + Fails if ``timeout`` expires before the text disappears. See + the `Timeouts` section for more information about using timeouts and + their default value and the `Locating elements` section for details + about the locator syntax. - `error` can be used to override the default error message. - - See also `Wait Until Page Contains`, `Wait Until Page Contains Element`, `Wait For Condition`, - `Wait Until Element Is Visible` and BuiltIn keyword `Wait Until - Keyword Succeeds`. + ``error`` can be used to override the default error message. """ self._wait_until( lambda: text not in self.find_element(locator).text,