Guest User

Untitled

a guest
Nov 12th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. public void waitUntilCountChanges() {
  2. WebDriverWait wait = new WebDriverWait(getDriver(), 5);
  3. wait.until(new ExpectedCondition<Boolean>() {
  4. public Boolean apply(WebDriver driver) {
  5. int elementCount = driver.findElement(By.xpath("xxxx")).size();
  6. if (elementCount > 1)
  7. return true;
  8. else
  9. return false;
  10. }
  11. });
  12. }
  13.  
  14. public function spin ($lambda, $wait = 60) {
  15. for ($i = 0; $i < $wait; $i++) {
  16. try {
  17. if ($lambda($this)) {
  18. return true;
  19. }
  20. } catch (Exception $e) {
  21. // do nothing
  22. }
  23.  
  24. sleep(1);
  25. }
  26.  
  27. $backtrace = debug_backtrace();
  28.  
  29. throw new Exception(
  30. "Timeout thrown by " . $backtrace[1]['class'] . "::" . $backtrace[1]['function'] . "()n" .
  31. $backtrace[1]['file'] . ", line " . $backtrace[1]['line']
  32. );
  33. }
  34.  
  35. $this->spin(function($context) {
  36. return ($context->getSession()->getPage()->findById('example')->isVisible());
  37. });
  38.  
  39. start_time=now
  40. count=number of elements
  41. while count < X:
  42. count=number of elements
  43. if now - start_time > timeout
  44. exit loop
Add Comment
Please, Sign In to add comment