Skip to content

Commit bb2c2f3

Browse files
authored
Merge pull request #614 from seleniumbase/better-error-messages
Improve error messages, and more
2 parents 74f9a65 + 962d6fc commit bb2c2f3

File tree

7 files changed

+50
-17
lines changed

7 files changed

+50
-17
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ coverage==5.2
4242
pyotp==2.3.0
4343
boto==2.49.0
4444
cffi==1.14.0
45-
rich==3.0.3;python_version>="3.6" and python_version<"4.0"
45+
rich==3.0.5;python_version>="3.6" and python_version<"4.0"
4646
flake8==3.7.9;python_version<"3.5"
4747
flake8==3.8.3;python_version>="3.5"
4848
pyflakes==2.1.1;python_version<"3.5"

seleniumbase/fixtures/page_actions.py

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ def wait_for_element_present(driver, selector, by=By.CSS_SELECTOR,
217217
timeout=settings.LARGE_TIMEOUT):
218218
"""
219219
Searches for the specified element by the given selector. Returns the
220-
element object if the element is present on the page. The element can be
221-
invisible. Raises an exception if the element does not appear in the
222-
specified timeout.
220+
element object if it exists in the HTML. (The element can be invisible.)
221+
Raises NoSuchElementException if the element does not exist in the HTML
222+
within the specified timeout.
223223
@Params
224224
driver - the webdriver object
225225
selector - the locator for identifying the page element (required)
@@ -256,24 +256,27 @@ def wait_for_element_visible(driver, selector, by=By.CSS_SELECTOR,
256256
"""
257257
Searches for the specified element by the given selector. Returns the
258258
element object if the element is present and visible on the page.
259-
Raises an exception if the element does not appear in the
260-
specified timeout.
259+
Raises NoSuchElementException if the element does not exist in the HTML
260+
within the specified timeout.
261+
Raises ElementNotVisibleException if the element exists in the HTML,
262+
but is not visible (eg. opacity is "0") within the specified timeout.
261263
@Params
262264
driver - the webdriver object (required)
263265
selector - the locator for identifying the page element (required)
264266
by - the type of selector being used (Default: By.CSS_SELECTOR)
265267
timeout - the time to wait for elements in seconds
266-
267268
@Returns
268269
A web element object
269270
"""
270271
element = None
272+
is_present = False
271273
start_ms = time.time() * 1000.0
272274
stop_ms = start_ms + (timeout * 1000.0)
273275
for x in range(int(timeout * 10)):
274276
s_utils.check_if_time_limit_exceeded()
275277
try:
276278
element = driver.find_element(by=by, value=selector)
279+
is_present = True
277280
if element.is_displayed():
278281
return element
279282
else:
@@ -288,6 +291,13 @@ def wait_for_element_visible(driver, selector, by=By.CSS_SELECTOR,
288291
if timeout == 1:
289292
plural = ""
290293
if not element and by != By.LINK_TEXT:
294+
if not is_present:
295+
# The element does not exist in the HTML
296+
message = (
297+
"Element {%s} was not present after %s second%s!"
298+
"" % (selector, timeout, plural))
299+
timeout_exception(NoSuchElementException, message)
300+
# The element exists in the HTML, but is not visible
291301
message = (
292302
"Element {%s} was not visible after %s second%s!"
293303
"" % (selector, timeout, plural))
@@ -304,8 +314,11 @@ def wait_for_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
304314
"""
305315
Searches for the specified element by the given selector. Returns the
306316
element object if the text is present in the element and visible
307-
on the page. Raises an exception if the text or element do not appear
308-
in the specified timeout.
317+
on the page.
318+
Raises NoSuchElementException if the element does not exist in the HTML
319+
within the specified timeout.
320+
Raises ElementNotVisibleException if the element exists in the HTML,
321+
but the text is not visible within the specified timeout.
309322
@Params
310323
driver - the webdriver object (required)
311324
text - the text that is being searched for in the element (required)
@@ -316,12 +329,14 @@ def wait_for_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
316329
A web element object that contains the text searched for
317330
"""
318331
element = None
332+
is_present = False
319333
start_ms = time.time() * 1000.0
320334
stop_ms = start_ms + (timeout * 1000.0)
321335
for x in range(int(timeout * 10)):
322336
s_utils.check_if_time_limit_exceeded()
323337
try:
324338
element = driver.find_element(by=by, value=selector)
339+
is_present = True
325340
if element.is_displayed() and text in element.text:
326341
return element
327342
else:
@@ -336,6 +351,13 @@ def wait_for_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
336351
if timeout == 1:
337352
plural = ""
338353
if not element:
354+
if not is_present:
355+
# The element does not exist in the HTML
356+
message = (
357+
"Element {%s} was not present after %s second%s!"
358+
"" % (selector, timeout, plural))
359+
timeout_exception(NoSuchElementException, message)
360+
# The element exists in the HTML, but the text is not visible
339361
message = (
340362
"Expected text {%s} for {%s} was not visible after %s second%s!"
341363
"" % (text, selector, timeout, plural))
@@ -348,8 +370,10 @@ def wait_for_exact_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
348370
Searches for the specified element by the given selector. Returns the
349371
element object if the text matches exactly with the text in the element,
350372
and the text is visible.
351-
Raises an exception if the text or element do not appear
352-
in the specified timeout.
373+
Raises NoSuchElementException if the element does not exist in the HTML
374+
within the specified timeout.
375+
Raises ElementNotVisibleException if the element exists in the HTML,
376+
but the exact text is not visible within the specified timeout.
353377
@Params
354378
driver - the webdriver object (required)
355379
text - the exact text that is expected for the element (required)
@@ -360,12 +384,14 @@ def wait_for_exact_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
360384
A web element object that contains the text searched for
361385
"""
362386
element = None
387+
is_present = False
363388
start_ms = time.time() * 1000.0
364389
stop_ms = start_ms + (timeout * 1000.0)
365390
for x in range(int(timeout * 10)):
366391
s_utils.check_if_time_limit_exceeded()
367392
try:
368393
element = driver.find_element(by=by, value=selector)
394+
is_present = True
369395
if element.is_displayed() and text.strip() == element.text.strip():
370396
return element
371397
else:
@@ -380,6 +406,13 @@ def wait_for_exact_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
380406
if timeout == 1:
381407
plural = ""
382408
if not element:
409+
if not is_present:
410+
# The element does not exist in the HTML
411+
message = (
412+
"Element {%s} was not present after %s second%s!"
413+
"" % (selector, timeout, plural))
414+
timeout_exception(NoSuchElementException, message)
415+
# The element exists in the HTML, but the exact text is not visible
383416
message = (
384417
"Expected exact text {%s} for {%s} was not visible "
385418
"after %s second%s!" % (text, selector, timeout, plural))

seleniumbase/utilities/selenium_grid/grid-hub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ if [ "$GRID_HUB_VERBOSE_LOGS" == "True" ]; then
3434
fi
3535

3636
WEBDRIVER_SERVER_JAR=${DIR}/selenium-server-standalone.jar
37-
WEBDRIVER_HUB_PARAMS="-role hub -timeout 180 -browserTimeout 75 -port 4444"
37+
WEBDRIVER_HUB_PARAMS="-role hub -timeout 230 -browserTimeout 170 -port 4444"
3838
WEBDRIVER_HUB_PIDFILE="/tmp/webdriver_hub.pid"
3939

4040
if [ ! -f $WEBDRIVER_SERVER_JAR ]; then

seleniumbase/utilities/selenium_grid/grid_hub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def main():
8181
if grid_hub_command == "start" or grid_hub_command == "restart":
8282
shell_command = (
8383
"""java -jar %s/selenium-server-standalone.jar -role hub """
84-
"""-timeout 180 -browserTimeout 75 -port 4444""" % dir_path)
84+
"""-timeout 230 -browserTimeout 170 -port 4444""" % dir_path)
8585
print("\nStarting Selenium-WebDriver Grid Hub...\n")
8686
print(shell_command)
8787
print("")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
java -jar selenium-server-standalone.jar -role hub -timeout 180 -browserTimeout 75 -port 4444
1+
java -jar selenium-server-standalone.jar -role hub -timeout 230 -browserTimeout 170 -port 4444
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
java -jar selenium-server-standalone.jar -role hub -timeout 180 -browserTimeout 75 -port 4444
2+
java -jar selenium-server-standalone.jar -role hub -timeout 230 -browserTimeout 170 -port 4444

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
setup(
5656
name='seleniumbase',
57-
version='1.42.5',
57+
version='1.42.6',
5858
description='Fast, Easy, and Reliable Browser Automation & Testing.',
5959
long_description=long_description,
6060
long_description_content_type='text/markdown',
@@ -134,7 +134,7 @@
134134
'pyotp==2.3.0',
135135
'boto==2.49.0',
136136
'cffi==1.14.0',
137-
'rich==3.0.3;python_version>="3.6" and python_version<"4.0"',
137+
'rich==3.0.5;python_version>="3.6" and python_version<"4.0"',
138138
'flake8==3.7.9;python_version<"3.5"',
139139
'flake8==3.8.3;python_version>="3.5"',
140140
'pyflakes==2.1.1;python_version<"3.5"',

0 commit comments

Comments
 (0)