From b10478ff19be0e4c38f8ff6b0c31f1a40eda0043 Mon Sep 17 00:00:00 2001 From: Daniel Calviño Sánchez Date: Wed, 3 May 2017 12:53:02 +0200 Subject: Try again to start browser sessions when they fail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Starting a session for an Actor can fail, typically, due to a timeout connecting with the web browser. Now if the session fails to start it will be tried again up to "actorTimeoutMultiplier" times in total before giving up. Signed-off-by: Daniel Calviño Sánchez --- tests/acceptance/features/core/ActorContext.php | 28 ++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'tests/acceptance/features/core') diff --git a/tests/acceptance/features/core/ActorContext.php b/tests/acceptance/features/core/ActorContext.php index c62ebb5e74f..d6fb63694ec 100644 --- a/tests/acceptance/features/core/ActorContext.php +++ b/tests/acceptance/features/core/ActorContext.php @@ -40,7 +40,8 @@ use Behat\MinkExtension\Context\RawMinkContext; * * By default no multiplier for the find timeout is set in the Actors. However, * it can be customized using the "actorTimeoutMultiplier" parameter of the - * ActorContext in "behat.yml". + * ActorContext in "behat.yml". This parameter also affects the overall timeout + * to start a session for an Actor before giving up. * * Every actor used in the scenarios must have a corresponding Mink session * declared in "behat.yml" with the same name as the actor. All used sessions @@ -97,6 +98,31 @@ class ActorContext extends RawMinkContext { } } + /** + * Returns the session with the given name. + * + * If the session is not started it is started before returning it; if the + * session fails to start (typically due to a timeout connecting with the + * web browser) it will be tried again up to $actorTimeoutMultiplier times + * in total (rounded up to the next integer) before giving up. + * + * @param string|null $sname the name of the session to get, or null for the + * default session. + * @return \Behat\Mink\Session the session. + */ + public function getSession($name = null) { + for ($i = 0; $i < ($this->actorTimeoutMultiplier - 1); $i++) { + try { + return parent::getSession($name); + } catch (\Behat\Mink\Exception\DriverException $exception) { + echo "Exception when getting " . ($name == null? "default session": "session '$name'") . ": " . $exception->getMessage() . "\n"; + echo "Trying again\n"; + } + } + + return parent::getSession($name); + } + /** * @BeforeScenario * -- cgit v1.2.3