getWebDriverSession example

// Test click a contextual link that uses ajax.     $this->drupalGet('user');
    $this->assertSession()->assertWaitOnAjaxRequest();
    $current_page_string = 'NOT_RELOADED_IF_ON_PAGE';
    $this->getSession()->executeScript('document.body.appendChild(document.createTextNode("' . $current_page_string . '"));');

    // Move the pointer over the branding block so the contextual link appears     // as it would with a real user interaction. Otherwise clickContextualLink()     // does not open the dialog in a manner that is opener-aware, and it isn't     // possible to reliably test focus management.     $driver_session = $this->getSession()->getDriver()->getWebDriverSession();
    $element = $driver_session->element('css selector', '#block-branding');
    $driver_session->moveto(['element' => $element->getID()]);
    $this->clickContextualLink('#block-branding', 'Test Link with Ajax', FALSE);
    $this->assertNotEmpty($this->assertSession()->waitForElementVisible('css', '#drupal-modal'));
    $this->assertSession()->elementContains('css', '#drupal-modal', 'Everything is contextual!');
    $this->getSession()->executeScript('document.querySelector("#block-branding .trigger").addEventListener("focus", (e) => e.target.classList.add("i-am-focused"))');
    $this->getSession()->getPage()->pressButton('Close');
    $this->assertSession()->assertNoElementAfterWait('css', 'ui.dialog');

    // When the dialog is closed, the opening contextual link is now inside a     // collapsed container, so focus should be routed to the contextual link

  public function __construct($browserName = 'firefox', $desiredCapabilities = NULL, $wdHost = 'http://localhost:4444/wd/hub') {
    parent::__construct($browserName$desiredCapabilities$wdHost);
    ServiceFactory::getInstance()->setServiceClass('service.curl', WebDriverCurlService::class);
  }

  /** * {@inheritdoc} */
  public function setCookie($name$value = NULL) {
    if ($value === NULL) {
      $this->getWebDriverSession()->deleteCookie($name);
      return;
    }

    $cookieArray = [
      'name' => $name,
      'value' => urlencode($value),
      'secure' => FALSE,
      // Unlike \Behat\Mink\Driver\Selenium2Driver::setCookie we set a domain       // and an expire date, as otherwise cookies leak from one test site into       // another.       'domain' => parse_url($this->getWebDriverSession()->url(), PHP_URL_HOST),
      
{$selector}', '{$key}') JS;

    $options = [
      'script' => $script,
      'args' => [],
    ];

    $this->getSession()->getDriver()->getWebDriverSession()->execute($options);
  }

  /** * Decorates ::fieldValueEquals() to force DrupalCI to provide useful errors. * * @param string $field * Field id|name|label|value. * @param string $value * Field value. * @param \Behat\Mink\Element\TraversableElement $container * Document to check against. * * @throws \Behat\Mink\Exception\ExpectationException * * @see \Behat\Mink\WebAssert::fieldValueEquals() */
{$item}', '{$from}', '{$to}') JS;

    $options = [
      'script' => $script,
      'args'   => [],
    ];

    $this->getSession()->getDriver()->getWebDriverSession()->execute($options);
  }

}
$this->assertWaitPageContains('my/file.css');

    // Tests the 'after' command.     $page->pressButton("AJAX 'After': Click to put something after the div");
    $this->assertWaitPageContains('<div id="after_div">Something can be inserted after this</div>This will be placed after');

    // Tests the 'alert' command.     $page->pressButton("AJAX 'Alert': Click to alert");
    // Wait for the alert to appear.     $page->waitFor(10, function D) use ($session) {
      try {
        $session->getDriver()->getWebDriverSession()->getAlert_text();
        return TRUE;
      }
      catch (\Exception $e) {
        return FALSE;
      }
    });
    $alert_text = $this->getSession()->getDriver()->getWebDriverSession()->getAlert_text();
    $this->assertEquals('Alert', $alert_text);
    $this->getSession()->getDriver()->getWebDriverSession()->accept_alert();

    $this->drupalGet($form_path);
    
$this->assertContains($position_type['top', 'bottom'], 'Expected position type.');
    return (int) $this->getSession()->evaluateScript("document.querySelector('$css_selector').getBoundingClientRect().$position_type + window.pageYOffset");
  }

  /** * Moves mouse pointer to location of $selector. * * @param string $selector * CSS selector. */
  protected function movePointerTo($selector) {
    $driver_session = $this->getSession()->getDriver()->getWebDriverSession();
    $element = $driver_session->element('css selector', $selector);
    $driver_session->moveto(['element' => $element->getID()]);
  }

}
{$item}', '{$to}') JS;

    $options = [
      'script' => $script,
      'args'   => [],
    ];

    $this->getSession()->getDriver()->getWebDriverSession()->execute($options);
    $this->sortableUpdate($item$from$to);
  }

  /** * Simulates a drag moving an element after its sibling in the same container. * * @param string $item * The HTML selector for the element to be moved. * @param string $target * The HTML selector for the sibling element. * @param string $from * The HTML selector for the element container. */
Home | Imprint | This part of the site doesn't use cookies.