Best Python code snippet using selene_python
entity.py
Source:entity.py
...392 "you also can build your own inverted conditions by: `not_ok = Condition.as_not(have.text('Ok'))`",393 DeprecationWarning,394 )395 return self.should(not_(condition), timeout)396 def assure_not(self, condition: ElementCondition, timeout=None) -> Element:397 warnings.warn(398 "deprecated; use `should` method with `be.not_.*` or `have.no.*` style conditions instead: "399 "`browser.element('#foo').should(be.not_.enabled).should(have.no.css_class('bar')`, "400 "you also can build your own inverted conditions by: `not_ok = Condition.as_not(have.text('Ok'))`",401 DeprecationWarning,402 )403 return self.should(not_(condition), timeout)404 def should_not_be(405 self, condition: ElementCondition, timeout=None406 ) -> Element:407 warnings.warn(408 "deprecated; use `should` method with `be.not_.*` or `have.no.*` style conditions instead: "409 "`browser.element('#foo').should(be.not_.enabled).should(have.no.css_class('bar')`, "410 "you also can build your own inverted conditions by: `not_ok = Condition.as_not(have.text('Ok'))`",411 DeprecationWarning,412 )413 return self.should(not_(condition), timeout)414 def should_not_have(415 self, condition: ElementCondition, timeout=None416 ) -> Element:417 warnings.warn(418 "deprecated; use `should` method with `be.not_.*` or `have.no.*` style conditions instead: "419 "`browser.element('#foo').should(be.not_.enabled).should(have.no.css_class('bar')`, "420 "you also can build your own inverted conditions by: `not_ok = Condition.as_not(have.text('Ok'))`",421 DeprecationWarning,422 )423 return self.should(not_(condition), timeout)424 def set(self, value: Union[str, int]) -> Element:425 warnings.warn(426 "deprecated; use `set_value` method instead", DeprecationWarning427 )428 return self.set_value(value)429 def scroll_to(self):430 warnings.warn(431 "deprecated; use `browser.element('#foo').perform(command.js.scroll_into_view)` style instead",432 DeprecationWarning,433 )434 from core.utils.selene.core import command435 self.perform(command.js.scroll_into_view)436 return self437 def press_down(self):438 warnings.warn(439 "deprecated; use `browser.element('#foo').type(Keys.ARROW_DOWN)` style instead",440 DeprecationWarning,441 )442 return self.type(Keys.ARROW_DOWN)443 def find_element(self, by=By.ID, value=None):444 warnings.warn(445 "deprecated; use `browser.element('#foo').should(be.in_dom)().find_element(by, value)` style instead",446 DeprecationWarning,447 )448 self.wait.command(449 'find element', lambda element: element().find_element(by, value)450 )451 return self452 def find_elements(self, by=By.ID, value=None):453 warnings.warn(454 "deprecated; use `browser.element('#foo').should(be.in_dom)().find_elements(by, value)` style instead",455 DeprecationWarning,456 )457 self.wait.command(458 'find elements', lambda element: element().find_elements(by, value)459 )460 return self461 def send_keys(self, *value) -> Element:462 self.wait.command(463 'send keys', lambda element: element().send_keys(*value)464 )465 return self466 @property467 def tag_name(self) -> str:468 warnings.warn(469 "deprecated; use `browser.element('#foo').get(query.tag_name)` style instead",470 DeprecationWarning,471 )472 from core.utils.selene.core import query473 return self.get(query.tag)474 @property475 def text(self) -> str:476 warnings.warn(477 "deprecated; use `browser.element('#foo').get(query.text)` style instead",478 DeprecationWarning,479 )480 from core.utils.selene.core import query481 return self.get(query.text)482 def attribute(self, name: str) -> str:483 warnings.warn(484 "deprecated; use `browser.element('#foo').get(query.attribute('name'))` style instead",485 DeprecationWarning,486 )487 from core.utils.selene.core import query488 return self.get(query.attribute(name))489 def js_property(self, name: str) -> str:490 warnings.warn(491 "deprecated; use `browser.element('#foo').get(query.js_property('name'))` style instead",492 DeprecationWarning,493 )494 from core.utils.selene.core import query495 return self.get(query.js_property(name))496 def value_of_css_property(self, name: str) -> str:497 warnings.warn(498 "deprecated; use `browser.element('#foo').get(query.css_property('name'))` style instead",499 DeprecationWarning,500 )501 from core.utils.selene.core import query502 return self.get(query.css_property(name))503 def get_attribute(self, name: str) -> str:504 warnings.warn(505 "deprecated; use `browser.element('#foo').get(query.attribute('name'))` style instead",506 DeprecationWarning,507 )508 from core.utils.selene.core import query509 return self.get(query.attribute(name))510 def get_property(self, name: str) -> str:511 warnings.warn(512 "deprecated; use `browser.element('#foo').get(query.js_property('name'))` style instead",513 DeprecationWarning,514 )515 from core.utils.selene.core import query516 return self.get(query.js_property(name))517 def is_selected(self) -> bool:518 warnings.warn(519 "deprecated; use `browser.element('#foo').matching(be.selected)` style instead",520 DeprecationWarning,521 )522 from core.utils.selene.support.conditions import be523 return self.matching(be.selected)524 def is_enabled(self):525 warnings.warn(526 "deprecated; use `browser.element('#foo').matching(be.enabled)` style instead",527 DeprecationWarning,528 )529 from core.utils.selene.support.conditions import be530 return self.matching(be.enabled)531 def is_displayed(self):532 warnings.warn(533 "deprecated; use `browser.element('#foo').matching(be.visible)` style instead",534 DeprecationWarning,535 )536 from core.utils.selene.support.conditions import be537 return self.matching(be.visible)538 @property539 def location(self) -> Dict[str, int]:540 warnings.warn(541 "deprecated; use `browser.element('#foo').get(query.location)` style instead",542 DeprecationWarning,543 )544 from core.utils.selene.core import query545 return self.get(query.location)546 @property547 def location_once_scrolled_into_view(self) -> Dict[str, int]:548 warnings.warn(549 "deprecated; use `browser.element('#foo').get(query.location_once_scrolled_into_view)` style instead",550 DeprecationWarning,551 )552 from core.utils.selene.core import query553 return self.get(query.location_once_scrolled_into_view)554 @property555 def size(self) -> Dict[str, Any]:556 warnings.warn(557 "deprecated; use `browser.element('#foo').get(query.size)` style instead",558 DeprecationWarning,559 )560 from core.utils.selene.core import query561 return self.get(query.size)562 @property563 def rect(self) -> Dict[str, Any]:564 warnings.warn(565 "deprecated; use `browser.element('#foo').get(query.rect)` style instead",566 DeprecationWarning,567 )568 from core.utils.selene.core import query569 return self.get(query.rect)570 @property571 def screenshot_as_base64(self) -> Any:572 warnings.warn(573 "deprecated; use `browser.element('#foo').get(query.screenshot_as_base64)` style instead",574 DeprecationWarning,575 )576 from core.utils.selene.core import query577 return self.get(query.screenshot_as_base64)578 @property579 def screenshot_as_png(self) -> Any:580 warnings.warn(581 "deprecated; use `browser.element('#foo').get(query.screenshot_as_base64)` style instead",582 DeprecationWarning,583 )584 from core.utils.selene.core import query585 return self.get(query.screenshot_as_png)586 def screenshot(self, filename: str) -> bool:587 warnings.warn(588 "deprecated; use `browser.element('#foo').get(query.screenshot('filename'))` style instead",589 DeprecationWarning,590 )591 from core.utils.selene.core import query592 return self.get(query.screenshot(filename))593 @property594 def parent(self):595 warnings.warn(596 "deprecated; use `browser.element('#foo')().parent` style for the majority of cases",597 DeprecationWarning,598 )599 return self.get(600 Query('parent search context', lambda element: element().parent)601 )602 @property603 def id(self):604 warnings.warn(605 "deprecated; use `browser.element('#foo').get(query.internal_id)` style instead",606 DeprecationWarning,607 )608 from core.utils.selene.core import query609 return self.get(query.internal_id)610class SeleneElement(Element):611 pass612class Collection(WaitingEntity):613 def __init__(self, locator: Locator[List[WebElement]], config: Config):614 self._locator = locator615 super().__init__(config)616 def with_(self, config: Config = None, **config_as_kwargs) -> Collection:617 return Collection(618 self._locator, self.config.with_(config, **config_as_kwargs)619 )620 def __str__(self):621 return str(self._locator)622 def __call__(self) -> List[WebElement]:623 return self._locator()624 @property625 def cached(self) -> Collection:626 webelements = self()627 return Collection(628 Locator(f'{self}.cached', lambda: webelements), self.config629 )630 def __iter__(self):631 i = 0632 cached = self.cached633 while i < len(cached()):634 element = cached[i]635 yield element636 i += 1637 def __len__(self):638 from core.utils.selene.core import query639 return self.get(query.size)640 def element(self, index: int) -> Element:641 def find() -> WebElement:642 webelements = self()643 length = len(webelements)644 if length <= index:645 raise AssertionError(646 f'Cannot get element with index {index} '647 + f'from webelements collection with length {length}'648 )649 return webelements[index]650 return Element(Locator(f'{self}[{index}]', find), self.config)651 @property652 def first(self):653 return self.element(0)654 def sliced(self, start: int, stop: int, step: int = 1) -> Collection:655 def find() -> List[WebElement]:656 webelements = self()657 return webelements[start:stop:step]658 return Collection(659 Locator(f'{self}[{start}:{stop}:{step}]', find), self.config660 )661 def __getitem__(662 self, index_or_slice: Union[int, slice]663 ) -> Union[Element, Collection]:664 if isinstance(index_or_slice, slice):665 return self.sliced(666 index_or_slice.start, index_or_slice.stop, index_or_slice.step667 )668 return self.element(index_or_slice)669 def from_(self, start: int) -> Collection:670 return self[start:]671 def to(self, stop: int) -> Collection:672 return self[:stop]673 def filtered_by(674 self, condition: Union[Condition[[], Element], Callable[[E], None]]675 ) -> Collection:676 condition = (677 condition678 if isinstance(condition, Condition)679 else Condition(str(condition), condition)680 )681 return Collection(682 Locator(683 f'{self}.filtered_by({condition})',684 lambda: [685 element()686 for element in self.cached687 if element.matching(condition)688 ],689 ),690 self.config,691 )692 def filtered_by_their(693 self,694 selector_or_callable: Union[str, tuple, Callable[[Element], Element]],695 condition: Condition[[], Element],696 ) -> Collection:697 warnings.warn(698 'filtered_by_their is experimental; might be renamed or removed in future',699 FutureWarning,700 )701 def find_in(parent: Element):702 if callable(selector_or_callable):703 return selector_or_callable(parent)704 else:705 return parent.element(selector_or_callable)706 return self.filtered_by(lambda it: condition(find_in(it)))707 def element_by(708 self, condition: Union[Condition[[], Element], Callable[[E], None]]709 ) -> Element:710 condition = (711 condition712 if isinstance(condition, Condition)713 else Condition(str(condition), condition)714 )715 def find() -> WebElement:716 cached = self.cached717 for element in cached:718 if element.matching(condition):719 return element()720 from core.utils.selene.core import query721 if self.config.log_outer_html_on_failure:722 outer_htmls = [query.outer_html(element) for element in cached]723 raise AssertionError(724 f'\n\tCannot find element by condition «{condition}» '725 f'\n\tAmong {self}'726 f'\n\tActual webelements collection:'727 f'\n\t{outer_htmls}'728 )729 else:730 raise AssertionError(731 f'\n\tCannot find element by condition «{condition}» '732 f'\n\tAmong {self}'733 )734 return Element(735 Locator(f'{self}.element_by({condition})', find), self.config736 )737 def element_by_its(738 self,739 selector_or_callable: Union[str, tuple, Callable[[Element], Element]],740 condition: Condition[[], Element],741 ) -> Element:742 warnings.warn(743 'element_by_its is experimental; might be renamed or removed in future',744 FutureWarning,745 )746 def find_in(parent: Element):747 if callable(selector_or_callable):748 return selector_or_callable(parent)749 else:750 return parent.element(selector_or_callable)751 return self.element_by(lambda it: condition(find_in(it)))752 def all(self, css_or_xpath_or_by: Union[str, tuple]) -> Collection:753 warnings.warn(754 'might be renamed or deprecated in future; '755 'all is actually a shortcut for collected(lambda element: element.all(selector)...'756 'but we also have all_first and...'757 'it is yet unclear what name would be best for all_first as addition to all... '758 'all_first might confuse with all(...).first... I mean: '759 'all_first(selector) is actually '760 'collected(lambda e: e.element(selector)) '761 'but it is not the same as '762 'all(selector).first '763 'that is collected(lambda e: e.all(selector)).first ... o_O ',764 FutureWarning,765 )766 by = to_by(css_or_xpath_or_by)767 return Collection(768 Locator(769 f'{self}.all({by})',770 lambda: flatten(771 [webelement.find_elements(*by) for webelement in self()]772 ),773 ),774 self.config,775 )776 def all_first(self, css_or_xpath_or_by: Union[str, tuple]) -> Collection:777 warnings.warn(778 'might be renamed or deprecated in future; '779 'it is yet unclear what name would be best... '780 'all_first might confuse with all(...).first... I mean: '781 'all_first(selector) is actually '782 'collected(lambda e: e.element(selector)) '783 'but it is not the same as '784 'all(selector).first '785 'that is collected(lambda e: e.all(selector)).first ... o_O ',786 FutureWarning,787 )788 by = to_by(css_or_xpath_or_by)789 return Collection(790 Locator(791 f'{self}.all_first({by})',792 lambda: [793 webelement.find_element(*by) for webelement in self()794 ],795 ),796 self.config,797 )798 def collected(799 self, finder: Callable[[Element], Union[Element, Collection]]800 ) -> Collection:801 return Collection(802 Locator(803 f'{self}.collected({finder})',804 lambda: flatten(805 [finder(element)() for element in self.cached]806 ),807 ),808 self.config,809 )810 def should(811 self,812 condition: Union[Condition[[], Collection], Condition[[], Element]],813 timeout: int = None,814 ) -> Collection:815 if isinstance(condition, ElementCondition):816 for element in self:817 if timeout:818 warnings.warn(819 "using timeout argument is deprecated; "820 "use `browser.all('.foo').with_(Config(timeout=6)).should(have.size(0))`"821 "or just `...with_(timeout=6).should(...` style instead",822 DeprecationWarning,823 )824 element.with_(Config(timeout=timeout)).should(condition)825 element.should(condition)826 else:827 if timeout:828 warnings.warn(829 "using timeout argument is deprecated; "830 "use `browser.all('.foo').with_(Config(timeout=6)).should(have.size(0))` "831 "or just `...with_(timeout=6).should(...` style instead",832 DeprecationWarning,833 )834 self.with_(Config(timeout=timeout)).should(condition)835 super().should(condition)836 return self837 def get_actual_webelements(self) -> List[WebElement]:838 warnings.warn(839 "considering to be deprecated; use collection as callable instead, like: browser.all('.foo')()",840 PendingDeprecationWarning,841 )842 return self()843 def caching(self) -> Collection:844 warnings.warn(845 "deprecated; use `cached` property instead: browser.all('#foo').cached",846 DeprecationWarning,847 )848 return self.cached849 def all_by(self, condition: Condition[[], Element]) -> Collection:850 warnings.warn(851 "deprecated; use `filtered_by` instead: browser.all('.foo').filtered_by(be.enabled)",852 DeprecationWarning,853 )854 return self.filtered_by(condition)855 def filter_by(self, condition: Condition[[], Element]) -> Collection:856 warnings.warn(857 "deprecated; use `filtered_by` instead: browser.all('.foo').filtered_by(be.enabled)",858 DeprecationWarning,859 )860 return self.filtered_by(condition)861 def find_by(self, condition: Condition[[], Element]) -> Element:862 warnings.warn(863 "deprecated; use `element_by` instead: browser.all('.foo').element_by(be.enabled)",864 DeprecationWarning,865 )866 return self.element_by(condition)867 def size(self):868 warnings.warn(869 "deprecated; use `len` standard function instead: len(browser.all('.foo'))",870 DeprecationWarning,871 )872 return len(self)873 def should_each(874 self, condition: ElementCondition, timeout=None875 ) -> Collection:876 return self.should(condition, timeout)877 def assure(878 self,879 condition: Union[CollectionCondition, ElementCondition],880 timeout=None,881 ) -> Collection:882 warnings.warn(883 "deprecated; use `should` method instead: browser.all('.foo').should(have.size(0))",884 DeprecationWarning,885 )886 return self.should(condition, timeout)887 def should_be(888 self,889 condition: Union[CollectionCondition, ElementCondition],890 timeout=None,891 ) -> Collection:892 warnings.warn(893 "deprecated; use `should` method with `be.*` style conditions instead: "894 "browser.all('.foo').should(be.*)",895 DeprecationWarning,896 )897 return self.should(condition, timeout)898 def should_have(899 self,900 condition: Union[CollectionCondition, ElementCondition],901 timeout=None,902 ) -> Collection:903 warnings.warn(904 "deprecated; use `should` method with `have.*` style conditions instead: "905 "browser.all('.foo').should(have.size(0))",906 DeprecationWarning,907 )908 return self.should(condition, timeout)909 def should_not(910 self,911 condition: Union[CollectionCondition, ElementCondition],912 timeout=None,913 ) -> Collection:914 warnings.warn(915 "deprecated; use `should` method with `be.not_.*` or `have.no.*` style conditions instead: "916 "`browser.all('.foo').should(have.no.size(2))`, "917 "you also can build your own inverted conditions by: `not_zero = Condition.as_not(have.size(0'))`",918 DeprecationWarning,919 )920 return self.should(not_(condition), timeout)921 def assure_not(922 self,923 condition: Union[CollectionCondition, ElementCondition],924 timeout=None,925 ) -> Collection:926 warnings.warn(927 "deprecated; use `should` method with `be.not_.*` or `have.no.*` style conditions instead: "928 "`browser.all('.foo').should(have.no.size(2))`, "929 "you also can build your own inverted conditions by: `not_zero = Condition.as_not(have.size(0'))`",930 DeprecationWarning,931 )932 return self.should(not_(condition), timeout)933 def should_not_be(934 self,935 condition: Union[CollectionCondition, ElementCondition],...
elements.py
Source:elements.py
...251 not_condition = not_(condition)252 _wait_with_screenshot(self._webdriver, self, not_condition, timeout)253 return self254 # todo: consider removing some aliases255 def assure_not(self, condition, timeout=None):256 return self.should_not(condition, timeout)257 def should_not_be(self, condition, timeout=None):258 return self.should_not(condition, timeout)259 def should_not_have(self, condition, timeout=None):260 return self.should_not(condition, timeout)261 # *** Additional actions ***262 def double_click(self):263 self._execute_on_webelement(264 lambda it: self._actions_chains.double_click(it).perform(),265 condition=be.visible)266 return self267 def context_click(self):268 self._execute_on_webelement(lambda it: self._actions_chains.context_click(it).perform(),269 condition=be.visible)270 return self271 def set(self, new_text_value):272 def clear_and_send_keys(webelement):273 webelement.clear()274 webelement.send_keys(new_text_value)275 self._execute_on_webelement(276 clear_and_send_keys,277 condition=be.visible)278 return self279 set_value = set280 def scroll_to(self):281 def js_scroll_to(webelement):282 location = webelement.location283 self._webdriver.execute_script("window.scrollTo({x},{y});".format(x=location['x'],284 y=location['y']))285 self._execute_on_webelement(286 js_scroll_to,287 condition=be.visible)288 return self289 def press_enter(self):290 return self.send_keys(Keys.ENTER)291 def press_escape(self):292 return self.send_keys(Keys.ESCAPE)293 def press_tab(self):294 return self.send_keys(Keys.TAB)295 def hover(self):296 self._execute_on_webelement(297 lambda it: self._actions_chains.move_to_element(it).perform(),298 condition=be.visible)299 return self300 # *** ISearchContext methods ***301 def find_elements(self, by=By.ID, value=None):302 return self._execute_on_webelement(303 lambda it: it.find_elements(by, value),304 condition=be.visible)305 # return self.__delegate__.find_elements(by, value) # todo: remove306 def find_element(self, by=By.ID, value=None):307 return self._execute_on_webelement(308 lambda it: it.find_element(by, value),309 condition=be.visible)310 # return self.__delegate__.find_element(by, value) # todo: remove311 # *** IWebElement methods ***312 @property313 def tag_name(self):314 return self._execute_on_webelement(315 lambda it: it.tag_name,316 condition=be.in_dom)317 @property318 def text(self):319 return self._execute_on_webelement(320 lambda it: it.text,321 condition=be.visible)322 def click(self):323 self._execute_on_webelement(324 lambda it: it.click(),325 condition=be.visible)326 return self # todo: think on: IWebElement#click was supposed to return None327 def submit(self):328 self._execute_on_webelement(329 lambda it: it.submit(),330 condition=be.visible)331 return self332 def clear(self):333 self._execute_on_webelement(334 lambda it: it.clear(),335 condition=be.visible)336 return self337 def get_attribute(self, name):338 return self._execute_on_webelement(339 lambda it: it.get_attribute(name),340 condition=be.in_dom)341 def is_selected(self):342 return self._execute_on_webelement(343 lambda it: it.is_selected(),344 condition=be.visible)345 def is_enabled(self):346 return self._execute_on_webelement(347 lambda it: it.is_enabled(),348 condition=be.visible)349 def send_keys(self, *value):350 self._execute_on_webelement(351 lambda it: it.send_keys(*value),352 condition=be.visible)353 return self354 # RenderedWebElement Items355 def is_displayed(self):356 return self._execute_on_webelement(357 lambda it: it.is_displayed(),358 condition=be.in_dom)359 @property360 def location_once_scrolled_into_view(self):361 return self._execute_on_webelement(362 lambda it: it.location_once_scrolled_into_view,363 condition=be.visible)364 @property365 def size(self):366 return self._execute_on_webelement(367 lambda it: it.size,368 condition=be.visible)369 def value_of_css_property(self, property_name):370 return self._execute_on_webelement(371 lambda it: it.value_of_css_property(property_name),372 condition=be.in_dom)373 @property374 def location(self):375 return self._execute_on_webelement(376 lambda it: it.location,377 condition=be.visible)378 @property379 def rect(self):380 return self._execute_on_webelement(381 lambda it: it.rect,382 condition=be.visible)383 @property384 def screenshot_as_base64(self):385 return self._execute_on_webelement(386 lambda it: it.screenshot_as_base64,387 condition=be.visible) # todo: or `be.in_dom`?388 @property389 def screenshot_as_png(self):390 return self._execute_on_webelement(391 lambda it: it.screenshot_as_png,392 condition=be.visible) # todo: or `be.in_dom`?393 def screenshot(self, filename):394 return self._execute_on_webelement(395 lambda it: it.screenshot(filename),396 condition=be.visible) # todo: or `be.in_dom`?397 @property398 def parent(self):399 return self._execute_on_webelement(400 lambda it: it.parent, # todo: should not we return here some Selene entity as search_context?401 condition=be.in_dom)402 @property403 def id(self):404 return self._execute_on_webelement(405 lambda it: it.id,406 condition=be.in_dom)407class SeleneCollection(with_metaclass(DelegatingMeta, Sequence)):408 """409 To fully match Selenium, SeleneCollection should extend collection.abc.MutableSequence.410 But that's the place where we should be more restrictive.411 It is actually the Selenium, who should use "Sequence" instead of "MutableSequence" (list)412 """413 @property414 def __delegate__(self):415 # type: () -> List[IWebElement]416 return self._locator.find()417 def get_actual_webelements(self):418 # type: () -> List[IWebElement]419 return self.__delegate__420 def __call__(self):421 # type: () -> List[IWebElement]422 return self.__delegate__423 @classmethod424 def by(cls, by, webdriver, context=None):425 # type: (Tuple[str, str], IWebDriver, ISearchContext) -> SeleneCollection426 if not context:427 context = webdriver428 return SeleneCollection(WebdriverListWebElementLocator(by, context), webdriver)429 @classmethod430 def by_css(cls, css_selector, webdriver, context=None):431 # type: (str, IWebDriver, ISearchContext) -> SeleneCollection432 if not context:433 context = webdriver434 return SeleneCollection.by((By.CSS_SELECTOR, css_selector), webdriver, context)435 @classmethod436 def by_css_or_by(cls, css_selector_or_by, webdriver, context=None):437 if not context:438 context = webdriver439 return SeleneCollection.by(css_or_by_to_by(css_selector_or_by), webdriver, context)440 def __init__(self, selene_locator, webdriver):441 # type: (ISeleneListWebElementLocator, IWebDriver) -> None442 self._locator = selene_locator443 self._webdriver = webdriver444 # todo: consider adding self.cashing, self.cashed - like for SeleneElement445 def __str__(self):446 return self._locator.description447 # todo: consider extracting the following not DRY should methods to BaseMixin, or even better: some WaitObject448 # to be mixed in to both Selene Element and Collection449 # Points to think about:450 # * this may break DelegatingMeta logic (because we will have multiple inheritance...)451 # * this will Inheritance... Should not we at least use Composition here?452 def should(self, condition, timeout=None):453 if timeout is None:454 timeout = config.timeout455 _wait_with_screenshot(self._webdriver, self, condition, timeout)456 return self457 # todo: consider removing some aliases458 def assure(self, condition, timeout=None):459 return self.should(condition, timeout)460 def should_be(self, condition, timeout=None):461 return self.should(condition, timeout)462 def should_have(self, condition, timeout=None):463 return self.should(condition, timeout)464 def should_not(self, condition, timeout=None):465 if timeout is None:466 timeout = config.timeout467 # todo: implement proper cashing468 not_condition = not_(condition)469 _wait_with_screenshot(self._webdriver, self, not_condition, timeout)470 return self471 # todo: consider removing some aliases are even all of them472 def assure_not(self, condition, timeout=None):473 return self.should_not(condition, timeout)474 def should_not_be(self, condition, timeout=None):475 return self.should_not(condition, timeout)476 def should_not_have(self, condition, timeout=None):477 return self.should_not(condition, timeout)478 def should_each(self, condition, timeout=None):479 if timeout is None:480 timeout = config.timeout481 for selement in self:482 selement.should(condition, timeout)483 def assure_each(self, condition, timeout=None):484 return self.should_each(condition, timeout)485 def should_each_not(self, condition, timeout=None):486 if timeout is None:...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!