You are here

public function BlazyJavaScriptTestBase::doTestFormatterDisplay in Blazy 8.2

Test the Blazy element from loading to loaded states.

2 calls to BlazyJavaScriptTestBase::doTestFormatterDisplay()
BlazyBlazyJavaScriptTest::testFormatterDisplay in tests/src/FunctionalJavascript/BlazyBlazyJavaScriptTest.php
Test the Blazy element from loading to loaded states.
BlazyIoJavaScriptTest::testFormatterDisplay in tests/src/FunctionalJavascript/BlazyIoJavaScriptTest.php
Test the Blazy element from loading to loaded states.

File

tests/src/FunctionalJavascript/BlazyJavaScriptTestBase.php, line 64

Class

BlazyJavaScriptTestBase
Tests the Blazy JavaScript using PhantomJS, or Chromedriver.

Namespace

Drupal\Tests\blazy\FunctionalJavascript

Code

public function doTestFormatterDisplay() {
  $image_path = $this
    ->getImagePath(TRUE);

  // Capture the initial page load moment.
  $this
    ->createScreenshot($image_path . '/' . $this->scriptLoader . '_1_initial.png');
  $this
    ->assertSession()
    ->elementExists('css', '.b-lazy');

  // Trigger Blazy to load images by scrolling down window.
  $this
    ->getSession()
    ->executeScript('window.scrollTo(0, document.body.scrollHeight);');

  // Capture the loading moment after scrolling down the window.
  $this
    ->createScreenshot($image_path . '/' . $this->scriptLoader . '_2_loading.png');

  // Wait a moment.
  $this
    ->getSession()
    ->wait(3000);

  // Verifies that one of the images is there once loaded.
  $this
    ->assertNotEmpty($this
    ->assertSession()
    ->waitForElement('css', '.b-loaded'));

  // Capture the loaded moment.
  // The screenshots are at sites/default/files/simpletest/blazy.
  $this
    ->createScreenshot($image_path . '/' . $this->scriptLoader . '_3_loaded.png');
}