From a6e0890ca930aad35f63e3f4a93797101604c9d7 Mon Sep 17 00:00:00 2001 From: benjamin-vauchel-webrivage Date: Fri, 11 Sep 2020 12:12:48 +0200 Subject: [PATCH] Fix HttpCallListener when Mink driver is not started yet --- .travis.yml | 7 ++++--- src/Context/BrowserContext.php | 4 +++- src/HttpCall/HttpCallListener.php | 8 +++++--- tests/features/browser.feature | 6 +++++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index cb7db35d..63e0999b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: php -dist: trusty +dist: xenial addons: chrome: stable @@ -44,8 +44,9 @@ matrix: before_script: - Xvfb $DISPLAY -extension RANDR &> /dev/null & - - LATEST_CHROMEDRIVER_VERSION=`curl http://chromedriver.storage.googleapis.com/LATEST_RELEASE` - - wget --no-verbose https://chromedriver.storage.googleapis.com/$LATEST_CHROMEDRIVER_VERSION/chromedriver_linux64.zip + - CHROME_MAIN_VERSION=`google-chrome-stable --version | sed -E 's/(^Google Chrome |\.[0-9]+ )//g'` + - CHROMEDRIVER_VERSION=`curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_MAIN_VERSION"` + - wget --no-verbose "https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip" - unzip chromedriver_linux64.zip -d ~/bin - wget "https://selenium-release.storage.googleapis.com/${SELENIUM_VERSION%%.[[:digit:]]}/selenium-server-standalone-${SELENIUM_VERSION}.jar" -O selenium.jar diff --git a/src/Context/BrowserContext.php b/src/Context/BrowserContext.php index f09d04cd..81c3e65d 100644 --- a/src/Context/BrowserContext.php +++ b/src/Context/BrowserContext.php @@ -25,7 +25,9 @@ public function __construct($timeout = 1) */ public function closeBrowser() { - $this->getSession()->stop(); + if ($this->getMink()->isSessionStarted()) { + $this->getSession()->stop(); + } } /** diff --git a/src/HttpCall/HttpCallListener.php b/src/HttpCall/HttpCallListener.php index 4ac5f23c..f7d5afb8 100644 --- a/src/HttpCall/HttpCallListener.php +++ b/src/HttpCall/HttpCallListener.php @@ -51,9 +51,11 @@ public function afterStep(AfterStepTested $event) // For now to avoid modification on MinkContext // We add fallback on Mink try { - $this->httpCallResultPool->store( - new HttpCallResult($this->mink->getSession()->getPage()->getContent()) - ); + if ($this->mink->getSession()->isStarted()) { + $this->httpCallResultPool->store( + new HttpCallResult($this->mink->getSession()->getPage()->getContent()) + ); + } } catch (\LogicException $e) { // Mink has no response } catch (\Behat\Mink\Exception\DriverException $e) { diff --git a/tests/features/browser.feature b/tests/features/browser.feature index e9939f5d..f5a8b17d 100644 --- a/tests/features/browser.feature +++ b/tests/features/browser.feature @@ -1,8 +1,12 @@ Feature: Browser Feature + @javascript + Scenario: Testing when scenario has no HTTP call + Given I wait 0.1 seconds + # If this scenario fails # It's probably because your web environment is not properly setup - # You will find the necessery help in README.md + # You will find the necessary help in README.md @javascript Scenario: Testing simple web access Given I am on "/index.html"