Skip to content
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"mikey179/vfsStream": "^1.6",
"behat/mink-extension": "^2.2",
"behat/mink-goutte-driver": "^1.2",
"behat/mink-selenium2-driver": "^1.3",
"behat/mink-selenium2-driver": "dev-master",
"sensiolabs/behat-page-object-extension": "^2.0",
"behat/behat": "^3.0",
"jarnaiz/behat-junit-formatter": "^1.3"
Expand Down
17 changes: 9 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion tests/travis/start_behat_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ then
else
BASE_URL="http://$SRV_HOST_NAME:$SRV_HOST_PORT/$SRV_HOST_URL"
fi

if [ "$BROWSER" == "firefox" ]
then
EXTRA_CAPABILITIES='"seleniumVersion":"2.53.1",'
fi

EXTRA_CAPABILITIES=$EXTRA_CAPABILITIES'"maxDuration":"3600"'

echo "Running tests on '$BROWSER' ($BROWSER_VERSION) on $PLATFORM"
export BEHAT_PARAMS='{"extensions" : {"Behat\\MinkExtension" : {"browser_name": "'$BROWSER'", "base_url" : "'$BASE_URL'","selenium2":{"capabilities": {"browser": "'$BROWSER'", "version": "'$BROWSER_VERSION'", "platform": "'$PLATFORM'", "name": "'$TRAVIS_REPO_SLUG' - '$TRAVIS_JOB_NUMBER'"}, "wd_host":"http://'$SAUCE_USERNAME:$SAUCE_ACCESS_KEY'@localhost:4445/wd/hub"}}}}'
export BEHAT_PARAMS='{"extensions" : {"Behat\\MinkExtension" : {"browser_name": "'$BROWSER'", "base_url" : "'$BASE_URL'","selenium2":{"capabilities": {"browser": "'$BROWSER'", "version": "'$BROWSER_VERSION'", "platform": "'$PLATFORM'", "name": "'$TRAVIS_REPO_SLUG' - '$TRAVIS_JOB_NUMBER'", "extra_capabilities": {'$EXTRA_CAPABILITIES'}}, "wd_host":"http://'$SAUCE_USERNAME:$SAUCE_ACCESS_KEY'@localhost:4445/wd/hub"}}}}'

if [ "$BROWSER" == "internet explorer" ]
then
Expand Down
23 changes: 23 additions & 0 deletions tests/ui/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\MinkExtension\Context\RawMinkContext;
use Behat\Gherkin\Node\TableNode;
use Page\OwncloudPage;
use Page\LoginPage;

Expand Down Expand Up @@ -54,6 +55,28 @@ public function aNotificationShouldBeDisplayedWithTheText($notificationText)
);
}

/**
* @Then notifications should be displayed with the text
*/
public function notificationsShouldBeDisplayedWithTheText(TableNode $table)
{
$notifications = $this->owncloudPage->getNotifications();
$tableRows=$table->getRows();
PHPUnit_Framework_Assert::assertEquals(
count($tableRows),
count($notifications)
);

$notificationCounter=0;
foreach ($tableRows as $row) {
PHPUnit_Framework_Assert::assertEquals(
$row[0],
$notifications[$notificationCounter]
);
$notificationCounter++;
}
}

/**
* @Then I should be redirected to a page with the title :title
*/
Expand Down
43 changes: 42 additions & 1 deletion tests/ui/features/bootstrap/FilesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

use Behat\Behat\Context\Context;
use Behat\MinkExtension\Context\RawMinkContext;

use Behat\Gherkin\Node\TableNode;
use Page\FilesPage;

require_once 'bootstrap.php';
Expand Down Expand Up @@ -76,6 +76,47 @@ public function theListOfFilesFoldersDoesNotFitInOneBrowserPage()
$this->filesPage->waitTillPageIsloaded(10);
}

/**
* @Given I rename the file/folder :fromName to :toName
*/
public function iRenameTheFileFolderTo($fromName, $toName)
{
$this->filesPage->waitTillPageIsloaded(10);
$this->filesPage->renameFile($fromName, $toName, $this->getSession());
}

/**
* @When I rename the file/folder :fromName to one of these names
*/
public function iRenameTheFileToOneOfThisNames($fromName, TableNode $table)
{
$this->filesPage->waitTillPageIsloaded(10);
foreach ($table->getRows() as $row) {
$this->filesPage->renameFile($fromName, $row[0], $this->getSession());
}

}

/**
* @Then the file/folder :name should be listed
*/
public function theFileFolderShouldBeListed($name)
{
PHPUnit_Framework_Assert::assertNotNull(
$this->filesPage->findFileRowByName($name, $this->getSession())
);
}

/**
* @Then near the file/folder :name a tooltip with the text :toolTipText should be displayed
*/
public function nearTheFileATooltipWithTheTextShouldBeDisplayed($name, $toolTipText)
{
PHPUnit_Framework_Assert::assertEquals($toolTipText,
$this->filesPage->getTooltipOfFile($name, $this->getSession())
);
}

/**
* @Then the filesactionmenu should be completely visible after clicking on it
*/
Expand Down
157 changes: 150 additions & 7 deletions tests/ui/features/lib/FilesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use SensioLabs\Behat\PageObjectExtension\PageObject\Page;
use SensioLabs\Behat\PageObjectExtension\PageObject\Exception\UnexpectedPageException;
use Behat\Mink\Session;


class FilesPage extends OwnCloudPage
Expand All @@ -39,17 +40,23 @@ class FilesPage extends OwnCloudPage
protected $newFileFolderButtonXpath = './/*[@id="controls"]//a[@class="button new"]';
protected $newFolderButtonXpath = './/div[contains(@class, "newFileMenu")]//a[@data-templatename="New folder"]';
protected $newFolderNameInputLabel = 'New folder';
protected $fileActionMenuXpathByNo = ".//*[@id='fileList']/tr[%d]//a[@data-action='menu']";
protected $fileActionMenuBtnXpathByNo = ".//*[@id='fileList']/tr[%d]//a[@data-action='menu']";
protected $fileActionMenuBtnXpath = "//a[@data-action='menu']";
protected $fileActionMenuXpath = "//div[contains(@class,'fileActionsMenu')]";
protected $fileNamesXpath = "//span[@class='nametext']";
protected $fileRowFromNameXpath = "/../../..";
protected $fileActionXpath = "//a[@data-action='%s']";
protected $fileRenameInputXpath = "//input[contains(@class,'filename')]";
protected $fileBusyIndicatorXpath = ".//*[@class='thumbnail' and contains(@style,'loading')]";
protected $appContentId ="app-content";
protected $renameActionLabel = "Rename";
protected $fileTooltipXpath = ".//*[@class='tooltip-inner']";
//TODO make simpler, only ID .//*[@id='fileList']
protected $fileListXpath = ".//div[@id='app-content-files']//tbody[@id='fileList']";
protected $fileDeleteXpathByNo = ".//*[@id='fileList']/tr[%d]//a[@data-action='Delete']";

private $strForNormalFileName = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';

public function findFileInList($filename)
{
return $this->findLink($filename);
}

/**
* created a folder with the given name.
* If name is not given a random one is choosen
Expand All @@ -74,10 +81,134 @@ public function getSizeOfFileFolderList()
);
}
public function findActionMenuByNo($number) {
$xpath = sprintf($this->fileActionMenuXpathByNo,$number);
$xpath = sprintf($this->fileActionMenuBtnXpathByNo,$number);
return $this->find("xpath", $xpath);
}

/**
* finds the complete row of the file
*
* @param string $name
* @param Session $session
* @return \Behat\Mink\Element\NodeElement|NULL
*/
public function findFileRowByName($name, Session $session)
{
$lastFileNameCoordinates ["top"] = 0;
$appContentHeight = 0;
$previousFileCounter = 0;
$fileNameSpans = array();

$fileNameSpans = $this->find("xpath", $this->fileListXpath)->findAll(
"xpath", $this->fileNamesXpath
);
//loop to keep on scrolling down to load not viewed files
//when the file count is not increasing, the file is not there
while ($previousFileCounter < count($fileNameSpans)) {
//check every file if the name is the one we are searching for
//but no need to check names that we checked already ($previousFileCounter)
for ($fileCounter = $previousFileCounter;
$fileCounter < count($fileNameSpans);
$fileCounter ++) {
//found the file
if ($fileNameSpans[$fileCounter]->getText() === $name ||
strip_tags($fileNameSpans[$fileCounter]->getHtml()) === $name) {
return $fileNameSpans[$fileCounter]->find(
"xpath", $this->fileRowFromNameXpath
);
}
$previousFileCounter = $fileCounter;
}

// scroll to the bottom of the page
// we need to scroll because the files app does only load a part of
// the files in one screen
$this->scrollDownAppContent(count($fileNameSpans), $session);

$fileNameSpans = $this->find("xpath", $this->fileListXpath)->findAll(
"xpath", $this->fileNamesXpath
);
}
}

/**
* scrolls down the file list, to load not yet displayed files
* @param int $numberOfFilesOld how many files were listed before the scroll.
* So we can guess how long to wait for the loading of new files to finish
* @param Session $session
* @param int $timeout
*/
public function scrollDownAppContent ($numberOfFilesOld, Session $session, $timeout=5)
{
$session->evaluateScript(
'$("#' . $this->appContentId . '").scrollTop($("#' . $this->appContentId . '")[0].scrollHeight);'
);

// there is no loading indicator here, so we are going to wait until we have
// more files than before
for ($counter = 0; $counter <= $timeout; $counter ++) {
$fileNameSpans = $this->find("xpath", $this->fileListXpath)->findAll(
"xpath", $this->fileNamesXpath
);
if (count($fileNameSpans) > $numberOfFilesOld) {
break;
}
sleep(1);
}
}

/**
* Takes a row of a file and finds the Action Button in it
* @param \Behat\Mink\Element\NodeElement $fileRow
* @return \Behat\Mink\Element\NodeElement|NULL
*/
public function findFileActionButtonInFileRow (\Behat\Mink\Element\NodeElement $fileRow)
{
return $fileRow->find("xpath", $this->fileActionMenuBtnXpath);
}

/**
* Takes a row of a file and finds the File Action in it
* the File Action Button must be clicked first
* @param \Behat\Mink\Element\NodeElement $fileRow
* @return \Behat\Mink\Element\NodeElement|NULL
*/
public function findFileActionMenuInFileRow (\Behat\Mink\Element\NodeElement $fileRow)
{
return $fileRow->find("xpath", $this->fileActionMenuXpath);
}

/**
* finds the actual action link in the action menu
* @param string $action
* @param \Behat\Mink\Element\NodeElement $actionMenu
* @return \Behat\Mink\Element\NodeElement|NULL
*/
public function findButtonInActionMenu ($action, \Behat\Mink\Element\NodeElement $actionMenu)
{
return $actionMenu->find("xpath",
sprintf($this->fileActionXpath, $action)
);
}

/**
* renames a file
* @param string $fromFileName
* @param string $toFileName
* @param Session $session
*/
public function renameFile($fromFileName, $toFileName, Session $session)
{
$fileRow=$this->findFileRowByName($fromFileName, $session);
$actionMenuBtn=$this->findFileActionButtonInFileRow($fileRow);
$actionMenuBtn->click();
$actionMenu=$this->findFileActionMenuInFileRow($fileRow);
$this->findButtonInActionMenu($this->renameActionLabel, $actionMenu)->click();
$fileRow->find("xpath", $this->fileRenameInputXpath)->setValue($toFileName);
$fileRow->find("xpath", $this->fileRenameInputXpath)->blur();
$this->waitTillElementIsNull($this->fileBusyIndicatorXpath);
}

public function findDeleteByNo($number) {
$xpath = sprintf($this->fileDeleteXpathByNo,$number);
return $this->find("xpath", $xpath);
Expand All @@ -98,6 +229,18 @@ public function waitTillPageIsloaded($timeout)
}
}

/**
* returns the tooltip that is displayed next to the filename if something is wrong
* @param string $fileName
* @param Session $session
* @return string
*/
public function getTooltipOfFile ($fileName, Session $session)
{
$fileRow=$this->findFileRowByName($fileName, $session);
return $fileRow->find("xpath", $this->fileTooltipXpath)->getText();
}

/**
* same as the original open() function but with a more slack
* URL verification as oC adds some extra parameters to the URL e.g.
Expand Down
Loading