MDL-67317 behat: Ensure that on every scenario we have a session.
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Thu, 9 Apr 2020 12:02:40 +0000 (14:02 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Thu, 16 Apr 2020 18:28:49 +0000 (20:28 +0200)
Before Mink 1.8.0, any call to getSession() used to auto-start
the session if it was not avaliable there. That always has been
an unsupported detail.

With https://github.com/minkphp/Mink/pull/705 new sessions aren't
auto-created anymore.

And we were relying on that.

So this is, simply about to explicitly create the new session
in our before_scenario stuff, to guarantee that it's always there.

lib/tests/behat/behat_hooks.php

index 0695b14..c7b53df 100644 (file)
@@ -307,6 +307,9 @@ class behat_hooks extends behat_base {
         $driverexceptionmsg = 'Selenium server is not running, you need to start it to run tests that involve Javascript. ' . $moreinfo;
         try {
             $session = $this->getSession();
+            if (!$session->isStarted()) {
+                $session->start();
+            }
         } catch (CurlExec $e) {
             // Exception thrown by WebDriver, so only @javascript tests will be caugth; in
             // behat_util::check_server_status() we already checked that the server is running.