Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for the shared link to be set in the acceptance tests #7605

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions tests/acceptance/features/bootstrap/FilesAppContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,16 @@ public function iShareTheLinkFor($fileName) {
* @Given I write down the shared link
*/
public function iWriteDownTheSharedLink() {
$this->actor->getSharedNotebook()["shared link"] = $this->actor->find(self::shareLinkField(), 10)->getValue();
// The shared link field always exists in the DOM (once the "Sharing"
// tab is loaded), but its value is the actual shared link only when it
// is visible.
if (!$this->waitForElementToBeEventuallyShown(
self::shareLinkField(),
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
PHPUnit_Framework_Assert::fail("The shared link was not shown yet after $timeout seconds");
}

$this->actor->getSharedNotebook()["shared link"] = $this->actor->find(self::shareLinkField())->getValue();
}

/**
Expand Down Expand Up @@ -606,7 +615,9 @@ public function iSeeThatTheTagInTheDropdownForTagsInTheDetailsViewIsNotChecked($
* @When I see that the :tabName tab in the details view is eventually loaded
*/
public function iSeeThatTheTabInTheDetailsViewIsEventuallyLoaded($tabName) {
if (!$this->waitForElementToBeEventuallyNotShown(self::loadingIconForTabInCurrentSectionDetailsViewNamed($tabName), $timeout = 10)) {
if (!$this->waitForElementToBeEventuallyNotShown(
self::loadingIconForTabInCurrentSectionDetailsViewNamed($tabName),
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
PHPUnit_Framework_Assert::fail("The $tabName tab in the details view has not been loaded after $timeout seconds");
}
}
Expand All @@ -622,7 +633,9 @@ public function iSeeThatTheWorkingIconForPasswordProtectIsShown() {
* @Then I see that the working icon for password protect is eventually not shown
*/
public function iSeeThatTheWorkingIconForPasswordProtectIsEventuallyNotShown() {
if (!$this->waitForElementToBeEventuallyNotShown(self::passwordProtectWorkingIcon(), $timeout = 10)) {
if (!$this->waitForElementToBeEventuallyNotShown(
self::passwordProtectWorkingIcon(),
$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
PHPUnit_Framework_Assert::fail("The working icon for password protect is still shown after $timeout seconds");
}
}
Expand All @@ -637,17 +650,31 @@ public function iShareTheLinkForProtectedByThePassword($fileName, $password) {
$this->iSeeThatTheWorkingIconForPasswordProtectIsEventuallyNotShown();
}

private function waitForElementToBeEventuallyShown($elementLocator, $timeout = 10, $timeoutStep = 1) {
$actor = $this->actor;

$elementShownCallback = function() use ($actor, $elementLocator) {
try {
return $actor->find($elementLocator)->isVisible();
} catch (NoSuchElementException $exception) {
return false;
}
};

return Utils::waitFor($elementShownCallback, $timeout, $timeoutStep);
}

private function waitForElementToBeEventuallyNotShown($elementLocator, $timeout = 10, $timeoutStep = 1) {
$actor = $this->actor;

$elementNotFoundCallback = function() use ($actor, $elementLocator) {
$elementNotShownCallback = function() use ($actor, $elementLocator) {
try {
return !$actor->find($elementLocator)->isVisible();
} catch (NoSuchElementException $exception) {
return true;
}
};

return Utils::waitFor($elementNotFoundCallback, $timeout, $timeoutStep);
return Utils::waitFor($elementNotShownCallback, $timeout, $timeoutStep);
}
}