How to use __assert_shadow_text_visible method in SeleniumBase

Best Python code snippet using SeleniumBase

asserts.py

Source:asserts.py Github

copy

Full Screen

...251 self.driver, messenger_post, self.message_duration252 )253 except Exception:254 pass255 def __assert_shadow_text_visible(self, text, selector, timeout):256 self.__wait_for_shadow_text_visible(text, selector, timeout)257 if self.demo_mode:258 a_t = "ASSERT TEXT"259 i_n = "in"260 by = By.CSS_SELECTOR261 if self._language != "English":262 from seleniumbase.fixtures.words import SD263 a_t = SD.translate_assert_text(self._language)264 i_n = SD.translate_in(self._language)265 messenger_post = "%s: {%s} %s %s: %s" % (266 a_t,267 text,268 i_n,269 by.upper(),270 selector,271 )272 try:273 js_utils.activate_jquery(self.driver)274 js_utils.post_messenger_success_message(275 self.driver, messenger_post, self.message_duration276 )277 except Exception:278 pass279 def assert_attribute_not_present(280 self, selector, attribute, value=None, by=By.CSS_SELECTOR, timeout=None281 ):282 """Similar to wait_for_attribute_not_present()283 Raises an exception if the attribute is still present after timeout.284 Returns True if successful. Default timeout = SMALL_TIMEOUT."""285 self.__check_scope__()286 timeout = self.get_timeout(timeout, constants.SMALL_TIMEOUT)287 return self.wait_for_attribute_not_present(288 selector, attribute, value=value, by=by, timeout=timeout289 )290 def assert_element(self, selector, by=By.CSS_SELECTOR, timeout=None):291 """Similar to wait_for_element_visible(), but returns nothing.292 As above, will raise an exception if nothing can be found.293 Returns True if successful. Default timeout = SMALL_TIMEOUT."""294 self.__check_scope()295 timeout = self.get_timeout(timeout, constants.SMALL_TIMEOUT)296 if type(selector) is list:297 self.assert_elements(selector, by=by, timeout=timeout)298 return True299 if self.__is_shadow_selector(selector):300 self.__assert_shadow_element_visible(selector)301 return True302 self.wait_for_element_visible(selector, by=by, timeout=timeout)303 if self.demo_mode:304 selector, by = self.__recalculate_selector(305 selector, by, xp_ok=False306 )307 a_t = "ASSERT"308 if self._language != "English":309 from seleniumbase.fixtures.words import SD310 a_t = SD.translate_assert(self._language)311 messenger_post = "%s %s: %s" % (a_t, by.upper(), selector)312 self.__highlight_with_assert_success(messenger_post, selector, by)313 return True314 def assert_element_visible(315 self, selector, by=By.CSS_SELECTOR, timeout=None316 ):317 """Same as self.assert_element()318 As above, will raise an exception if nothing can be found."""319 self.__check_scope()320 timeout = self.get_timeout(timeout, constants.SMALL_TIMEOUT)321 self.assert_element(selector, by=by, timeout=timeout)322 return True323 def assert_elements(self, *args, **kwargs):324 """Similar to self.assert_element(), but can assert multiple elements.325 The input is a list of elements.326 Optional kwargs include "by" and "timeout" (used by all selectors).327 Raises an exception if any of the elements are not visible.328 Examples:329 self.assert_elements("h1", "h2", "h3")330 OR331 self.assert_elements(["h1", "h2", "h3"])"""332 self.__check_scope()333 selectors = []334 timeout = None335 by = By.CSS_SELECTOR336 for kwarg in kwargs:337 if kwarg == "timeout":338 timeout = kwargs["timeout"]339 elif kwarg == "by":340 by = kwargs["by"]341 elif kwarg == "selector":342 selector = kwargs["selector"]343 if type(selector) is str:344 selectors.append(selector)345 elif type(selector) is list:346 selectors_list = selector347 for selector in selectors_list:348 if type(selector) is str:349 selectors.append(selector)350 else:351 raise Exception('Unknown kwarg: "%s"!' % kwarg)352 timeout = self.get_timeout(timeout, constants.SMALL_TIMEOUT)353 for arg in args:354 if type(arg) is list:355 for selector in arg:356 if type(selector) is str:357 selectors.append(selector)358 elif type(arg) is str:359 selectors.append(arg)360 for selector in selectors:361 if self.__is_shadow_selector(selector):362 self.__assert_shadow_element_visible(selector)363 continue364 self.wait_for_element_visible(selector, by=by, timeout=timeout)365 if self.demo_mode:366 selector, by = self.__recalculate_selector(selector, by)367 a_t = "ASSERT"368 if self._language != "English":369 from seleniumbase.fixtures.words import SD370 a_t = SD.translate_assert(self._language)371 messenger_post = "%s %s: %s" % (a_t, by.upper(), selector)372 self.__highlight_with_assert_success(373 messenger_post, selector, by374 )375 continue376 return True377 def assert_elements_visible(self, *args, **kwargs):378 """Same as self.assert_elements()379 Raises an exception if any element cannot be found."""380 return self.assert_elements(*args, **kwargs)381 def assert_element_absent(382 self, selector, by=By.CSS_SELECTOR, timeout=None383 ):384 """Similar to wait_for_element_absent()385 As above, will raise an exception if the element stays present.386 A hidden element counts as a present element, which fails this assert.387 If you want to assert that elements are hidden instead of nonexistent,388 use assert_element_not_visible() instead.389 (Note that hidden elements are still present in the HTML of the page.)390 Returns True if successful. Default timeout = SMALL_TIMEOUT."""391 self.__check_scope()392 timeout = self.get_timeout(timeout, constants.SMALL_TIMEOUT)393 self.wait_for_element_absent(selector, by=by, timeout=timeout)394 return True395 def assert_element_not_present(396 self, selector, by=By.CSS_SELECTOR, timeout=None397 ):398 """Same as self.assert_element_absent()399 Will raise an exception if the element stays present.400 A hidden element counts as a present element, which fails this assert.401 If you want to assert that elements are hidden instead of nonexistent,402 use assert_element_not_visible() instead.403 (Note that hidden elements are still present in the HTML of the page.)404 Returns True if successful. Default timeout = SMALL_TIMEOUT."""405 self.__check_scope()406 timeout = self.get_timeout(timeout, constants.SMALL_TIMEOUT)407 self.wait_for_element_absent(selector, by=by, timeout=timeout)408 return True409 def assert_element_not_visible(410 self, selector, by=By.CSS_SELECTOR, timeout=None411 ):412 """Similar to wait_for_element_not_visible()413 As above, will raise an exception if the element stays visible.414 Returns True if successful. Default timeout = SMALL_TIMEOUT."""415 self.__check_scope__()416 timeout = self.get_timeout(timeout, constants.SMALL_TIMEOUT)417 self.wait_for_element_not_visible(selector, by=by, timeout=timeout)418 return True419 def assert_element_present(420 self, selector, by=By.CSS_SELECTOR, timeout=None421 ):422 """Similar to wait_for_element_present(), but returns nothing.423 Waits for an element to appear in the HTML of a page.424 The element does not need be visible (it may be hidden).425 Returns True if successful. Default timeout = SMALL_TIMEOUT."""426 self.__check_scope()427 timeout = self.get_timeout(timeout, constants.SMALL_TIMEOUT)428 if type(selector) is list:429 self.assert_elements_present(selector, by=by, timeout=timeout)430 return True431 if self.__is_shadow_selector(selector):432 self.__assert_shadow_element_present(selector)433 return True434 self.wait_for_element_present(selector, by=by, timeout=timeout)435 return True436 def assert_elements_present(self, *args, **kwargs):437 """Similar to self.assert_element_present(),438 but can assert that multiple elements are present in the HTML.439 The input is a list of elements.440 Optional kwargs include "by" and "timeout" (used by all selectors).441 Raises an exception if any of the elements are not visible.442 Examples:443 self.assert_elements_present("head", "style", "script", "body")444 OR445 self.assert_elements_present(["head", "body", "h1", "h2"])446 """447 self.__check_scope()448 selectors = []449 timeout = None450 by = By.CSS_SELECTOR451 for kwarg in kwargs:452 if kwarg == "timeout":453 timeout = kwargs["timeout"]454 elif kwarg == "by":455 by = kwargs["by"]456 elif kwarg == "selector":457 selector = kwargs["selector"]458 if type(selector) is str:459 selectors.append(selector)460 elif type(selector) is list:461 selectors_list = selector462 for selector in selectors_list:463 if type(selector) is str:464 selectors.append(selector)465 else:466 raise Exception('Unknown kwarg: "%s"!' % kwarg)467 timeout = self.get_timeout(timeout, constants.SMALL_TIMEOUT)468 for arg in args:469 if type(arg) is list:470 for selector in arg:471 if type(selector) is str:472 selectors.append(selector)473 elif type(arg) is str:474 selectors.append(arg)475 for selector in selectors:476 if self.__is_shadow_selector(selector):477 self.__assert_shadow_element_visible(selector)478 continue479 self.wait_for_element_present(selector, by=by, timeout=timeout)480 continue481 return True482 def assert_text_visible(483 self, text, selector="html", by=By.CSS_SELECTOR, timeout=None484 ):485 """ Same as assert_text() """486 self.__check_scope()487 timeout = self.get_timeout(timeout, constants.SMALL_TIMEOUT)488 return self.assert_text(text, selector, by=by, timeout=timeout)489 def assert_text(490 self, text, selector="html", by=By.CSS_SELECTOR, timeout=None491 ):492 """Similar to wait_for_text_visible()493 Raises an exception if the element or the text is not found.494 The text only needs to be a subset within the complete text.495 Returns True if successful. Default timeout = SMALL_TIMEOUT."""496 self.__check_scope()497 timeout = self.get_timeout(timeout, constants.SMALL_TIMEOUT)498 selector, by = self.__recalculate_selector(selector, by)499 if self.__is_shadow_selector(selector):500 self.__assert_shadow_text_visible(text, selector, timeout)501 return True502 self.wait_for_text_visible(text, selector, by=by, timeout=timeout)503 if self.demo_mode:504 a_t = "ASSERT TEXT"505 i_n = "in"506 if self._language != "English":507 from seleniumbase.fixtures.words import SD508 a_t = SD.translate_assert_text(self._language)509 i_n = SD.translate_in(self._language)510 messenger_post = "%s: {%s} %s %s: %s" % (511 a_t,512 text,513 i_n,514 by.upper(),...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful