Commit 164c603c authored by catch's avatar catch
Browse files

Issue #3315227 by alexpott, Spokje, andypost, quietone:...

Issue #3315227 by alexpott, Spokje, andypost, quietone: Drupal\Tests\views\FunctionalJavascript\Plugin\views\Handler\FilterTest is failing a lot at the moment

(cherry picked from commit eb8c8d48)
parent c7381576
Loading
Loading
Loading
Loading
+1 −13
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@
use PHPUnit\Framework\Constraint\IsNull;
use PHPUnit\Framework\Constraint\LogicalNot;
use WebDriver\Exception;
use WebDriver\Exception\CurlExec;

// cspell:ignore interactable

@@ -156,18 +155,7 @@ public function waitForText($text, $timeout = 10000) {
   *   The result of $callback.
   */
  private function waitForHelper(int $timeout, callable $callback) {
    WebDriverCurlService::disableRetry();
    $wrapper = function (Element $element) use ($callback) {
      try {
        return call_user_func($callback, $element);
      }
      catch (CurlExec $e) {
        return NULL;
      }
    };
    $result = $this->session->getPage()->waitFor($timeout / 1000, $wrapper);
    WebDriverCurlService::enableRetry();
    return $result;
    return $this->session->getPage()->waitFor($timeout / 1000, $callback);
  }

  /**
+30 −0
Original line number Diff line number Diff line
@@ -7,7 +7,10 @@
namespace Drupal\Tests;

use Behat\Mink\Driver\BrowserKitDriver;
use Behat\Mink\Element\Element;
use Behat\Mink\Element\TraversableElement;
use Drupal\FunctionalJavascriptTests\WebDriverCurlService;
use WebDriver\Exception\CurlExec;

/**
 * Document element.
@@ -85,4 +88,31 @@ public function getText() {
    return parent::getText();
  }

  /**
   * {@inheritdoc}
   */
  public function waitFor($timeout, $callback) {
    // Wraps waits in a function to catch curl exceptions to continue waiting.
    WebDriverCurlService::disableRetry();
    $count = 0;
    $wrapper = function (Element $element) use ($callback, &$count) {
      $count++;
      try {
        return call_user_func($callback, $element);
      }
      catch (CurlExec $e) {
        return NULL;
      }
    };
    $result = parent::waitFor($timeout, $wrapper);
    if (!$result && $count < 2) {
      // If the callback or the system is really slow, then it might have only
      // fired once. In this case it is better to trigger it once more as the
      // page state has probably changed while the callback is running.
      return call_user_func($callback, $this);
    }
    WebDriverCurlService::enableRetry();
    return $result;
  }

}