You are here

public function CheckoutTest::switchToFrame in Commerce Stripe 8

Waits for a frame to become available and then switches to it.

Parameters

string $name: The frame name.

int $wait: The wait time, in seconds.

Return value

bool Returns TRUE if operation succeeds.

Throws

\Exception

2 calls to CheckoutTest::switchToFrame()
CheckoutTest::complete3ds in tests/src/FunctionalJavascript/CheckoutTest.php
Completes 3DS authentication using Stripe's modal.
CheckoutTest::switchToElementFrame in tests/src/FunctionalJavascript/CheckoutTest.php
Switch to the first iframe which ancestor is the given div element id.

File

tests/src/FunctionalJavascript/CheckoutTest.php, line 538

Class

CheckoutTest
Tests checkout with Stripe.

Namespace

Drupal\Tests\commerce_stripe\FunctionalJavascript

Code

public function switchToFrame($name, $wait = 20) {
  $last_exception = NULL;
  $stopTime = time() + $wait;
  while (time() < $stopTime) {
    try {
      $element = $this
        ->assertSession()
        ->elementExists('xpath', "//iframe[@id='{$name}' or @name='{$name}' or starts-with(@name, '{$name}')]");
      $this
        ->getSession()
        ->switchToIFrame($element
        ->getAttribute('name'));
      sleep(1);
      return TRUE;
    } catch (\Exception $e) {

      // If the frame has not been found, keep waiting.
      $last_exception = $e;
    }
    usleep(250000);
  }
  throw $last_exception;
}