seleniumbase 4.16.2__py3-none-any.whl → 4.16.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sbase/steps.py +65 -0
- seleniumbase/__version__.py +1 -1
- seleniumbase/behave/behave_helper.py +29 -1
- seleniumbase/common/exceptions.py +6 -1
- seleniumbase/console_scripts/sb_install.py +18 -4
- seleniumbase/core/browser_launcher.py +63 -8
- seleniumbase/core/recorder_helper.py +29 -1
- seleniumbase/fixtures/base_case.py +238 -10
- seleniumbase/fixtures/page_actions.py +131 -4
- seleniumbase/fixtures/shared_utils.py +5 -0
- seleniumbase/fixtures/words.py +15 -1
- seleniumbase/translate/chinese.py +4 -0
- seleniumbase/translate/dutch.py +4 -0
- seleniumbase/translate/french.py +4 -0
- seleniumbase/translate/italian.py +4 -0
- seleniumbase/translate/japanese.py +4 -0
- seleniumbase/translate/korean.py +4 -0
- seleniumbase/translate/master_dict.py +25 -0
- seleniumbase/translate/portuguese.py +4 -0
- seleniumbase/translate/russian.py +4 -0
- seleniumbase/translate/spanish.py +4 -0
- seleniumbase/undetected/patcher.py +5 -0
- {seleniumbase-4.16.2.dist-info → seleniumbase-4.16.3.dist-info}/METADATA +45 -45
- {seleniumbase-4.16.2.dist-info → seleniumbase-4.16.3.dist-info}/RECORD +28 -28
- {seleniumbase-4.16.2.dist-info → seleniumbase-4.16.3.dist-info}/WHEEL +1 -1
- {seleniumbase-4.16.2.dist-info → seleniumbase-4.16.3.dist-info}/LICENSE +0 -0
- {seleniumbase-4.16.2.dist-info → seleniumbase-4.16.3.dist-info}/entry_points.txt +0 -0
- {seleniumbase-4.16.2.dist-info → seleniumbase-4.16.3.dist-info}/top_level.txt +0 -0
@@ -1342,6 +1342,18 @@ class BaseCase(unittest.TestCase):
|
|
1342
1342
|
self.driver, text, selector, by, self.browser
|
1343
1343
|
)
|
1344
1344
|
|
1345
|
+
def is_non_empty_text_visible(self, selector="html", by="css selector"):
|
1346
|
+
"""Returns whether the element has any non-empty text visible.
|
1347
|
+
Whitespace-only text is considered empty text."""
|
1348
|
+
self.wait_for_ready_state_complete()
|
1349
|
+
time.sleep(0.01)
|
1350
|
+
selector, by = self.__recalculate_selector(selector, by)
|
1351
|
+
if self.__is_shadow_selector(selector):
|
1352
|
+
return self.__is_shadow_non_empty_text_visible(selector)
|
1353
|
+
return page_actions.is_non_empty_text_visible(
|
1354
|
+
self.driver, selector, by=by
|
1355
|
+
)
|
1356
|
+
|
1345
1357
|
def is_attribute_present(
|
1346
1358
|
self, selector, attribute, value=None, by="css selector"
|
1347
1359
|
):
|
@@ -1450,9 +1462,8 @@ class BaseCase(unittest.TestCase):
|
|
1450
1462
|
else:
|
1451
1463
|
return None
|
1452
1464
|
if hard_fail:
|
1453
|
-
|
1454
|
-
|
1455
|
-
)
|
1465
|
+
msg = "Partial Link text {%s} was not found!" % link_text
|
1466
|
+
page_actions.timeout_exception("LinkTextNotFoundException", msg)
|
1456
1467
|
else:
|
1457
1468
|
return None
|
1458
1469
|
|
@@ -4826,6 +4837,7 @@ class BaseCase(unittest.TestCase):
|
|
4826
4837
|
ext_actions.append("astnv")
|
4827
4838
|
ext_actions.append("aetnv")
|
4828
4839
|
ext_actions.append("as_et")
|
4840
|
+
ext_actions.append("asnet")
|
4829
4841
|
ext_actions.append("wf_el")
|
4830
4842
|
ext_actions.append("sw_fr")
|
4831
4843
|
ext_actions.append("sw_dc")
|
@@ -4852,6 +4864,7 @@ class BaseCase(unittest.TestCase):
|
|
4852
4864
|
ext_actions.append("da_ep")
|
4853
4865
|
ext_actions.append("da_te")
|
4854
4866
|
ext_actions.append("da_et")
|
4867
|
+
ext_actions.append("danet")
|
4855
4868
|
ext_actions.append("pr_da")
|
4856
4869
|
for n in range(len(srt_actions)):
|
4857
4870
|
if srt_actions[n][0] in ext_actions:
|
@@ -8200,6 +8213,15 @@ class BaseCase(unittest.TestCase):
|
|
8200
8213
|
original_selector=original_selector,
|
8201
8214
|
)
|
8202
8215
|
|
8216
|
+
def assert_link(self, link_text, timeout=None):
|
8217
|
+
"""Same as self.assert_link_text()"""
|
8218
|
+
self.__check_scope()
|
8219
|
+
if not timeout:
|
8220
|
+
timeout = settings.SMALL_TIMEOUT
|
8221
|
+
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
|
8222
|
+
timeout = self.__get_new_timeout(timeout)
|
8223
|
+
self.assert_link_text(link_text, timeout=timeout)
|
8224
|
+
|
8203
8225
|
def assert_element_not_present(
|
8204
8226
|
self, selector, by="css selector", timeout=None
|
8205
8227
|
):
|
@@ -8832,6 +8854,27 @@ class BaseCase(unittest.TestCase):
|
|
8832
8854
|
self.driver, text, selector, by, timeout, self.browser
|
8833
8855
|
)
|
8834
8856
|
|
8857
|
+
def wait_for_non_empty_text_visible(
|
8858
|
+
self, selector="html", by="css selector", timeout=None
|
8859
|
+
):
|
8860
|
+
"""Searches for any text in the element of the given selector.
|
8861
|
+
Returns the element if it has visible text within the timeout.
|
8862
|
+
Raises an exception if the element has no text within the timeout.
|
8863
|
+
Whitespace-only text is considered empty text."""
|
8864
|
+
self.__check_scope()
|
8865
|
+
if not timeout:
|
8866
|
+
timeout = settings.LARGE_TIMEOUT
|
8867
|
+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
|
8868
|
+
timeout = self.__get_new_timeout(timeout)
|
8869
|
+
selector, by = self.__recalculate_selector(selector, by)
|
8870
|
+
if self.__is_shadow_selector(selector):
|
8871
|
+
return self.__wait_for_non_empty_shadow_text_visible(
|
8872
|
+
selector, timeout
|
8873
|
+
)
|
8874
|
+
return page_actions.wait_for_non_empty_text_visible(
|
8875
|
+
self.driver, selector, by=by, timeout=timeout
|
8876
|
+
)
|
8877
|
+
|
8835
8878
|
def wait_for_text(
|
8836
8879
|
self, text, selector="html", by="css selector", timeout=None
|
8837
8880
|
):
|
@@ -8858,6 +8901,19 @@ class BaseCase(unittest.TestCase):
|
|
8858
8901
|
text, selector, by=by, timeout=timeout
|
8859
8902
|
)
|
8860
8903
|
|
8904
|
+
def wait_for_non_empty_text(
|
8905
|
+
self, selector="html", by="css selector", timeout=None
|
8906
|
+
):
|
8907
|
+
"""The shorter version of wait_for_non_empty_text_visible()"""
|
8908
|
+
self.__check_scope()
|
8909
|
+
if not timeout:
|
8910
|
+
timeout = settings.LARGE_TIMEOUT
|
8911
|
+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
|
8912
|
+
timeout = self.__get_new_timeout(timeout)
|
8913
|
+
return self.wait_for_non_empty_text_visible(
|
8914
|
+
selector, by=by, timeout=timeout
|
8915
|
+
)
|
8916
|
+
|
8861
8917
|
def find_text(
|
8862
8918
|
self, text, selector="html", by="css selector", timeout=None
|
8863
8919
|
):
|
@@ -8884,6 +8940,19 @@ class BaseCase(unittest.TestCase):
|
|
8884
8940
|
text, selector, by=by, timeout=timeout
|
8885
8941
|
)
|
8886
8942
|
|
8943
|
+
def find_non_empty_text(
|
8944
|
+
self, selector="html", by="css selector", timeout=None
|
8945
|
+
):
|
8946
|
+
"""Same as wait_for_non_empty_text_visible() - returns the element"""
|
8947
|
+
self.__check_scope()
|
8948
|
+
if not timeout:
|
8949
|
+
timeout = settings.LARGE_TIMEOUT
|
8950
|
+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
|
8951
|
+
timeout = self.__get_new_timeout(timeout)
|
8952
|
+
return self.wait_for_non_empty_text_visible(
|
8953
|
+
selector, by=by, timeout=timeout
|
8954
|
+
)
|
8955
|
+
|
8887
8956
|
def assert_text_visible(
|
8888
8957
|
self, text, selector="html", by="css selector", timeout=None
|
8889
8958
|
):
|
@@ -8988,6 +9057,48 @@ class BaseCase(unittest.TestCase):
|
|
8988
9057
|
self.__extra_actions.append(action)
|
8989
9058
|
return True
|
8990
9059
|
|
9060
|
+
def assert_non_empty_text(
|
9061
|
+
self, selector="html", by="css selector", timeout=None
|
9062
|
+
):
|
9063
|
+
"""Assert that the element has any non-empty text visible.
|
9064
|
+
Raises an exception if the element has no text within the timeout.
|
9065
|
+
Whitespace-only text is considered empty text."""
|
9066
|
+
self.__check_scope()
|
9067
|
+
if not timeout:
|
9068
|
+
timeout = settings.SMALL_TIMEOUT
|
9069
|
+
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
|
9070
|
+
timeout = self.__get_new_timeout(timeout)
|
9071
|
+
original_selector = selector
|
9072
|
+
selector, by = self.__recalculate_selector(selector, by)
|
9073
|
+
if self.__is_shadow_selector(selector):
|
9074
|
+
self.__assert_non_empty_shadow_text_visible(selector, timeout)
|
9075
|
+
return True
|
9076
|
+
self.wait_for_non_empty_text_visible(selector, by=by, timeout=timeout)
|
9077
|
+
if self.demo_mode:
|
9078
|
+
a_t = "ASSERT NON-EMPTY TEXT"
|
9079
|
+
i_n = "in"
|
9080
|
+
if self._language != "English":
|
9081
|
+
from seleniumbase.fixtures.words import SD
|
9082
|
+
|
9083
|
+
a_t = SD.translate_assert_non_empty_text(self._language)
|
9084
|
+
i_n = SD.translate_in(self._language)
|
9085
|
+
messenger_post = "<b>%s</b> %s %s: %s" % (
|
9086
|
+
a_t,
|
9087
|
+
i_n,
|
9088
|
+
by.upper(),
|
9089
|
+
selector,
|
9090
|
+
)
|
9091
|
+
self.__highlight_with_assert_success(messenger_post, selector, by)
|
9092
|
+
if self.recorder_mode and self.__current_url_is_recordable():
|
9093
|
+
if self.get_session_storage_item("pause_recorder") == "no":
|
9094
|
+
if by == By.XPATH:
|
9095
|
+
selector = original_selector
|
9096
|
+
time_stamp = self.execute_script("return Date.now();")
|
9097
|
+
origin = self.get_origin()
|
9098
|
+
action = ["asnet", selector, origin, time_stamp]
|
9099
|
+
self.__extra_actions.append(action)
|
9100
|
+
return True
|
9101
|
+
|
8991
9102
|
############
|
8992
9103
|
|
8993
9104
|
def wait_for_link_text_present(self, link_text, timeout=None):
|
@@ -9009,11 +9120,11 @@ class BaseCase(unittest.TestCase):
|
|
9009
9120
|
if now_ms >= stop_ms:
|
9010
9121
|
break
|
9011
9122
|
time.sleep(0.2)
|
9012
|
-
message = "Link text {%s} was not
|
9123
|
+
message = "Link text {%s} was not found after %s seconds!" % (
|
9013
9124
|
link_text,
|
9014
9125
|
timeout,
|
9015
9126
|
)
|
9016
|
-
page_actions.timeout_exception("
|
9127
|
+
page_actions.timeout_exception("LinkTextNotFoundException", message)
|
9017
9128
|
|
9018
9129
|
def wait_for_partial_link_text_present(self, link_text, timeout=None):
|
9019
9130
|
self.__check_scope()
|
@@ -9035,10 +9146,10 @@ class BaseCase(unittest.TestCase):
|
|
9035
9146
|
break
|
9036
9147
|
time.sleep(0.2)
|
9037
9148
|
message = (
|
9038
|
-
"Partial Link text {%s} was not
|
9149
|
+
"Partial Link text {%s} was not found after %s seconds!"
|
9039
9150
|
"" % (link_text, timeout)
|
9040
9151
|
)
|
9041
|
-
page_actions.timeout_exception("
|
9152
|
+
page_actions.timeout_exception("LinkTextNotFoundException", message)
|
9042
9153
|
|
9043
9154
|
def wait_for_link_text_visible(self, link_text, timeout=None):
|
9044
9155
|
self.__check_scope()
|
@@ -10121,6 +10232,49 @@ class BaseCase(unittest.TestCase):
|
|
10121
10232
|
self.__add_deferred_assert_failure(fs=fs)
|
10122
10233
|
return False
|
10123
10234
|
|
10235
|
+
def deferred_assert_non_empty_text(
|
10236
|
+
self,
|
10237
|
+
selector="html",
|
10238
|
+
by="css selector",
|
10239
|
+
timeout=None,
|
10240
|
+
fs=False,
|
10241
|
+
):
|
10242
|
+
"""A non-terminating assertion for non-empty element text.
|
10243
|
+
Failures will be saved until the process_deferred_asserts()
|
10244
|
+
method is called from inside a test, likely at the end of it.
|
10245
|
+
If "fs" is set to True, a failure screenshot is saved to the
|
10246
|
+
"latest_logs/" folder for that assertion failure. Otherwise,
|
10247
|
+
only the last page screenshot is taken for all failures when
|
10248
|
+
calling the process_deferred_asserts() method."""
|
10249
|
+
self.__check_scope()
|
10250
|
+
if not timeout:
|
10251
|
+
timeout = settings.MINI_TIMEOUT
|
10252
|
+
if self.timeout_multiplier and timeout == settings.MINI_TIMEOUT:
|
10253
|
+
timeout = self.__get_new_timeout(timeout)
|
10254
|
+
self.__deferred_assert_count += 1
|
10255
|
+
try:
|
10256
|
+
url = self.get_current_url()
|
10257
|
+
if url == self.__last_url_of_deferred_assert:
|
10258
|
+
timeout = 0.6 # Was already on page (full wait not needed)
|
10259
|
+
else:
|
10260
|
+
self.__last_url_of_deferred_assert = url
|
10261
|
+
except Exception:
|
10262
|
+
pass
|
10263
|
+
if self.recorder_mode and self.__current_url_is_recordable():
|
10264
|
+
if self.get_session_storage_item("pause_recorder") == "no":
|
10265
|
+
time_stamp = self.execute_script("return Date.now();")
|
10266
|
+
origin = self.get_origin()
|
10267
|
+
action = ["danet", selector, origin, time_stamp]
|
10268
|
+
self.__extra_actions.append(action)
|
10269
|
+
try:
|
10270
|
+
self.wait_for_non_empty_text_visible(
|
10271
|
+
selector, by=by, timeout=timeout
|
10272
|
+
)
|
10273
|
+
return True
|
10274
|
+
except Exception:
|
10275
|
+
self.__add_deferred_assert_failure(fs=fs)
|
10276
|
+
return False
|
10277
|
+
|
10124
10278
|
def deferred_check_window(
|
10125
10279
|
self,
|
10126
10280
|
name="default",
|
@@ -10217,6 +10371,18 @@ class BaseCase(unittest.TestCase):
|
|
10217
10371
|
text=text, selector=selector, by=by, timeout=timeout, fs=fs
|
10218
10372
|
)
|
10219
10373
|
|
10374
|
+
def delayed_assert_non_empty_text(
|
10375
|
+
self,
|
10376
|
+
selector="html",
|
10377
|
+
by="css selector",
|
10378
|
+
timeout=None,
|
10379
|
+
fs=False,
|
10380
|
+
):
|
10381
|
+
"""Same as self.deferred_assert_non_empty_text()"""
|
10382
|
+
return self.deferred_assert_non_empty_text(
|
10383
|
+
selector=selector, by=by, timeout=timeout, fs=fs
|
10384
|
+
)
|
10385
|
+
|
10220
10386
|
def delayed_check_window(
|
10221
10387
|
self,
|
10222
10388
|
name="default",
|
@@ -13223,7 +13389,7 @@ class BaseCase(unittest.TestCase):
|
|
13223
13389
|
text,
|
13224
13390
|
selector,
|
13225
13391
|
)
|
13226
|
-
page_actions.timeout_exception("
|
13392
|
+
page_actions.timeout_exception("TextNotVisibleException", msg)
|
13227
13393
|
return True
|
13228
13394
|
|
13229
13395
|
def __wait_for_exact_shadow_text_visible(self, text, selector, timeout):
|
@@ -13242,7 +13408,7 @@ class BaseCase(unittest.TestCase):
|
|
13242
13408
|
"" % (text, selector)
|
13243
13409
|
)
|
13244
13410
|
page_actions.timeout_exception(
|
13245
|
-
"
|
13411
|
+
"TextNotVisibleException", msg
|
13246
13412
|
)
|
13247
13413
|
return True
|
13248
13414
|
except Exception:
|
@@ -13257,7 +13423,32 @@ class BaseCase(unittest.TestCase):
|
|
13257
13423
|
"Expected exact text {%s} in element {%s} was not visible!"
|
13258
13424
|
% (text, selector)
|
13259
13425
|
)
|
13260
|
-
page_actions.timeout_exception("
|
13426
|
+
page_actions.timeout_exception("TextNotVisibleException", msg)
|
13427
|
+
return True
|
13428
|
+
|
13429
|
+
def __wait_for_non_empty_shadow_text_visible(self, selector, timeout):
|
13430
|
+
start_ms = time.time() * 1000.0
|
13431
|
+
stop_ms = start_ms + (settings.SMALL_TIMEOUT * 1000.0)
|
13432
|
+
for x in range(int(settings.SMALL_TIMEOUT * 10)):
|
13433
|
+
try:
|
13434
|
+
actual_text = self.__get_shadow_text(selector, timeout=1)
|
13435
|
+
actual_text = actual_text.strip()
|
13436
|
+
if len(actual_text) == 0:
|
13437
|
+
msg = "Element {%s} has no visible text!" % (selector)
|
13438
|
+
page_actions.timeout_exception(
|
13439
|
+
"TextNotVisibleException", msg
|
13440
|
+
)
|
13441
|
+
return True
|
13442
|
+
except Exception:
|
13443
|
+
now_ms = time.time() * 1000.0
|
13444
|
+
if now_ms >= stop_ms:
|
13445
|
+
break
|
13446
|
+
time.sleep(0.1)
|
13447
|
+
actual_text = self.__get_shadow_text(selector, timeout=1)
|
13448
|
+
actual_text = actual_text.strip()
|
13449
|
+
if len(actual_text) == 0:
|
13450
|
+
msg = "Element {%s} has no visible text!" % (selector)
|
13451
|
+
page_actions.timeout_exception("TextNotVisibleException", msg)
|
13261
13452
|
return True
|
13262
13453
|
|
13263
13454
|
def __assert_shadow_text_visible(self, text, selector, timeout):
|
@@ -13312,6 +13503,31 @@ class BaseCase(unittest.TestCase):
|
|
13312
13503
|
except Exception:
|
13313
13504
|
pass
|
13314
13505
|
|
13506
|
+
def __assert_non_empty_shadow_text_visible(self, selector, timeout, strip):
|
13507
|
+
self.__wait_for_non_empty_shadow_text_visible(selector, timeout, strip)
|
13508
|
+
if self.demo_mode:
|
13509
|
+
a_t = "ASSERT NON-EMPTY TEXT"
|
13510
|
+
i_n = "in"
|
13511
|
+
by = By.CSS_SELECTOR
|
13512
|
+
if self._language != "English":
|
13513
|
+
from seleniumbase.fixtures.words import SD
|
13514
|
+
|
13515
|
+
a_t = SD.translate_assert_non_empty_text(self._language)
|
13516
|
+
i_n = SD.translate_in(self._language)
|
13517
|
+
messenger_post = "<b>%s</b> %s %s: %s" % (
|
13518
|
+
a_t,
|
13519
|
+
i_n,
|
13520
|
+
by.upper(),
|
13521
|
+
selector,
|
13522
|
+
)
|
13523
|
+
try:
|
13524
|
+
js_utils.activate_jquery(self.driver)
|
13525
|
+
js_utils.post_messenger_success_message(
|
13526
|
+
self.driver, messenger_post, self.message_duration
|
13527
|
+
)
|
13528
|
+
except Exception:
|
13529
|
+
pass
|
13530
|
+
|
13315
13531
|
def __is_shadow_element_present(self, selector):
|
13316
13532
|
try:
|
13317
13533
|
element = self.__get_shadow_element(selector, timeout=0.1)
|
@@ -13371,6 +13587,18 @@ class BaseCase(unittest.TestCase):
|
|
13371
13587
|
except Exception:
|
13372
13588
|
return False
|
13373
13589
|
|
13590
|
+
def __is_shadow_non_empty_text_visible(self, selector):
|
13591
|
+
try:
|
13592
|
+
element = self.__get_shadow_element(selector, timeout=0.1)
|
13593
|
+
if self.browser == "safari":
|
13594
|
+
return (
|
13595
|
+
element.is_displayed()
|
13596
|
+
and len(element.get_attribute("innerText").strip() > 0)
|
13597
|
+
)
|
13598
|
+
return element.is_displayed() and len(element.text.strip()) > 0
|
13599
|
+
except Exception:
|
13600
|
+
return False
|
13601
|
+
|
13374
13602
|
def __is_shadow_attribute_present(self, selector, attribute, value=None):
|
13375
13603
|
try:
|
13376
13604
|
element = self.__get_shadow_element(selector, timeout=0.1)
|
@@ -28,6 +28,7 @@ from selenium.common.exceptions import NoSuchElementException
|
|
28
28
|
from selenium.common.exceptions import NoSuchWindowException
|
29
29
|
from selenium.common.exceptions import StaleElementReferenceException
|
30
30
|
from selenium.webdriver.common.action_chains import ActionChains
|
31
|
+
from seleniumbase.common.exceptions import LinkTextNotFoundException
|
31
32
|
from seleniumbase.common.exceptions import TextNotVisibleException
|
32
33
|
from seleniumbase.config import settings
|
33
34
|
from seleniumbase.fixtures import shared_utils
|
@@ -197,6 +198,38 @@ def is_attribute_present(
|
|
197
198
|
return False
|
198
199
|
|
199
200
|
|
201
|
+
def is_non_empty_text_visible(driver, selector, by="css selector"):
|
202
|
+
"""
|
203
|
+
Returns whether the element has any text visible for the given selector.
|
204
|
+
@Params
|
205
|
+
driver - the webdriver object (required)
|
206
|
+
selector - the locator for identifying the page element (required)
|
207
|
+
by - the type of selector being used (Default: "css selector")
|
208
|
+
@Returns
|
209
|
+
Boolean (is any text visible in the element with the selector)
|
210
|
+
"""
|
211
|
+
browser = None # Only used for covering a Safari edge case
|
212
|
+
try:
|
213
|
+
if "safari:platformVersion" in driver.capabilities:
|
214
|
+
browser = "safari"
|
215
|
+
except Exception:
|
216
|
+
pass
|
217
|
+
try:
|
218
|
+
element = driver.find_element(by=by, value=selector)
|
219
|
+
element_text = element.text
|
220
|
+
if browser == "safari":
|
221
|
+
if element.tag_name.lower() in ["input", "textarea"]:
|
222
|
+
element_text = element.get_attribute("value")
|
223
|
+
else:
|
224
|
+
element_text = element.get_attribute("innerText")
|
225
|
+
elif element.tag_name.lower() in ["input", "textarea"]:
|
226
|
+
element_text = element.get_property("value")
|
227
|
+
element_text = element_text.strip()
|
228
|
+
return element.is_displayed() and len(element_text) > 0
|
229
|
+
except Exception:
|
230
|
+
return False
|
231
|
+
|
232
|
+
|
200
233
|
def hover_on_element(driver, selector, by="css selector"):
|
201
234
|
"""
|
202
235
|
Fires the hover event for the specified element by the given selector.
|
@@ -468,12 +501,12 @@ def wait_for_element_visible(
|
|
468
501
|
)
|
469
502
|
timeout_exception(ElementNotVisibleException, message)
|
470
503
|
elif not element and by == "link text":
|
471
|
-
message = "Link text {%s} was not
|
504
|
+
message = "Link text {%s} was not found after %s second%s!" % (
|
472
505
|
selector,
|
473
506
|
timeout,
|
474
507
|
plural,
|
475
508
|
)
|
476
|
-
timeout_exception(
|
509
|
+
timeout_exception(LinkTextNotFoundException, message)
|
477
510
|
else:
|
478
511
|
return element
|
479
512
|
|
@@ -870,12 +903,12 @@ def wait_for_element_clickable(
|
|
870
903
|
)
|
871
904
|
timeout_exception(ElementNotInteractableException, message)
|
872
905
|
elif not element and by == "link text" and not is_visible:
|
873
|
-
message = "Link text {%s} was not
|
906
|
+
message = "Link text {%s} was not found after %s second%s!" % (
|
874
907
|
selector,
|
875
908
|
timeout,
|
876
909
|
plural,
|
877
910
|
)
|
878
|
-
timeout_exception(
|
911
|
+
timeout_exception(LinkTextNotFoundException, message)
|
879
912
|
elif not element and by == "link text" and is_visible:
|
880
913
|
message = "Link text {%s} was not clickable after %s second%s!" % (
|
881
914
|
selector,
|
@@ -1076,6 +1109,86 @@ def wait_for_exact_text_not_visible(
|
|
1076
1109
|
timeout_exception(Exception, message)
|
1077
1110
|
|
1078
1111
|
|
1112
|
+
def wait_for_non_empty_text_visible(
|
1113
|
+
driver, selector, by="css selector", timeout=settings.LARGE_TIMEOUT,
|
1114
|
+
):
|
1115
|
+
"""
|
1116
|
+
Searches for any text in the element of the given selector.
|
1117
|
+
Returns the element if it has visible text within the timeout.
|
1118
|
+
Raises an exception if the element has no text within the timeout.
|
1119
|
+
Whitespace-only text is considered empty text.
|
1120
|
+
@Params
|
1121
|
+
driver - the webdriver object (required)
|
1122
|
+
text - the text that is being searched for in the element (required)
|
1123
|
+
selector - the locator for identifying the page element (required)
|
1124
|
+
by - the type of selector being used (Default: "css selector")
|
1125
|
+
timeout - the time to wait for elements in seconds
|
1126
|
+
@Returns
|
1127
|
+
The web element object that has text
|
1128
|
+
"""
|
1129
|
+
start_ms = time.time() * 1000.0
|
1130
|
+
stop_ms = start_ms + (timeout * 1000.0)
|
1131
|
+
element = None
|
1132
|
+
visible = None
|
1133
|
+
browser = None # Only used for covering a Safari edge case
|
1134
|
+
try:
|
1135
|
+
if "safari:platformVersion" in driver.capabilities:
|
1136
|
+
browser = "safari"
|
1137
|
+
except Exception:
|
1138
|
+
pass
|
1139
|
+
for x in range(int(timeout * 10)):
|
1140
|
+
shared_utils.check_if_time_limit_exceeded()
|
1141
|
+
try:
|
1142
|
+
element = None
|
1143
|
+
visible = False
|
1144
|
+
element = driver.find_element(by=by, value=selector)
|
1145
|
+
if element.is_displayed():
|
1146
|
+
visible = True
|
1147
|
+
element_text = element.text
|
1148
|
+
if browser == "safari":
|
1149
|
+
if element.tag_name.lower() in ["input", "textarea"]:
|
1150
|
+
element_text = element.get_attribute("value")
|
1151
|
+
else:
|
1152
|
+
element_text = element.get_attribute("innerText")
|
1153
|
+
elif element.tag_name.lower() in ["input", "textarea"]:
|
1154
|
+
element_text = element.get_property("value")
|
1155
|
+
element_text = element_text.strip()
|
1156
|
+
if element.is_displayed() and len(element_text) > 0:
|
1157
|
+
return element
|
1158
|
+
except Exception:
|
1159
|
+
element = None
|
1160
|
+
now_ms = time.time() * 1000.0
|
1161
|
+
if now_ms >= stop_ms:
|
1162
|
+
break
|
1163
|
+
time.sleep(0.1)
|
1164
|
+
plural = "s"
|
1165
|
+
if timeout == 1:
|
1166
|
+
plural = ""
|
1167
|
+
if not element:
|
1168
|
+
# The element does not exist in the HTML
|
1169
|
+
message = "Element {%s} was not present after %s second%s!" % (
|
1170
|
+
selector,
|
1171
|
+
timeout,
|
1172
|
+
plural,
|
1173
|
+
)
|
1174
|
+
timeout_exception(NoSuchElementException, message)
|
1175
|
+
elif not visible:
|
1176
|
+
# The element exists in the HTML, but is not visible
|
1177
|
+
message = "Element {%s} was not visible after %s second%s!" % (
|
1178
|
+
selector,
|
1179
|
+
timeout,
|
1180
|
+
plural,
|
1181
|
+
)
|
1182
|
+
timeout_exception(ElementNotVisibleException, message)
|
1183
|
+
else:
|
1184
|
+
# The element exists in the HTML, but has no visible text
|
1185
|
+
message = (
|
1186
|
+
"Element {%s} has no visible text after %s second%s!"
|
1187
|
+
"" % (selector, timeout, plural)
|
1188
|
+
)
|
1189
|
+
timeout_exception(TextNotVisibleException, message)
|
1190
|
+
|
1191
|
+
|
1079
1192
|
def wait_for_attribute_not_present(
|
1080
1193
|
driver,
|
1081
1194
|
selector,
|
@@ -1421,3 +1534,17 @@ def wait_for_text(
|
|
1421
1534
|
timeout=timeout,
|
1422
1535
|
browser=browser,
|
1423
1536
|
)
|
1537
|
+
|
1538
|
+
|
1539
|
+
def wait_for_non_empty_text(
|
1540
|
+
driver,
|
1541
|
+
selector,
|
1542
|
+
by="css selector",
|
1543
|
+
timeout=settings.LARGE_TIMEOUT,
|
1544
|
+
):
|
1545
|
+
return wait_for_non_empty_text_visible(
|
1546
|
+
driver=driver,
|
1547
|
+
selector=selector,
|
1548
|
+
by=by,
|
1549
|
+
timeout=timeout,
|
1550
|
+
)
|
@@ -71,6 +71,7 @@ def format_exc(exception, message):
|
|
71
71
|
from selenium.common.exceptions import NoSuchElementException
|
72
72
|
from selenium.common.exceptions import NoSuchFrameException
|
73
73
|
from selenium.common.exceptions import NoSuchWindowException
|
74
|
+
from seleniumbase.common.exceptions import LinkTextNotFoundException
|
74
75
|
from seleniumbase.common.exceptions import NoSuchFileException
|
75
76
|
from seleniumbase.common.exceptions import NoSuchOptionException
|
76
77
|
from seleniumbase.common.exceptions import TextNotVisibleException
|
@@ -83,6 +84,10 @@ def format_exc(exception, message):
|
|
83
84
|
exc = exceptions.ElementNotVisibleException
|
84
85
|
elif exception == "ElementNotVisibleException":
|
85
86
|
exc = exceptions.ElementNotVisibleException
|
87
|
+
elif exception == LinkTextNotFoundException:
|
88
|
+
exc = exceptions.LinkTextNotFoundException
|
89
|
+
elif exception == "LinkTextNotFoundException":
|
90
|
+
exc = exceptions.LinkTextNotFoundException
|
86
91
|
elif exception == NoSuchElementException:
|
87
92
|
exc = exceptions.NoSuchElementException
|
88
93
|
elif exception == "NoSuchElementException":
|
seleniumbase/fixtures/words.py
CHANGED
@@ -38,7 +38,7 @@ class SD:
|
|
38
38
|
words["French"] = "VÉRIFIER TEXTE"
|
39
39
|
words["Italian"] = "VERIFICARE TESTO"
|
40
40
|
words["Japanese"] = "テキストを確認する"
|
41
|
-
words["Korean"] = "텍스트
|
41
|
+
words["Korean"] = "텍스트 확인하는"
|
42
42
|
words["Portuguese"] = "VERIFICAR TEXTO"
|
43
43
|
words["Russian"] = "ПОДТВЕРДИТЬ ТЕКСТ"
|
44
44
|
words["Spanish"] = "VERIFICAR TEXTO"
|
@@ -72,6 +72,20 @@ class SD:
|
|
72
72
|
words["Spanish"] = "VERIFICAR TEXTO DEL ENLACE"
|
73
73
|
return words[language]
|
74
74
|
|
75
|
+
def translate_assert_non_empty_text(language):
|
76
|
+
words = {}
|
77
|
+
words["English"] = "ASSERT NON-EMPTY TEXT"
|
78
|
+
words["Chinese"] = "断言非空文本"
|
79
|
+
words["Dutch"] = "CONTROLEREN NIET-LEGE TEKST"
|
80
|
+
words["French"] = "VÉRIFIER TEXTE NON VIDE"
|
81
|
+
words["Italian"] = "VERIFICARE TESTO NON VUOTO"
|
82
|
+
words["Japanese"] = "空ではないテキストを確認する"
|
83
|
+
words["Korean"] = "비어 있지 않은 텍스트 확인하는"
|
84
|
+
words["Portuguese"] = "VERIFICAR TEXTO NÃO VAZIO"
|
85
|
+
words["Russian"] = "ПОДТВЕРДИТЬ НЕПУСТОЙ ТЕКСТ"
|
86
|
+
words["Spanish"] = "VERIFICAR TEXTO NO VACÍO"
|
87
|
+
return words[language]
|
88
|
+
|
75
89
|
def translate_assert_attribute(language):
|
76
90
|
words = {}
|
77
91
|
words["English"] = "ASSERT ATTRIBUTE"
|
@@ -77,6 +77,10 @@ class 硒测试用例(BaseCase):
|
|
77
77
|
# assert_link_text(link_text)
|
78
78
|
return self.assert_link_text(*args, **kwargs)
|
79
79
|
|
80
|
+
def 断言非空文本(self, *args, **kwargs):
|
81
|
+
# assert_non_empty_text(selector)
|
82
|
+
return self.assert_non_empty_text(*args, **kwargs)
|
83
|
+
|
80
84
|
def 断言文本不可见(self, *args, **kwargs):
|
81
85
|
# assert_text_not_visible(text, selector)
|
82
86
|
return self.assert_text_not_visible(*args, **kwargs)
|
seleniumbase/translate/dutch.py
CHANGED
@@ -77,6 +77,10 @@ class Testgeval(BaseCase):
|
|
77
77
|
# assert_link_text(link_text)
|
78
78
|
return self.assert_link_text(*args, **kwargs)
|
79
79
|
|
80
|
+
def controleren_niet_lege_tekst(self, *args, **kwargs):
|
81
|
+
# assert_non_empty_text(selector)
|
82
|
+
return self.assert_non_empty_text(*args, **kwargs)
|
83
|
+
|
80
84
|
def controleren_tekst_niet_zichtbaar(self, *args, **kwargs):
|
81
85
|
# assert_text_not_visible(text, selector)
|
82
86
|
return self.assert_text_not_visible(*args, **kwargs)
|
seleniumbase/translate/french.py
CHANGED
@@ -77,6 +77,10 @@ class CasDeBase(BaseCase):
|
|
77
77
|
# assert_link_text(link_text)
|
78
78
|
return self.assert_link_text(*args, **kwargs)
|
79
79
|
|
80
|
+
def vérifier_texte_non_vide(self, *args, **kwargs):
|
81
|
+
# assert_non_empty_text(selector)
|
82
|
+
return self.assert_non_empty_text(*args, **kwargs)
|
83
|
+
|
80
84
|
def vérifier_texte_pas_affiché(self, *args, **kwargs):
|
81
85
|
# assert_text_not_visible(text, selector)
|
82
86
|
return self.assert_text_not_visible(*args, **kwargs)
|
@@ -77,6 +77,10 @@ class CasoDiProva(BaseCase):
|
|
77
77
|
# assert_link_text(link_text)
|
78
78
|
return self.assert_link_text(*args, **kwargs)
|
79
79
|
|
80
|
+
def verificare_testo_non_vuoto(self, *args, **kwargs):
|
81
|
+
# assert_non_empty_text(selector)
|
82
|
+
return self.assert_non_empty_text(*args, **kwargs)
|
83
|
+
|
80
84
|
def verificare_testo_non_visto(self, *args, **kwargs):
|
81
85
|
# assert_text_not_visible(text, selector)
|
82
86
|
return self.assert_text_not_visible(*args, **kwargs)
|
@@ -77,6 +77,10 @@ class セレニウムテストケース(BaseCase):
|
|
77
77
|
# assert_link_text(link_text)
|
78
78
|
return self.assert_link_text(*args, **kwargs)
|
79
79
|
|
80
|
+
def 空ではないテキストを確認する(self, *args, **kwargs):
|
81
|
+
# assert_non_empty_text(selector)
|
82
|
+
return self.assert_non_empty_text(*args, **kwargs)
|
83
|
+
|
80
84
|
def テキが表示されていないことを確認します(self, *args, **kwargs):
|
81
85
|
# assert_text_not_visible(text, selector)
|
82
86
|
return self.assert_text_not_visible(*args, **kwargs)
|
seleniumbase/translate/korean.py
CHANGED
@@ -77,6 +77,10 @@ class 셀레늄_테스트_케이스(BaseCase):
|
|
77
77
|
# assert_link_text(link_text)
|
78
78
|
return self.assert_link_text(*args, **kwargs)
|
79
79
|
|
80
|
+
def 비어_있지_않은_텍스트_확인하는(self, *args, **kwargs):
|
81
|
+
# assert_non_empty_text(selector)
|
82
|
+
return self.assert_non_empty_text(*args, **kwargs)
|
83
|
+
|
80
84
|
def 텍스트_보이지_않는지_확인(self, *args, **kwargs):
|
81
85
|
# assert_text_not_visible(text, selector)
|
82
86
|
return self.assert_text_not_visible(*args, **kwargs)
|