Skip to content

Commit 56fd06a

Browse files
Merge branch 'trunk' into firefox-entensions
2 parents 186b21b + d2ab626 commit 56fd06a

File tree

5 files changed

+103
-61
lines changed

5 files changed

+103
-61
lines changed

java/src/org/openqa/selenium/chromium/AddHasCdp.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,15 @@ public Class<HasCdp> getDescribedInterface() {
4747

4848
@Override
4949
public HasCdp getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {
50-
return new HasCdp() {
51-
@Override
52-
public Map<String, Object> executeCdpCommand(
53-
String commandName, Map<String, Object> parameters) {
54-
Require.nonNull("Command name", commandName);
55-
Require.nonNull("Parameters", parameters);
50+
return (commandName, parameters) -> {
51+
Require.nonNull("Command name", commandName);
52+
Require.nonNull("Parameters", parameters);
5653

57-
Map<String, Object> toReturn =
58-
(Map<String, Object>)
59-
executeMethod.execute(
60-
EXECUTE_CDP, Map.of("cmd", commandName, "params", parameters));
54+
Map<String, Object> toReturn =
55+
(Map<String, Object>)
56+
executeMethod.execute(EXECUTE_CDP, Map.of("cmd", commandName, "params", parameters));
6157

62-
return Map.copyOf(toReturn);
63-
}
58+
return Map.copyOf(toReturn);
6459
};
6560
}
6661
}

java/src/org/openqa/selenium/chromium/AddHasLaunchApp.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,9 @@ public Class<HasLaunchApp> getDescribedInterface() {
5757

5858
@Override
5959
public HasLaunchApp getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {
60-
return new HasLaunchApp() {
61-
@Override
62-
public void launchApp(String id) {
63-
Require.nonNull("id of Chromium App", id);
64-
65-
executeMethod.execute(LAUNCH_APP, Map.of("id", id));
66-
}
60+
return id -> {
61+
Require.nonNull("id of Chromium App", id);
62+
executeMethod.execute(LAUNCH_APP, Map.of("id", id));
6763
};
6864
}
6965
}

java/src/org/openqa/selenium/chromium/AddHasPermissions.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,11 @@ public Class<HasPermissions> getDescribedInterface() {
5757

5858
@Override
5959
public HasPermissions getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {
60-
return new HasPermissions() {
61-
@Override
62-
public void setPermission(String name, String value) {
63-
Require.nonNull("Permission name", name);
64-
Require.nonNull("Permission value", value);
65-
66-
executeMethod.execute(
67-
SET_PERMISSION, Map.of("descriptor", Map.of("name", name), "state", value));
68-
}
60+
return (name, value) -> {
61+
Require.nonNull("Permission name", name);
62+
Require.nonNull("Permission value", value);
63+
executeMethod.execute(
64+
SET_PERMISSION, Map.of("descriptor", Map.of("name", name), "state", value));
6965
};
7066
}
7167
}

java/src/org/openqa/selenium/safari/AddHasDebugger.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ public Class<HasDebugger> getDescribedInterface() {
5555

5656
@Override
5757
public HasDebugger getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {
58-
return new HasDebugger() {
59-
@Override
60-
public void attachDebugger() {
61-
executeMethod.execute(ATTACH_DEBUGGER, null);
62-
}
63-
};
58+
return () -> executeMethod.execute(ATTACH_DEBUGGER, null);
6459
}
6560
}

py/selenium/webdriver/support/wait.py

Lines changed: 87 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,29 @@ def __init__(
4848
):
4949
"""Constructor, takes a WebDriver instance and timeout in seconds.
5050
51-
:Args:
52-
- driver - Instance of WebDriver (Ie, Firefox, Chrome or Remote) or a WebElement
53-
- timeout - Number of seconds before timing out
54-
- poll_frequency - sleep interval between calls
55-
By default, it is 0.5 second.
56-
- ignored_exceptions - iterable structure of exception classes ignored during calls.
57-
By default, it contains NoSuchElementException only.
58-
59-
Example::
60-
61-
from selenium.webdriver.support.wait import WebDriverWait \n
62-
element = WebDriverWait(driver, 10).until(lambda x: x.find_element(By.ID, "someId")) \n
63-
is_disappeared = WebDriverWait(driver, 30, 1, (ElementNotVisibleException)).\\ \n
64-
until_not(lambda x: x.find_element(By.ID, "someId").is_displayed())
51+
Attributes:
52+
----------
53+
driver
54+
- Instance of WebDriver (Ie, Firefox, Chrome or Remote) or
55+
a WebElement
56+
timeout
57+
- Number of seconds before timing out
58+
poll_frequency
59+
- Sleep interval between calls
60+
- By default, it is 0.5 second.
61+
ignored_exceptions
62+
- Iterable structure of exception classes ignored during calls.
63+
- By default, it contains NoSuchElementException only.
64+
65+
Example:
66+
--------
67+
>>> from selenium.webdriver.common.by import By
68+
>>> from selenium.webdriver.support.wait import WebDriverWait
69+
>>> from selenium.common.exceptions import ElementNotVisibleException
70+
>>>
71+
>>> # Wait until the element is no longer visible
72+
>>> is_disappeared = WebDriverWait(driver, 30, 1, (ElementNotVisibleException))
73+
... .until_not(lambda x: x.find_element(By.ID, "someId").is_displayed())
6574
"""
6675
self._driver = driver
6776
self._timeout = float(timeout)
@@ -81,13 +90,39 @@ def __repr__(self):
8190
return f'<{type(self).__module__}.{type(self).__name__} (session="{self._driver.session_id}")>'
8291

8392
def until(self, method: Callable[[D], Union[Literal[False], T]], message: str = "") -> T:
84-
"""Calls the method provided with the driver as an argument until the \
93+
"""Wait until the method returns a value that is not False.
94+
95+
Calls the method provided with the driver as an argument until the
8596
return value does not evaluate to ``False``.
8697
87-
:param method: callable(WebDriver)
88-
:param message: optional message for :exc:`TimeoutException`
89-
:returns: the result of the last call to `method`
90-
:raises: :exc:`selenium.common.exceptions.TimeoutException` if timeout occurs
98+
Parameters:
99+
----------
100+
method: callable(WebDriver)
101+
- A callable object that takes a WebDriver instance as an argument.
102+
message: str
103+
- Optional message for :exc:`TimeoutException`
104+
105+
Return:
106+
-------
107+
object: T
108+
- The result of the last call to `method`
109+
110+
Raises:
111+
-------
112+
TimeoutException
113+
- If 'method' does not return a truthy value within the WebDriverWait
114+
object's timeout
115+
116+
Example:
117+
--------
118+
>>> from selenium.webdriver.common.by import By
119+
>>> from selenium.webdriver.support.ui import WebDriverWait
120+
>>> from selenium.webdriver.support import expected_conditions as EC
121+
122+
# Wait until an element is visible on the page
123+
>>> wait = WebDriverWait(driver, 10)
124+
>>> element = wait.until(EC.visibility_of_element_located((By.ID, "exampleId")))
125+
>>> print(element.text)
91126
"""
92127
screen = None
93128
stacktrace = None
@@ -107,14 +142,39 @@ def until(self, method: Callable[[D], Union[Literal[False], T]], message: str =
107142
raise TimeoutException(message, screen, stacktrace)
108143

109144
def until_not(self, method: Callable[[D], T], message: str = "") -> Union[T, Literal[True]]:
110-
"""Calls the method provided with the driver as an argument until the \
111-
return value evaluates to ``False``.
112-
113-
:param method: callable(WebDriver)
114-
:param message: optional message for :exc:`TimeoutException`
115-
:returns: the result of the last call to `method`, or
116-
``True`` if `method` has raised one of the ignored exceptions
117-
:raises: :exc:`selenium.common.exceptions.TimeoutException` if timeout occurs
145+
"""Wait until the method returns a value that is not False.
146+
147+
Calls the method provided with the driver as an argument until the
148+
return value does not evaluate to ``False``.
149+
150+
Parameters:
151+
----------
152+
method: callable(WebDriver)
153+
- A callable object that takes a WebDriver instance as an argument.
154+
message: str
155+
- Optional message for :exc:`TimeoutException`
156+
157+
Return:
158+
-------
159+
object: T
160+
- The result of the last call to `method`
161+
162+
Raises:
163+
-------
164+
TimeoutException
165+
- If 'method' does not return False within the WebDriverWait
166+
object's timeout
167+
168+
Example:
169+
--------
170+
>>> from selenium.webdriver.common.by import By
171+
>>> from selenium.webdriver.support.ui import WebDriverWait
172+
>>> from selenium.webdriver.support import expected_conditions as EC
173+
174+
# Wait until an element is visible on the page
175+
>>> wait = WebDriverWait(driver, 10)
176+
>>> is_disappeared = wait.until_not(EC.visibility_of_element_located(
177+
... (By.ID, "exampleId")))
118178
"""
119179
end_time = time.monotonic() + self._timeout
120180
while True:

0 commit comments

Comments
 (0)