From 13c84f66294034fe17f806d3db6ddc770c8158e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Sun, 23 Apr 2017 18:40:58 +0200 Subject: [PATCH] Add system to share data between acceptance test steps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The data storage (the "notebook") is shared between all the actors, so the data can be stored and retrieved between different steps by any actor in the same scenario. Signed-off-by: Daniel Calviño Sánchez --- tests/acceptance/features/core/Actor.php | 22 ++++++++++++++++++- .../acceptance/features/core/ActorContext.php | 10 +++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/tests/acceptance/features/core/Actor.php b/tests/acceptance/features/core/Actor.php index a27e8e6a01..0c23b5f7a4 100644 --- a/tests/acceptance/features/core/Actor.php +++ b/tests/acceptance/features/core/Actor.php @@ -48,6 +48,10 @@ * before giving up without modifying the tests themselves. Note that the * multiplier affects the timeout, but not the timeout step; the rate at which * find() will try again to find the element does not change. + * + * All actors share a notebook in which data can be annotated. This makes + * possible to share data between different test steps, no matter which Actor + * performs them. */ class Actor { @@ -66,16 +70,23 @@ class Actor { */ private $findTimeoutMultiplier; + /** + * @var array + */ + private $sharedNotebook; + /** * Creates a new Actor. * * @param \Behat\Mink\Session $session the Mink Session used to control its * web browser. * @param string $baseUrl the base URL used when solving relative URLs. + * @param array $sharedNotebook the notebook shared between all actors. */ - public function __construct(\Behat\Mink\Session $session, $baseUrl) { + public function __construct(\Behat\Mink\Session $session, $baseUrl, &$sharedNotebook) { $this->session = $session; $this->baseUrl = $baseUrl; + $this->sharedNotebook = &$sharedNotebook; $this->findTimeoutMultiplier = 1; } @@ -221,4 +232,13 @@ class Actor { return $ancestorElement; } + /** + * Returns the shared notebook of the Actors. + * + * @return array the shared notebook of the Actors. + */ + public function &getSharedNotebook() { + return $this->sharedNotebook; + } + } diff --git a/tests/acceptance/features/core/ActorContext.php b/tests/acceptance/features/core/ActorContext.php index 9667ef2f01..86fe3832f6 100644 --- a/tests/acceptance/features/core/ActorContext.php +++ b/tests/acceptance/features/core/ActorContext.php @@ -53,6 +53,11 @@ class ActorContext extends RawMinkContext { */ private $actors; + /** + * @var array + */ + private $sharedNotebook; + /** * @var Actor */ @@ -102,8 +107,9 @@ class ActorContext extends RawMinkContext { */ public function initializeActors() { $this->actors = array(); + $this->sharedNotebook = array(); - $this->actors["default"] = new Actor($this->getSession(), $this->getMinkParameter("base_url")); + $this->actors["default"] = new Actor($this->getSession(), $this->getMinkParameter("base_url"), $this->sharedNotebook); $this->actors["default"]->setFindTimeoutMultiplier($this->actorFindTimeoutMultiplier); $this->currentActor = $this->actors["default"]; @@ -127,7 +133,7 @@ class ActorContext extends RawMinkContext { */ public function iActAs($actorName) { if (!array_key_exists($actorName, $this->actors)) { - $this->actors[$actorName] = new Actor($this->getSession($actorName), $this->getMinkParameter("base_url")); + $this->actors[$actorName] = new Actor($this->getSession($actorName), $this->getMinkParameter("base_url"), $this->sharedNotebook); $this->actors[$actorName]->setFindTimeoutMultiplier($this->actorFindTimeoutMultiplier); }