How to use _wait_until method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

waiting.py

Source:waiting.py Github

copy

Full Screen

...44 if "return" not in condition:45 raise ValueError(46 f"Condition '{condition}' did not have mandatory 'return'."47 )48 self._wait_until(49 lambda: self.driver.execute_script(condition) is True,50 f"Condition '{condition}' did not become true in <TIMEOUT>.",51 timeout,52 error,53 )54 @keyword55 def wait_until_location_is(56 self,57 expected: str,58 timeout: Optional[timedelta] = None,59 message: Optional[str] = None,60 ):61 """Waits until the current URL is ``expected``.62 The ``expected`` argument is the expected value in url.63 Fails if ``timeout`` expires before the location is. See64 the `Timeouts` section for more information about using timeouts65 and their default value.66 The ``message`` argument can be used to override the default error67 message.68 New in SeleniumLibrary 4.069 """70 expected = str(expected)71 self._wait_until(72 lambda: expected == self.driver.current_url,73 f"Location did not become '{expected}' in <TIMEOUT>.",74 timeout,75 message,76 )77 @keyword78 def wait_until_location_is_not(79 self,80 location: str,81 timeout: Optional[timedelta] = None,82 message: Optional[str] = None,83 ):84 """Waits until the current URL is not ``location``.85 The ``location`` argument is the unexpected value in url.86 Fails if ``timeout`` expires before the location is not. See87 the `Timeouts` section for more information about using timeouts88 and their default value.89 The ``message`` argument can be used to override the default error90 message.91 New in SeleniumLibrary 4.392 """93 location = str(location)94 self._wait_until(95 lambda: location != self.driver.current_url,96 f"Location is '{location}' in <TIMEOUT>.",97 timeout,98 message,99 )100 @keyword101 def wait_until_location_contains(102 self,103 expected: str,104 timeout: Optional[timedelta] = None,105 message: Optional[str] = None,106 ):107 """Waits until the current URL contains ``expected``.108 The ``expected`` argument contains the expected value in url.109 Fails if ``timeout`` expires before the location contains. See110 the `Timeouts` section for more information about using timeouts111 and their default value.112 The ``message`` argument can be used to override the default error113 message.114 New in SeleniumLibrary 4.0115 """116 expected = str(expected)117 self._wait_until(118 lambda: expected in self.driver.current_url,119 f"Location did not contain '{expected}' in <TIMEOUT>.",120 timeout,121 message,122 )123 @keyword124 def wait_until_location_does_not_contain(125 self,126 location: str,127 timeout: Optional[timedelta] = None,128 message: Optional[str] = None,129 ):130 """Waits until the current URL does not contains ``location``.131 The ``location`` argument contains value not expected in url.132 Fails if ``timeout`` expires before the location not contains. See133 the `Timeouts` section for more information about using timeouts134 and their default value.135 The ``message`` argument can be used to override the default error136 message.137 New in SeleniumLibrary 4.3138 """139 location = str(location)140 self._wait_until(141 lambda: location not in self.driver.current_url,142 f"Location did contain '{location}' in <TIMEOUT>.",143 timeout,144 message,145 )146 @keyword147 def wait_until_page_contains(148 self,149 text: str,150 timeout: Optional[timedelta] = None,151 error: Optional[str] = None,152 ):153 """Waits until ``text`` appears on the current page.154 Fails if ``timeout`` expires before the text appears. See155 the `Timeouts` section for more information about using timeouts156 and their default value.157 ``error`` can be used to override the default error message.158 """159 self._wait_until(160 lambda: self.is_text_present(text),161 f"Text '{text}' did not appear in <TIMEOUT>.",162 timeout,163 error,164 )165 @keyword166 def wait_until_page_does_not_contain(167 self,168 text: str,169 timeout: Optional[timedelta] = None,170 error: Optional[str] = None,171 ):172 """Waits until ``text`` disappears from the current page.173 Fails if ``timeout`` expires before the text disappears. See174 the `Timeouts` section for more information about using timeouts175 and their default value.176 ``error`` can be used to override the default error message.177 """178 self._wait_until(179 lambda: not self.is_text_present(text),180 f"Text '{text}' did not disappear in <TIMEOUT>.",181 timeout,182 error,183 )184 @keyword185 def wait_until_page_contains_element(186 self,187 locator: str,188 timeout: Optional[timedelta] = None,189 error: Optional[str] = None,190 limit: Optional[int] = None,191 ):192 """Waits until the element ``locator`` appears on the current page.193 Fails if ``timeout`` expires before the element appears. See194 the `Timeouts` section for more information about using timeouts and195 their default value and the `Locating elements` section for details196 about the locator syntax.197 ``error`` can be used to override the default error message.198 The ``limit`` argument can used to define how many elements the199 page should contain. When ``limit`` is `None` (default) page can200 contain one or more elements. When limit is a number, page must201 contain same number of elements.202 ``limit`` is new in SeleniumLibrary 4.4203 """204 if limit is None:205 return self._wait_until(206 lambda: self.find_element(locator, required=False) is not None,207 f"Element '{locator}' did not appear in <TIMEOUT>.",208 timeout,209 error,210 )211 self._wait_until(212 lambda: len(self.find_elements(locator)) == limit,213 f'Page should have contained "{limit}" {locator} element(s) within <TIMEOUT>.',214 timeout,215 error,216 )217 @keyword218 def wait_until_page_does_not_contain_element(219 self,220 locator: str,221 timeout: Optional[timedelta] = None,222 error: Optional[str] = None,223 limit: Optional[int] = None,224 ):225 """Waits until the element ``locator`` disappears from the current page.226 Fails if ``timeout`` expires before the element disappears. See227 the `Timeouts` section for more information about using timeouts and228 their default value and the `Locating elements` section for details229 about the locator syntax.230 ``error`` can be used to override the default error message.231 The ``limit`` argument can used to define how many elements the232 page should not contain. When ``limit`` is `None` (default) page can`t233 contain any elements. When limit is a number, page must not234 contain same number of elements.235 ``limit`` is new in SeleniumLibrary 4.4236 """237 if limit is None:238 return self._wait_until(239 lambda: self.find_element(locator, required=False) is None,240 f"Element '{locator}' did not disappear in <TIMEOUT>.",241 timeout,242 error,243 )244 self._wait_until(245 lambda: len(self.find_elements(locator)) != limit,246 f'Page should have not contained "{limit}" {locator} element(s) within <TIMEOUT>.',247 timeout,248 error,249 )250 @keyword251 def wait_until_element_is_visible(252 self,253 locator: str,254 timeout: Optional[timedelta] = None,255 error: Optional[str] = None,256 ):257 """Waits until the element ``locator`` is visible.258 Fails if ``timeout`` expires before the element is visible. See259 the `Timeouts` section for more information about using timeouts and260 their default value and the `Locating elements` section for details261 about the locator syntax.262 ``error`` can be used to override the default error message.263 """264 self._wait_until(265 lambda: self.is_visible(locator),266 f"Element '{locator}' not visible after <TIMEOUT>.",267 timeout,268 error,269 )270 @keyword271 def wait_until_element_is_not_visible(272 self,273 locator: str,274 timeout: Optional[timedelta] = None,275 error: Optional[str] = None,276 ):277 """Waits until the element ``locator`` is not visible.278 Fails if ``timeout`` expires before the element is not visible. See279 the `Timeouts` section for more information about using timeouts and280 their default value and the `Locating elements` section for details281 about the locator syntax.282 ``error`` can be used to override the default error message.283 """284 self._wait_until(285 lambda: not self.is_visible(locator),286 f"Element '{locator}' still visible after <TIMEOUT>.",287 timeout,288 error,289 )290 @keyword291 def wait_until_element_is_enabled(292 self,293 locator: str,294 timeout: Optional[timedelta] = None,295 error: Optional[str] = None,296 ):297 """Waits until the element ``locator`` is enabled.298 Element is considered enabled if it is not disabled nor read-only.299 Fails if ``timeout`` expires before the element is enabled. See300 the `Timeouts` section for more information about using timeouts and301 their default value and the `Locating elements` section for details302 about the locator syntax.303 ``error`` can be used to override the default error message.304 Considering read-only elements to be disabled is a new feature305 in SeleniumLibrary 3.0.306 """307 self._wait_until(308 lambda: self.is_element_enabled(locator),309 f"Element '{locator}' was not enabled in <TIMEOUT>.",310 timeout,311 error,312 )313 @keyword314 def wait_until_element_contains(315 self,316 locator: str,317 text: str,318 timeout: Optional[timedelta] = None,319 error: Optional[str] = None,320 ):321 """Waits until the element ``locator`` contains ``text``.322 Fails if ``timeout`` expires before the text appears. See323 the `Timeouts` section for more information about using timeouts and324 their default value and the `Locating elements` section for details325 about the locator syntax.326 ``error`` can be used to override the default error message.327 """328 self._wait_until(329 lambda: text in self.find_element(locator).text,330 f"Element '{locator}' did not get text '{text}' in <TIMEOUT>.",331 timeout,332 error,333 )334 @keyword335 def wait_until_element_does_not_contain(336 self,337 locator: str,338 text: str,339 timeout: Optional[timedelta] = None,340 error: Optional[str] = None,341 ):342 """Waits until the element ``locator`` does not contain ``text``.343 Fails if ``timeout`` expires before the text disappears. See344 the `Timeouts` section for more information about using timeouts and345 their default value and the `Locating elements` section for details346 about the locator syntax.347 ``error`` can be used to override the default error message.348 """349 self._wait_until(350 lambda: text not in self.find_element(locator).text,351 f"Element '{locator}' still had text '{text}' after <TIMEOUT>.",352 timeout,353 error,354 )355 def _wait_until(self, condition, error, timeout=None, custom_error=None):356 timeout = self.get_timeout(timeout)357 if custom_error is None:358 error = error.replace("<TIMEOUT>", secs_to_timestr(timeout))359 else:360 error = custom_error361 self._wait_until_worker(condition, timeout, error)362 def _wait_until_worker(self, condition, timeout, error):363 max_time = time.time() + timeout364 not_found = None365 while time.time() < max_time:366 try:367 if condition():368 return369 except ElementNotFound as err:...

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 robotframework-appiumlibrary 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