You are here

public function MediaBrowserContext::completeSelection in Lightning Media 8.3

Same name and namespace in other branches
  1. 8 tests/contexts/MediaBrowserContext.behat.inc \Acquia\LightningExtension\Context\MediaBrowserContext::completeSelection()
  2. 8.2 tests/contexts/MediaBrowserContext.behat.inc \Acquia\LightningExtension\Context\MediaBrowserContext::completeSelection()

Completes the media browser selection.

@When I complete the media browser selection

File

tests/contexts/MediaBrowserContext.behat.inc, line 120

Class

MediaBrowserContext
Contains step definitions for interacting with Lightning's media browser.

Namespace

Acquia\LightningExtension\Context

Code

public function completeSelection() {
  $assert = $this
    ->assertSession();
  $session = $this
    ->getSession();
  $frame = $session
    ->evaluateScript('window.name') ?: $session
    ->evaluateScript('window.active_iframe.name');
  Assert::notEmpty($frame);
  $button = $assert
    ->elementExists('named', [
    'button',
    'Place',
  ])
    ->getXpath();

  // Switch out of the iFrame, because it will be destroyed as soon as we
  // press the button.
  $session
    ->switchToIFrame();
  $js = <<<END
document.evaluate('{<span class="php-variable">$button</span>}', window.{<span class="php-variable">$frame</span>}.document, null).iterateNext().click();
END;
  $session
    ->executeScript($js);
  $this
    ->awaitElement('form.entity-embed-dialog');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Embed');
  $this
    ->awaitAjax();
}