function DrupalSelenium2Driver::setCookie

Same name in other branches
  1. 9 core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php \Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver::setCookie()
  2. 8.9.x core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php \Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver::setCookie()

File

core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php, line 30

Class

DrupalSelenium2Driver
Provides a driver for Selenium testing.

Namespace

Drupal\FunctionalJavascriptTests

Code

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),
        'expires' => time() + 80000,
    ];
    $this->getWebDriverSession()
        ->setCookie($cookieArray);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.