diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2017-04-15 18:56:24 +0200 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2017-04-19 08:26:04 +0200 |
commit | be96be09b599235c6b712d39f88760f10020508b (patch) | |
tree | f59cef699ea5e607f88adb23669eb5238758bacc | |
parent | a7e1833cf3f110845da92180f0e8fbb9fbf430ce (diff) | |
download | nextcloud-server-be96be09b599235c6b712d39f88760f10020508b.tar.gz nextcloud-server-be96be09b599235c6b712d39f88760f10020508b.zip |
Add general multiplier for find timeouts
Although the timeouts specified in the acceptance tests are enough in
most cases they may not be when running them in a slow system or
environment. For those situations a general multiplier for find
timeouts is added. It can be set in the "behat.yml" configuration file
to increase the timeout used in every find call (except those that used
a timeout of 0, as in those cases the element had to be already present
when finding it and whether the system is slow or not does not change
that).
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
-rw-r--r-- | build/acceptance/features/core/Actor.php | 28 | ||||
-rw-r--r-- | build/acceptance/features/core/ActorContext.php | 21 |
2 files changed, 48 insertions, 1 deletions
diff --git a/build/acceptance/features/core/Actor.php b/build/acceptance/features/core/Actor.php index ac08822fffe..a27e8e6a015 100644 --- a/build/acceptance/features/core/Actor.php +++ b/build/acceptance/features/core/Actor.php @@ -41,6 +41,13 @@ * several features: the element can be looked for based on a Locator object, an * exception is thrown if the element is not found, and, optionally, it is * possible to try again to find the element several times before giving up. + * + * The amount of time to wait before giving up is specified in each call to + * find(). However, a general multiplier to be applied to every timeout can be + * set using setFindTimeoutMultiplier(); this makes possible to retry longer + * 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. */ class Actor { @@ -55,6 +62,11 @@ class Actor { private $baseUrl; /** + * @var float + */ + private $findTimeoutMultiplier; + + /** * Creates a new Actor. * * @param \Behat\Mink\Session $session the Mink Session used to control its @@ -64,6 +76,7 @@ class Actor { public function __construct(\Behat\Mink\Session $session, $baseUrl) { $this->session = $session; $this->baseUrl = $baseUrl; + $this->findTimeoutMultiplier = 1; } /** @@ -76,6 +89,16 @@ class Actor { } /** + * Sets the multiplier for find timeouts. + * + * @param float $findTimeoutMultiplier the multiplier to apply to find + * timeouts. + */ + public function setFindTimeoutMultiplier($findTimeoutMultiplier) { + $this->findTimeoutMultiplier = $findTimeoutMultiplier; + } + + /** * Returns the Mink Session used to control its web browser. * * @return \Behat\Mink\Session the Mink Session used to control its web @@ -113,7 +136,8 @@ class Actor { * and, then, up to 10 seconds to find the ancestor and, then, up to 10 * seconds to find the element. By default the timeout is 0, so the element * and its ancestor will be looked for just once; the default time to wait - * before retrying is half a second. + * before retrying is half a second. If the timeout is not 0 it will be + * affected by the multiplier set using setFindTimeoutMultiplier(), if any. * * In any case, if the element, or its ancestors, can not be found a * NoSuchElementException is thrown. @@ -128,6 +152,8 @@ class Actor { * be found. */ public function find($elementLocator, $timeout = 0, $timeoutStep = 0.5) { + $timeout = $timeout * $this->findTimeoutMultiplier; + $element = null; $selector = $elementLocator->getSelector(); $locator = $elementLocator->getLocator(); diff --git a/build/acceptance/features/core/ActorContext.php b/build/acceptance/features/core/ActorContext.php index e655911af67..9667ef2f01c 100644 --- a/build/acceptance/features/core/ActorContext.php +++ b/build/acceptance/features/core/ActorContext.php @@ -38,6 +38,10 @@ use Behat\MinkExtension\Context\RawMinkContext; * Besides updating the current actor in sibling contexts the ActorContext also * propagates its inherited "base_url" Mink parameter to the Actors as needed. * + * By default no multiplier for the find timeout is set in the Actors. However, + * it can be customized using the "actorFindTimeoutMultiplier" parameter of the + * ActorContext in "behat.yml". + * * 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 * are stopped after each scenario is run. @@ -55,6 +59,21 @@ class ActorContext extends RawMinkContext { private $currentActor; /** + * @var float + */ + private $actorFindTimeoutMultiplier; + + /** + * Creates a new ActorContext. + * + * @param float $actorFindTimeoutMultiplier the find timeout multiplier to + * set in the Actors. + */ + public function __construct($actorFindTimeoutMultiplier = 1) { + $this->actorFindTimeoutMultiplier = $actorFindTimeoutMultiplier; + } + + /** * Sets a Mink parameter. * * When the "base_url" parameter is set its value is propagated to all the @@ -85,6 +104,7 @@ class ActorContext extends RawMinkContext { $this->actors = array(); $this->actors["default"] = new Actor($this->getSession(), $this->getMinkParameter("base_url")); + $this->actors["default"]->setFindTimeoutMultiplier($this->actorFindTimeoutMultiplier); $this->currentActor = $this->actors["default"]; } @@ -108,6 +128,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]->setFindTimeoutMultiplier($this->actorFindTimeoutMultiplier); } $this->currentActor = $this->actors[$actorName]; |