Add system to share data between acceptance test steps

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 <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2017-04-23 18:40:58 +02:00
parent 8a1d3c7e87
commit 13c84f6629
2 changed files with 29 additions and 3 deletions

View file

@ -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;
}
}

View file

@ -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);
}