Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expected conditions 1827 #1865

Merged
merged 24 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5a6735c
Sketching out initial ideas for test suite on expected conditions
emanlove Jun 9, 2023
583c9e6
Added dynamic and delayed title change as initial test framework for
emanlove Nov 11, 2023
fc60e23
Merge branch 'master' into add-expected-conditions-1827
emanlove Nov 11, 2023
2b10abf
Initial (working) prototype of wait for.. keyword
emanlove Nov 11, 2023
eb49c98
Bumped number of library keywords by one
emanlove Nov 11, 2023
129e9b0
Moved previous expected condition tests out of current test suite
emanlove Nov 11, 2023
36e7da3
Adding another sample tests and modifying keyword behavior
emanlove Nov 11, 2023
48376f7
Added sample test case where an expected timeout would occur
emanlove Nov 11, 2023
3083459
added timeout argument to keyword wait_for_expected_condition
yuriverweij Nov 15, 2023
754e793
Merge pull request #3 from yuriverweij/feature/add_expected_condition…
emanlove Nov 22, 2023
98d8f89
Some intial parsing and validation for parsing condition argument
emanlove Nov 22, 2023
7ad5296
Basic working keyword for wait
emanlove Jan 18, 2024
b022031
Added test case for capitals within expected condition name
emanlove Jan 19, 2024
d23700e
Added example test where expected condition expected "locator" tuple
emanlove Jan 21, 2024
7bdca3c
Added keyword documentation for new `Wait For Expected Condition` key…
emanlove Mar 26, 2024
bd05dfd
Merge branch 'master' into add-expected-conditions-1827
emanlove Mar 26, 2024
fd751bb
Fix Firefox unit tests
emanlove Apr 2, 2024
204ceda
Reduced the timeout on the expected timeout within expected conditions
emanlove Apr 2, 2024
e1a4f4c
Expanded selenium versions upto 4.19.0
emanlove Apr 3, 2024
f17f8f0
Fix acceptance tests
emanlove Apr 5, 2024
de1a4fb
Append results to zip file
emanlove Apr 5, 2024
8db00db
Added selenium version and browser name to archive
emanlove Apr 14, 2024
a0e241d
Upload only failed artifacts
emanlove Apr 14, 2024
cc41bc1
Updated some expected log messages in chrome tests
emanlove Apr 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions atest/acceptance/expected_conditions.robot.PROTOTYPE
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
*** Test Cases ***
# Wait Until Element State Is (Not)
# Get Element State
# Element States Should (Not) Be

Check waiting for condition that takes a element
Fail

Check waiting for condition that takes a title
Fail

Check waiting for condition that takes a url
Fail
Wait Until url contains google
# verify took 2 seconds

Check waiting for condition that takes locator and string
Wait Until Element State Is ${condition} ${locator} ${string}
Wait Until Element State Is ${condition} ${element}
Wait Until Condition Is ${condition} ${target}
Wait Until Condition Is ${condition} ${whatelse you need for this condition}


Wait Until State Is number_of_windows_to_be
Wait Until Expected Condition Is number_of_windows_to_be
Wait Until Condition Is number of windows to be 5
Wait Until Condition Is text to be present in element attribute //some/xpath/to/an/element href http://hello

Wait Until Condition Is number of windows to be 5 text to be present in element attribute //some/xpath/to/an/element href http://hello

Wait Until number of windows to be 5
Wait Until text to be present in element attribute //some/xpath/to/an/element href http://hello
Get Condition
Is number of windows to be 5
21 changes: 21 additions & 0 deletions atest/acceptance/keywords/expected_conditions.robot
emanlove marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
*** Settings ***
Test Setup Go To Page "javascript/expected_conditions.html"
Resource ../resource.robot

*** Test Cases ***
Wait For Expected Conditions One Argument
Title Should Be Original
Click Element link=delayed change title
Wait For Expected Condition title_is Delayed
emanlove marked this conversation as resolved.
Show resolved Hide resolved
Title Should Be Delayed

Wait For Expected Condition Times out
Title Should Be Original
Click Element link=delayed change title
Wait For Expected Condition title_is Foo
# Verify failure

Wait For Expected Conditions using WebElement as locator
Click Button Change the button state
${dynamic_btn}= Get WebElement id:enabledDisabledBtn
Wait For Expected Condition element_to_be_clickable ${dynamic_btn}
7 changes: 7 additions & 0 deletions atest/resources/html/javascript/dynamic_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@
container = document.getElementById(target_container);
container.appendChild(p);
}

function delayed_title_change() {
setTimeout(function(){
document.title='Delayed';
},600);
}
</script>
</head>
<body>
<a href="javascript:return false;" onclick="document.title='Changed'; return false;">change title</a><br/>
<a href="javascript:return false;" onclick="delayed_title_change(); return false;">delayed change title</a><br/>
<a href="javascript:return false;" onclick="add_content('target', 'added content'); return false;">add content</a><br/>
<a id="unicode" href="javascript:return false;" onclick="document.title='äää'; return false;">title to ääää</a><br/>
<p>
Expand Down
72 changes: 72 additions & 0 deletions atest/resources/html/javascript/expected_conditions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Original</title>
<script type="text/javascript">
function add_content(target_container, content) {
p = document.createElement('p');
p.appendChild(document.createTextNode(content));
container = document.getElementById(target_container);
container.appendChild(p);
}

function delayed_button_state() {
setTimeout(function() {
state_btn = document.getElementById('enabledDisabledBtn')
if (state_btn.hasAttribute("disabled")) {
state_btn.removeAttribute("disabled")
state_btn.value = "Enabled"
} else {
state_btn.setAttribute("disabled", "")
state_btn.value = "Disabled"
}
},900)
}
function delayed_title_change() {
setTimeout(function(){
document.title='Delayed';
},600);
}
</script>
</head>
<body>
<a href="javascript:return false;" onclick="document.title='Changed'; return false;">change title</a><br/>
<a href="javascript:return false;" onclick="delayed_title_change(); return false;">delayed change title</a><br/>
<a href="javascript:return false;" onclick="add_content('target', 'added content'); return false;">add content</a><br/>
<a id="unicode" href="javascript:return false;" onclick="document.title='äää'; return false;">title to ääää</a><br/>
<p>
<input type="radio" name="group" value="title"
onclick="document.title='Changed by Button';" />Change Title<br/>
<input type="radio" name="group" value="content"
onclick="add_content('button_target', 'added by button');"/>Add Content<br/>
</p>
<div id="target">
</div>
<div id="button_target">
</div>
<form name=myform>
<input type=button value="Change the title"
onClick="if(confirm('Really change the title?'))
document.title += ' Changed!';" >
</form>
<p>
<input type=button id=stateChangeBtn value="Change the button state"
onClick="delayed_button_state()" />
<input type=button id=enabledDisabledBtn value="Disabled"
disabled />
</p>
<p>
<form name=titleChanger>
<td>
<input type=text id=titleChangeTxt value="Enter Title here">
</td>
<td>
<input type=button id=titleChangeBtn value="Set Title"
onClick="document.title = document.getElementById('titleChangeTxt').value;" >
</td>
</form>
</p>
</body>
</html>

2 changes: 2 additions & 0 deletions src/SeleniumLibrary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
BrowserManagementKeywords,
CookieKeywords,
ElementKeywords,
ExpectedConditionKeywords,
FormElementKeywords,
FrameKeywords,
JavaScriptKeywords,
Expand Down Expand Up @@ -490,6 +491,7 @@ def __init__(
BrowserManagementKeywords(self),
CookieKeywords(self),
ElementKeywords(self),
ExpectedConditionKeywords(self),
FormElementKeywords(self),
FrameKeywords(self),
JavaScriptKeywords(self),
Expand Down
1 change: 1 addition & 0 deletions src/SeleniumLibrary/keywords/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from .browsermanagement import BrowserManagementKeywords # noqa
from .cookie import CookieKeywords # noqa
from .element import ElementKeywords # noqa
from .expectedconditions import ExpectedConditionKeywords # noqa
from .formelement import FormElementKeywords # noqa
from .frames import FrameKeywords # noqa
from .javascript import JavaScriptKeywords # noqa
Expand Down
25 changes: 25 additions & 0 deletions src/SeleniumLibrary/keywords/expectedconditions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2016- Robot Framework Foundation
yuriverweij marked this conversation as resolved.
Show resolved Hide resolved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from SeleniumLibrary.base import LibraryComponent, keyword
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class ExpectedConditionKeywords(LibraryComponent):
@keyword
def wait_for_expected_condition(self, condition, *args):
emanlove marked this conversation as resolved.
Show resolved Hide resolved
wait = WebDriverWait(self.driver, 10, 0.1)
# import sys,pdb;pdb.Pdb(stdout=sys.__stdout__).set_trace()
c = getattr(EC, condition)
wait.until(c(*args))
emanlove marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion utest/test/api/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setUpClass(cls):
def test_no_libraries(self):
for item in [None, "None", ""]:
sl = SeleniumLibrary(plugins=item)
self.assertEqual(len(sl.get_keyword_names()), 177)
self.assertEqual(len(sl.get_keyword_names()), 178)

def test_parse_library(self):
plugin = "path.to.MyLibrary"
Expand Down
Loading