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

[stable10] webUI search tests #32776

Merged
merged 1 commit into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ default:
- WebUILoginContext:
- WebUIUsersContext:
- WebUIFilesContext:
- WebUISearchContext:

webUIMoveFilesFolders:
paths:
Expand Down
37 changes: 31 additions & 6 deletions tests/acceptance/features/bootstrap/WebUIFilesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException;
use TestHelpers\DeleteHelper;
use TestHelpers\DownloadHelper;
use Page\FilesPageBasic;

require_once 'bootstrap.php';

Expand Down Expand Up @@ -1108,12 +1109,13 @@ public function theFileFolderShouldBeListedOnTheWebUI(
* @param string $shouldOrNot
* @param string $typeOfFilesPage
* @param string $folder
* @param string $path if set, name and path (shown in the webUI) of the file need match
*
* @return void
* @throws \Exception
*/
public function checkIfFileFolderIsListedOnTheWebUI(
$name, $shouldOrNot, $typeOfFilesPage = "", $folder = ""
$name, $shouldOrNot, $typeOfFilesPage = "", $folder = "", $path = ""
) {
$should = ($shouldOrNot !== "not");
$exceptionMessage = null;
Expand All @@ -1130,7 +1132,14 @@ public function checkIfFileFolderIsListedOnTheWebUI(
case "shared-with-you page":
$this->theUserBrowsesToTheSharedWithYouPage();
break;
case "search results page":
//nothing to do here, we cannot navigate to that page, except by performing a search
break;
}
/**
*
* @var FilesPageBasic $pageObject
*/
$pageObject = $this->getCurrentPageObject();
$pageObject->waitTillPageIsLoaded($this->getSession());
if ($folder !== "") {
Expand All @@ -1140,11 +1149,23 @@ public function checkIfFileFolderIsListedOnTheWebUI(
}

try {
/**
*
* @var FileRow $fileRow
*/
$fileRow = $pageObject->findFileRowByName($name, $this->getSession());
if ($path === "") {
/**
*
* @var FileRow $fileRow
*/
$fileRow = $pageObject->findFileRowByName(
$name, $this->getSession()
);
} else {
/**
*
* @var FileRow $fileRow
*/
$fileRow = $pageObject->findFileRowByNameAndPath(
$name, $path, $this->getSession()
);
}
$exceptionMessage = '';
} catch (ElementNotFoundException $e) {
$exceptionMessage = $e->getMessage();
Expand All @@ -1159,6 +1180,10 @@ public function checkIfFileFolderIsListedOnTheWebUI(

$fileLocationText = " file '$nameText'";

if ($path !== "") {
$fileLocationText .= " with path '$path'";
}

if ($folder !== "") {
$fileLocationText .= " in folder '$folder'";
} else {
Expand Down
128 changes: 128 additions & 0 deletions tests/acceptance/features/bootstrap/WebUISearchContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
/**
* ownCloud
*
* @author Artur Neumann <artur@jankaritech.com>
* @copyright Copyright (c) 2018 Artur Neumann artur@jankaritech.com
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License,
* as published by the Free Software Foundation;
* either version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\MinkExtension\Context\RawMinkContext;
use Page\SearchResultInOtherFoldersPage;
use Page\OwncloudPage;

require_once 'bootstrap.php';

/**
* WebUI Search context.
*/
class WebUISearchContext extends RawMinkContext implements Context {
/**
*
* @var SearchResultInOtherFoldersPage
*/
private $searchResultInOtherFoldersPage;
/**
*
* @var OwncloudPage
*/
private $ownCloudPage;

/**
*
* @var WebUIGeneralContext
*/
private $webUIGeneralContext;

/**
*
* @var WebUIFilesContext
*/
private $webUIFilesContext;

/**
* WebUILoginContext constructor.
*
* @param SearchResultInOtherFoldersPage $searchResultInOtherFoldersPage
*/
public function __construct(
OwncloudPage $ownCloudPage,
SearchResultInOtherFoldersPage $searchResultInOtherFoldersPage
) {
$this->ownCloudPage = $ownCloudPage;
$this->searchResultInOtherFoldersPage = $searchResultInOtherFoldersPage;
}

/**
* @When the user searches for :searchTerm using the webUI
*
* @param string $searchTerm
*
* @return void
* @throws \Exception
*/
public function theUserSearchesUsingTheWebUI($searchTerm) {
$this->ownCloudPage->waitTillPageIsLoaded($this->getSession());
$this->ownCloudPage->search($this->getSession(), $searchTerm);
}

/**
* @Then /^the (?:file|folder) ((?:'[^']*')|(?:"[^"]*")) with the path ((?:'[^']*')|(?:"[^"]*")) should (not|)\s?be listed in the search results in other folders section on the webUI$/
* @param string $fileName
* @param string $path
*/
public function fileShouldBeListedSearchResultOtherFolders($fileName, $path, $shouldOrNot) {
$fileName = \trim($fileName, $fileName[0]);
$path = \trim($path, $path[0]);
$this->webUIGeneralContext->setCurrentPageObject($this->searchResultInOtherFoldersPage);
$this->webUIFilesContext->checkIfFileFolderIsListedOnTheWebUI(
$fileName, $shouldOrNot, "search results page", "", $path
);
}

/**
* @Then /^the (?:file|folder) ((?:'[^']*')|(?:"[^"]*")) should (not|)\s?be listed in the search results in other folders section on the webUI$/
*
* @param string $fileName
*/
public function fileShouldNotBeListedSearchResultOtherFolders($fileName, $shouldOrNot) {
$fileName = \trim($fileName, $fileName[0]);
$this->webUIGeneralContext->setCurrentPageObject($this->searchResultInOtherFoldersPage);
$this->webUIFilesContext->checkIfFileFolderIsListedOnTheWebUI(
$fileName, $shouldOrNot, "search results page"
);
}

/**
* This will run before EVERY scenario.
* It will set the properties for this object.
*
* @BeforeScenario @webUI
*
* @param BeforeScenarioScope $scope
*
* @return void
*/
public function before(BeforeScenarioScope $scope) {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$this->webUIGeneralContext = $environment->getContext('WebUIGeneralContext');
$this->webUIFilesContext = $environment->getContext('WebUIFilesContext');
}
}
9 changes: 9 additions & 0 deletions tests/acceptance/features/lib/FavoritesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,13 @@ protected function getFileNameMatchXpath() {
protected function getEmptyContentXpath() {
return $this->emptyContentXpath;
}

/**
*
* {@inheritDoc}
* @see \Page\FilesPageBasic::getFilePathInRowXpath()
*/
protected function getFilePathInRowXpath() {
throw new \Exception("not implemented in FavoritesPage");
}
}
9 changes: 9 additions & 0 deletions tests/acceptance/features/lib/FilesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ protected function getFileNameMatchXpath() {
protected function getEmptyContentXpath() {
return $this->emptyContentXpath;
}

/**
*
* {@inheritDoc}
* @see \Page\FilesPageBasic::getFilePathInRowXpath()
*/
protected function getFilePathInRowXpath() {
throw new \Exception("not implemented in FilesPage");
}

/**
* create a folder with the given name.
Expand Down
29 changes: 29 additions & 0 deletions tests/acceptance/features/lib/FilesPageBasic.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ abstract protected function getFileNameMatchXpath();
*/
abstract protected function getEmptyContentXpath();

/**
* @return string
*/
abstract protected function getFilePathInRowXpath();

/**
* @return int the number of files and folders listed on the page
*/
Expand Down Expand Up @@ -109,6 +114,30 @@ public function findFileRowByName($name, Session $session) {
return $this->findAllFileRowsByName($name, $session)[0];
}

/**
* finds the complete row of a file with a given name and path
* useful for pages where multiple files with the same name can be displayed
*
* @param string|array $name
* @param Session $session
*
* @return FileRow
* @throws ElementNotFoundException
*/
public function findFileRowByNameAndPath($name, $path, Session $session) {
$fileRows = $this->findAllFileRowsByName($name, $session);
foreach ($fileRows as $fileRow) {
$filePath = $fileRow->getFilePath($this->getFilePathInRowXpath());
if ($filePath === $path) {
return $fileRow;
}
}
throw new ElementNotFoundException(
__METHOD__ .
" could not find file with the name '$name' and path '$path'"
);
}

/**
* finds all rows that have the given name
*
Expand Down
18 changes: 18 additions & 0 deletions tests/acceptance/features/lib/FilesPageElement/FileRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,24 @@ public function getTooltip() {
return $this->getTrimmedText($this->findTooltipElement());
}

/**
* return the path of the current file
*
* @param string $xpath xpath related to the fileRow element
* @throws ElementNotFoundException
* @return string
*/
public function getFilePath($xpath) {
$filePathElement = $this->rowElement->find("xpath", $xpath);
if ($filePathElement === null) {
throw new ElementNotFoundException(
__METHOD__ .
" xpath $xpath could not find file path element"
);
}
return \dirname($filePathElement->getText());
}

/**
* finds and returns the thumbnail of the file
*
Expand Down
26 changes: 26 additions & 0 deletions tests/acceptance/features/lib/OwncloudPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class OwncloudPage extends Page {
protected $ocDialogXpath = ".//*[@class='oc-dialog']";
protected $avatarImgXpath = ".//div[@id='settings']//div[contains(@class, 'avatardiv')]/img";
protected $titleXpath = ".//title";
protected $searchBoxId = "searchbox";

/**
* used to store the unchanged path string when $path gets changed
Expand Down Expand Up @@ -303,6 +304,31 @@ public function isAvatarVisible() {
return $avatarElement->isVisible();
}

/**
*
* @param Session $session
* @param string $searchTerm
* @throws ElementNotFoundException
*/
public function search($session, $searchTerm) {
$searchbox = $this->findById($this->searchBoxId);
if ($searchbox === null) {
throw new ElementNotFoundException(
__METHOD__ .
" id: '$this->searchBoxId' " .
"could not find searchbox / button"
);
}
$searchbox->click();
$searchbox->setValue($searchTerm);
$this->waitForAjaxCallsToStartAndFinish($session);
/**
*
* @var SearchResultInOtherFoldersPage $searchResultInOtherFoldersPage
*/
$searchResultInOtherFoldersPage = $this->getPage("SearchResultInOtherFoldersPage");
$searchResultInOtherFoldersPage->waitTillPageIsLoaded($session);
}
/**
* return the path to the relevant page
*
Expand Down
9 changes: 9 additions & 0 deletions tests/acceptance/features/lib/PublicLinkFilesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ protected function getEmptyContentXpath() {
return $this->emptyContentXpath;
}

/**
*
* {@inheritDoc}
* @see \Page\FilesPageBasic::getFilePathInRowXpath()
*/
protected function getFilePathInRowXpath() {
throw new \Exception("not implemented in PublicLinkFilesPage");
}

/**
* adding public link share to particular server
*
Expand Down
Loading