summaryrefslogtreecommitdiffstats
path: root/tests/acceptance/features
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-05-04 00:02:18 -0300
committerGitHub <noreply@github.com>2017-05-04 00:02:18 -0300
commit61379c9165bee668612a407ea153ab382e5039b2 (patch)
treef9a091cbbf4cdae423f0273c0f104730d2bfdc84 /tests/acceptance/features
parent806aeae71d970f70efaeb35db79d92f953279e49 (diff)
parent1a83c4c5c3601a69eff0fab1a3d6eca6683bdcb9 (diff)
downloadnextcloud-server-61379c9165bee668612a407ea153ab382e5039b2.tar.gz
nextcloud-server-61379c9165bee668612a407ea153ab382e5039b2.zip
Merge pull request #4682 from nextcloud/try-to-start-browser-sessions-again-when-they-fail-in-acceptance-tests
Try to start browser sessions again when they fail in acceptance tests
Diffstat (limited to 'tests/acceptance/features')
-rw-r--r--tests/acceptance/features/core/Actor.php14
-rw-r--r--tests/acceptance/features/core/ActorContext.php44
2 files changed, 48 insertions, 10 deletions
diff --git a/tests/acceptance/features/core/Actor.php b/tests/acceptance/features/core/Actor.php
index 0c23b5f7a40..3a57b7e6054 100644
--- a/tests/acceptance/features/core/Actor.php
+++ b/tests/acceptance/features/core/Actor.php
@@ -165,6 +165,18 @@ class Actor {
public function find($elementLocator, $timeout = 0, $timeoutStep = 0.5) {
$timeout = $timeout * $this->findTimeoutMultiplier;
+ return $this->findInternal($elementLocator, $timeout, $timeoutStep);
+ }
+
+ /**
+ * Finds an element in the Mink Session of this Actor.
+ *
+ * The timeout is not affected by the multiplier set using
+ * setFindTimeoutMultiplier().
+ *
+ * @see find($elementLocator, $timeout, $timeoutStep)
+ */
+ private function findInternal($elementLocator, $timeout, $timeoutStep) {
$element = null;
$selector = $elementLocator->getSelector();
$locator = $elementLocator->getLocator();
@@ -211,7 +223,7 @@ class Actor {
$ancestorElement = $elementLocator->getAncestor();
if ($ancestorElement instanceof Locator) {
try {
- $ancestorElement = $this->find($ancestorElement, $timeout, $timeoutStep);
+ $ancestorElement = $this->findInternal($ancestorElement, $timeout, $timeoutStep);
} catch (NoSuchElementException $exception) {
// Little hack to show the stack of ancestor elements that could
// not be found, as Behat only shows the message of the last
diff --git a/tests/acceptance/features/core/ActorContext.php b/tests/acceptance/features/core/ActorContext.php
index 86fe3832f66..d6fb63694ec 100644
--- a/tests/acceptance/features/core/ActorContext.php
+++ b/tests/acceptance/features/core/ActorContext.php
@@ -39,8 +39,9 @@ use Behat\MinkExtension\Context\RawMinkContext;
* 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".
+ * it can be customized using the "actorTimeoutMultiplier" parameter of the
+ * 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
@@ -66,16 +67,16 @@ class ActorContext extends RawMinkContext {
/**
* @var float
*/
- private $actorFindTimeoutMultiplier;
+ private $actorTimeoutMultiplier;
/**
* Creates a new ActorContext.
*
- * @param float $actorFindTimeoutMultiplier the find timeout multiplier to
- * set in the Actors.
+ * @param float $actorTimeoutMultiplier the timeout multiplier for Actor
+ * related timeouts.
*/
- public function __construct($actorFindTimeoutMultiplier = 1) {
- $this->actorFindTimeoutMultiplier = $actorFindTimeoutMultiplier;
+ public function __construct($actorTimeoutMultiplier = 1) {
+ $this->actorTimeoutMultiplier = $actorTimeoutMultiplier;
}
/**
@@ -98,6 +99,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
*
* Initializes the Actors for the new Scenario with the default Actor.
@@ -110,7 +136,7 @@ class ActorContext extends RawMinkContext {
$this->sharedNotebook = array();
$this->actors["default"] = new Actor($this->getSession(), $this->getMinkParameter("base_url"), $this->sharedNotebook);
- $this->actors["default"]->setFindTimeoutMultiplier($this->actorFindTimeoutMultiplier);
+ $this->actors["default"]->setFindTimeoutMultiplier($this->actorTimeoutMultiplier);
$this->currentActor = $this->actors["default"];
}
@@ -134,7 +160,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->sharedNotebook);
- $this->actors[$actorName]->setFindTimeoutMultiplier($this->actorFindTimeoutMultiplier);
+ $this->actors[$actorName]->setFindTimeoutMultiplier($this->actorTimeoutMultiplier);
}
$this->currentActor = $this->actors[$actorName];