SeleniumLibrary icon indicating copy to clipboard operation
SeleniumLibrary copied to clipboard

Incorporate the expected conditions of Selenium

Open emanlove opened this issue 2 years ago • 4 comments

There is now a a variety of conditions that Selenium can either wait for, get, or check against. The idea is that we can create a small set of generic keywords, maybe

Wait Until Element State Is (Not) Get Element State Element States Should (Not) Be

which allows for one to wait for, get, or check against the element state. There is also capability to create a custom condition within selenium that could be incorporated into the library and these keywords. As for names maybe condition or expected condition might be better as not all object to be checked I suspect would be an element.

Although not part of this issue, it may be worth starting to have a conversation around whether or not these keywords might allow for reducing the number of library keywords and deprecating the "Wait For ..." keywords.

Related Issues:

Add new selenium 4 timeout getters #1825 Add keywords for dealing with stale elements #1767 Add "Wait for DOM inactivity" keyword which waits until page is fully loaded/rendered #1764 New Keyword 'Element Attriubte Should Contain' #1129 New Keyword 'Wait Until Element Contains attribute' #1126 How we can deal with stale element reference with selenium libray?We need a keyword to deal with stale element reference #1792 Add "Wait for DOM inactivity" keyword which waits until page is fully loaded/rendered #1764 Wait For Condition and Title Should Be seem to be out of sync #1728 Provide support for waiting for a value in a textarea element #1726 Add parameter to make Wait Until Page Contains case insensitive #1517 Wait until does not contain element always waits for full amount of wait time #1364

References:

selenium.webdriver.support.expected_conditions within API Example implementation

emanlove avatar May 18 '23 00:05 emanlove

Some of my initial notes on (what I was originally calling) Wait For Condition

  • Can we allow the user to use the same name (ie element_to_be_clickable ,text_to_be_present_in_element, etc) so that the conditions aren't hard coded within the library? so that as the conditions change with selenium we don't need to change the code in the library? How do we then allow for arguments and type check them? or provide type hints?
  • How do we check for the positive or the negative? is it just a true false check? Can there be just a single negative keyword and what do we call it - Wait till Condition Not ?
  • How do we allow for custom condition? Can the custom condition have the same name as another? if so how do we give precedence or warn that there are more than one with that name?
  • How do we open up these waits and conditions to the library API for usage throughout or within plug-ins?

emanlove avatar May 18 '23 02:05 emanlove

Some more notes from conversation with Lisa Crispin (@lisacrispin)

  • Is there a way to have "and", "or" type conjunctions/logic with the conditions?
  • "Make it positive" - Lisa has a great point about making one's statements in the positive and avoiding double negatives.

emanlove avatar Jun 09 '23 17:06 emanlove

Making a list of task to be done to complete this work .. (this is a work in progress and subject to change)

Design

  • [ ] Categorize conditions (would be nice if shared back to selenium API doc)
  • [ ] Sketch out test cases
  • [ ] Sketch out keyword usage (in particular ALL, ANY, XOR)
  • [ ] Sketch out mapping conditions to keywords
  • [ ] Sketch out error message and debug/trace level debugging
  • [ ] Review duplicate/related issues within GitHub

Development

  • [ ] Create Dynamic Test Page
  • [ ] Create Static Test Page
  • [ ] Create 'Wait Until Element State Is (Not)' keyword
  • [ ] Create 'Get Element State' keyword
  • [ ] Create 'Element States Should (Not) Be' keyword
  • [ ] Review duplicate/related issues within GitHub

Document & Cleanup

  • [ ] Document keyword usage
  • [ ] Document to be done (custom conditions)

emanlove avatar Nov 10 '23 14:11 emanlove

I added this comment to the #1865 PR, but add them here as well for possible discussion:

some brainstorming:
wait_for_expected_condition should take the following arguments:

condition (condition=)
timeout (timeout=)
msg (msg=custom message)
arguments (arguments for the condition, depending on the condition this can be a String, WebElement, List)
One (to me) "strange" expectedcondition is "new_window_is_opened". Does this one implicitly add the current number of windows?

Example use of keyword: ${result} Wait for Expected Condition timeout=50ms condition=title_is msg=title did not change title

yuriverweij avatar Nov 14 '23 08:11 yuriverweij

Fixed in #1865

emanlove avatar Apr 16 '24 11:04 emanlove