You are here

protected function MediaLibraryTestBase::waitForElementsCount in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTestBase::waitForElementsCount()

Checks for a specified number of specific elements on page after wait.

@todo replace with whatever gets added in https://www.drupal.org/node/3061852

Parameters

string $selector_type: Element selector type (css, xpath)

string|array $selector: Element selector.

int $count: Expected count.

int $timeout: Timeout in milliseconds, defaults to 10000.

2 calls to MediaLibraryTestBase::waitForElementsCount()
EntityReferenceWidgetTest::testWidget in core/modules/media_library/tests/src/FunctionalJavascript/EntityReferenceWidgetTest.php
Tests that the Media library's widget works as expected.
ViewsUiIntegrationTest::testViewsAdmin in core/modules/media_library/tests/src/FunctionalJavascript/ViewsUiIntegrationTest.php
Tests that the integration with Views works correctly.

File

core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php, line 104

Class

MediaLibraryTestBase
Base class for functional tests of Media Library functionality.

Namespace

Drupal\Tests\media_library\FunctionalJavascript

Code

protected function waitForElementsCount($selector_type, $selector, $count, $timeout = 10000) {
  $page = $this
    ->getSession()
    ->getPage();
  $start = microtime(TRUE);
  $end = $start + $timeout / 1000;
  do {
    $nodes = $page
      ->findAll($selector_type, $selector);
    if (count($nodes) === $count) {
      return;
    }
    usleep(100000);
  } while (microtime(TRUE) < $end);
  $this
    ->assertSession()
    ->elementsCount($selector_type, $selector, $count);
}