Chris@0: tempFilesDirectory . DIRECTORY_SEPARATOR . 'browsertestbase-templatecache'; Chris@0: $this->minkDefaultDriverArgs = [ Chris@0: 'http://127.0.0.1:8510', Chris@0: $path, Chris@0: ]; Chris@0: if (!file_exists($path)) { Chris@0: mkdir($path); Chris@0: } Chris@0: Chris@0: try { Chris@0: return parent::initMink(); Chris@0: } Chris@0: catch (DeadClient $e) { Chris@0: $this->markTestSkipped('PhantomJS is either not installed or not running. Start it via phantomjs --ssl-protocol=any --ignore-ssl-errors=true vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768&'); Chris@0: } Chris@0: catch (\Exception $e) { Chris@0: $this->markTestSkipped('An unexpected error occurred while starting Mink: ' . $e->getMessage()); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function tearDown() { Chris@0: if ($this->mink) { Chris@0: // Wait for all requests to finish. It is possible that an AJAX request is Chris@0: // still on-going. Chris@0: $result = $this->getSession()->wait(5000, '(typeof(jQuery)=="undefined" || (0 === jQuery.active && 0 === jQuery(\':animated\').length))'); Chris@0: if (!$result) { Chris@0: // If the wait is unsuccessful, there may still be an AJAX request in Chris@0: // progress. If we tear down now, then this AJAX request may fail with Chris@0: // missing database tables, because tear down will have removed them. Chris@0: // Rather than allow it to fail, throw an explicit exception now Chris@0: // explaining what the problem is. Chris@0: throw new \RuntimeException('Unfinished AJAX requests while tearing down a test'); Chris@0: } Chris@0: } Chris@0: parent::tearDown(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Asserts that the element with the given CSS selector is visible. Chris@0: * Chris@0: * @param string $css_selector Chris@0: * The CSS selector identifying the element to check. Chris@0: * @param string $message Chris@0: * Optional message to show alongside the assertion. Chris@0: * Chris@0: * @deprecated in Drupal 8.1.x, will be removed before Drupal 8.3.x. Use Chris@0: * \Behat\Mink\Element\NodeElement::isVisible() instead. Chris@0: */ Chris@0: protected function assertElementVisible($css_selector, $message = '') { Chris@0: $this->assertTrue($this->getSession()->getDriver()->isVisible($this->cssSelectToXpath($css_selector)), $message); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Asserts that the element with the given CSS selector is not visible. Chris@0: * Chris@0: * @param string $css_selector Chris@0: * The CSS selector identifying the element to check. Chris@0: * @param string $message Chris@0: * Optional message to show alongside the assertion. Chris@0: * Chris@0: * @deprecated in Drupal 8.1.x, will be removed before Drupal 8.3.x. Use Chris@0: * \Behat\Mink\Element\NodeElement::isVisible() instead. Chris@0: */ Chris@0: protected function assertElementNotVisible($css_selector, $message = '') { Chris@0: $this->assertFalse($this->getSession()->getDriver()->isVisible($this->cssSelectToXpath($css_selector)), $message); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Waits for the given time or until the given JS condition becomes TRUE. Chris@0: * Chris@0: * @param string $condition Chris@0: * JS condition to wait until it becomes TRUE. Chris@0: * @param int $timeout Chris@0: * (Optional) Timeout in milliseconds, defaults to 10000. Chris@0: * @param string $message Chris@0: * (optional) A message to display with the assertion. If left blank, a Chris@0: * default message will be displayed. Chris@0: * Chris@0: * @throws \PHPUnit_Framework_AssertionFailedError Chris@0: * Chris@0: * @see \Behat\Mink\Driver\DriverInterface::evaluateScript() Chris@0: */ Chris@0: protected function assertJsCondition($condition, $timeout = 10000, $message = '') { Chris@0: $message = $message ?: "Javascript condition met:\n" . $condition; Chris@0: $result = $this->getSession()->getDriver()->wait($timeout, $condition); Chris@0: $this->assertTrue($result, $message); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates a screenshot. Chris@0: * Chris@0: * @param string $filename Chris@0: * The file name of the resulting screenshot. If using the default phantomjs Chris@0: * driver then this should be a JPG filename. Chris@0: * @param bool $set_background_color Chris@0: * (optional) By default this method will set the background color to white. Chris@0: * Set to FALSE to override this behaviour. Chris@0: * Chris@0: * @throws \Behat\Mink\Exception\UnsupportedDriverActionException Chris@0: * When operation not supported by the driver. Chris@0: * @throws \Behat\Mink\Exception\DriverException Chris@0: * When the operation cannot be done. Chris@0: */ Chris@0: protected function createScreenshot($filename, $set_background_color = TRUE) { Chris@0: $session = $this->getSession(); Chris@0: if ($set_background_color) { Chris@0: $session->executeScript("document.body.style.backgroundColor = 'white';"); Chris@0: } Chris@0: $image = $session->getScreenshot(); Chris@0: file_put_contents($filename, $image); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function assertSession($name = NULL) { Chris@0: return new WebDriverWebAssert($this->getSession($name), $this->baseUrl); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the current Drupal javascript settings and parses into an array. Chris@0: * Chris@0: * Unlike BrowserTestBase::getDrupalSettings(), this implementation reads the Chris@0: * current values of drupalSettings, capturing all changes made via javascript Chris@0: * after the page was loaded. Chris@0: * Chris@0: * @return array Chris@0: * The Drupal javascript settings array. Chris@0: * Chris@0: * @see \Drupal\Tests\BrowserTestBase::getDrupalSettings() Chris@0: */ Chris@0: protected function getDrupalSettings() { Chris@0: $script = <<getSession()->evaluateScript($script) ?: []; Chris@0: } Chris@0: Chris@0: }