Behatch / contexts

Behat extension with most custom helper steps
Other
394 stars 203 forks source link

Fix HttpCallListener when Mink driver is not started yet #292

Open benjamin-vauchel-webrivage opened 4 years ago

benjamin-vauchel-webrivage commented 4 years ago

Fix the following error when BehatchExtension is used with Selenium2 Mink driver :

`[11-Sep-2020 12:14:21 Europe/Paris] PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function source() on null in /app/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php:487 Stack trace:

0 /app/vendor/behat/mink/src/Element/DocumentElement.php(37): Behat\Mink\Driver\Selenium2Driver->getContent()

1 /app/vendor/behatch/contexts/src/HttpCall/HttpCallListener.php(55): Behat\Mink\Element\DocumentElement->getContent()

2 /app/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php(184): Behatch\HttpCall\HttpCallListener->afterStep(Object(Behat\Behat\EventDispatcher\Event\AfterStepTested), 'tester.step_tes...', Object(Behat\Testwork\EventDispatcher\TestworkEventDispatcher))

3 /app/vendor/behat/behat/src/Behat/Testwork/EventDispatcher/TestworkEventDispatcher.php(39): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(Array, 'tester.step_tes...', Object(Behat\Behat\EventDispatcher\Event\AfterStepTested))

4 /app/vendor/behat/behat/src/Behat/Behat/EventDispatcher/Tester/EventD in /app/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php on line 487

`

Behat\Mink\Driver\Selenium2Driver->getContent() is called whereas the driver hasn't started yet.

benjamin-vauchel-webrivage commented 3 years ago

@sanpii Could you take a look to the PR please ? ;)

robertfausk commented 3 years ago

This PR looks good to me :smiley: @benjamin-vauchel-webrivage Could you provide a test case too?

robertfausk commented 3 years ago

@benjamin-vauchel-webrivage FYI: I am using an adopted script for using related chrome driver version in my repo. https://github.com/robertfausk/behat-panther-extension/blob/master/bin/updatePantherChromeDriver.sh

#!/usr/bin/env bash
# ensure that symfony/panther's chromeDriver matches installed chromium version
# this needs chromium and symfony/panther (in vendor folder) to be installed

cd /srv/api/vendor/symfony/panther/chromedriver-bin

chromiumVersion=$(chromium --product-version 2>&1;);
chromiumBrowserVersion=$(chromium-browser --product-version 2>&1;);
googleChromeVersion=$(google-chrome --product-version 2>&1;);
if [[ ${chromiumVersion} == *"."*"."* ]]; then
  chromiumVersion="$( cut -d '.' -f 1 <<< "$chromiumVersion" )";
  echo "Found chromium version ${chromiumVersion}";
  chromeDriverVersion="_${chromiumVersion}"
elif [[ ${chromiumBrowserVersion} == *"."*"."* ]]; then
  chromiumBrowserVersion="$( cut -d '.' -f 1 <<< "$chromiumBrowserVersion" )";
  echo "Found chromium-browser version ${chromiumBrowserVersion}";
  chromeDriverVersion="_${chromiumBrowserVersion}"
elif [[ ${googleChromeVersion} == *"."*"."* ]]; then
  googleChromeVersion="$( cut -d '.' -f 1 <<< "$googleChromeVersion" )";
  echo "Found google-chrome version ${googleChromeVersion}";
  chromeDriverVersion="_${googleChromeVersion}"
else
  "No google-chrome, chromium-browser or chromium found. Using latest release..."
  chromeDriverVersion=""
fi

chromeDriver=$(curl -s https://chromedriver.storage.googleapis.com/LATEST_RELEASE${chromeDriverVersion});
echo "Downloading ChromeDriver version ${chromeDriver} from https://chromedriver.storage.googleapis.com/LATEST_RELEASE${chromeDriverVersion} ..."

declare -a binaries=("chromedriver_linux64" "chromedriver_mac64" "chromedriver_win32")
for name in "${binaries[@]}"
do
   curl -s https://chromedriver.storage.googleapis.com/${chromeDriver}/${name}.zip -O
   unzip -q -o ${name}.zip
   rm ${name}.zip
   if [[ -f "chromedriver" ]]; then
      mv chromedriver ${name}
   fi
done

curl -s https://chromedriver.storage.googleapis.com/${chromeDriver}/notes.txt -O
echo "Done."

Maybe this helps.

benjamin-vauchel-webrivage commented 3 years ago

@robertfausk It seems Chrome latest stable version is not compatible anymore with Trusty release (https://travis-ci.community/t/you-can-no-longer-install-chrome-stable-on-trusty-machines/8521). I got an error "dpkg: error processing archive /tmp/google-chrome-stable_current_amd64.deb (--install):".

I'll try with Xenial and Bionic releases ...

J-Ben87 commented 3 years ago

Hi, thanks for the PR. I was struggling on the same issue, and ended up with a similar solution.

@sanpii could you please accept and merge the PR? This is quite a simple fix for quite a blocking issue. Or maybe give us an advise on how to fix the tests?

Thanks :slightly_smiling_face:

J-Ben87 commented 3 years ago

Hi @sanpii , did you consider merging this PR yet?

J-Ben87 commented 3 years ago

Up @sanpii ? That's a shame that we can't use this great bundle for such a little issue :slightly_frowning_face: