From bb003479182f51a094214e0eec562842e43d89d4 Mon Sep 17 00:00:00 2001 From: Dipak Acharya Date: Mon, 20 May 2019 15:02:12 +0545 Subject: [PATCH] Add exception page page object and its related steps in acceptance test --- .../bootstrap/WebUIGeneralContext.php | 56 ++++++++++++- .../features/lib/GeneralExceptionPage.php | 79 +++++++++++++++++++ 2 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 tests/acceptance/features/lib/GeneralExceptionPage.php diff --git a/tests/acceptance/features/bootstrap/WebUIGeneralContext.php b/tests/acceptance/features/bootstrap/WebUIGeneralContext.php index 3d053d100e09..fc396ca9a167 100644 --- a/tests/acceptance/features/bootstrap/WebUIGeneralContext.php +++ b/tests/acceptance/features/bootstrap/WebUIGeneralContext.php @@ -33,6 +33,7 @@ use TestHelpers\SetupHelper; use TestHelpers\UploadHelper; use Page\GeneralErrorPage; +use Page\GeneralExceptionPage; require_once 'bootstrap.php'; @@ -48,6 +49,12 @@ class WebUIGeneralContext extends RawMinkContext implements Context { */ private $generalErrorPage; + /** + * + * @var GeneralExceptionPage + */ + private $generalExceptionPage; + /** * * @var LoginPage @@ -141,15 +148,18 @@ class WebUIGeneralContext extends RawMinkContext implements Context { * @param OwncloudPage $owncloudPage * @param LoginPage $loginPage * @param GeneralErrorPage $generalErrorPage + * @param GeneralExceptionPage $generalExceptionPage */ public function __construct( OwncloudPage $owncloudPage, LoginPage $loginPage, - GeneralErrorPage $generalErrorPage + GeneralErrorPage $generalErrorPage, + GeneralExceptionPage $generalExceptionPage ) { $this->owncloudPage = $owncloudPage; $this->loginPage = $loginPage; $this->generalErrorPage = $generalErrorPage; + $this->generalExceptionPage = $generalExceptionPage; } /** @@ -459,6 +469,50 @@ public function anErrorShouldBeDisplayedOnTheGeneralErrorPage($error) { ); } + /** + * @Then the user should be redirected to the general exception webUI page with the title :title + * + * @param string $title + * + * @return void + */ + public function theUserShouldBeRedirectedToGeneralExceptionPage($title) { + $title = $this->featureContext->substituteInLineCodes($title); + $this->generalExceptionPage->waitTillPageIsLoaded($this->getSession()); + // Just check that the actual title starts with the expected title. + // Theming can have other text following. + PHPUnit\Framework\Assert::assertStringStartsWith( + $title, $this->generalExceptionPage->getPageTitle() + ); + } + + /** + * @Then the title of the exception on general exception webUI page should be :title + * + * @param string $title + * + * @return void + */ + public function anErrorShouldBeDisplayedOnTheGeneralExceptionPageWithTitle($title) { + PHPUnit\Framework\Assert::assertEquals( + $title, $this->generalExceptionPage->getExceptionTitle() + ); + } + + /** + * @Then a message should be displayed on the general exception webUI page containing :message + * + * @param string $message + * + * @return void + */ + public function anErrorShouldBeDisplayedOnTheGeneralErrorPageContaining($message) { + PHPUnit\Framework\Assert::assertContains( + $message, + $this->generalExceptionPage->getExceptionMessage() + ); + } + /** * @When /^the administrator (disables|enables) the setting "([^"]*)" in the section "([^"]*)"$/ * diff --git a/tests/acceptance/features/lib/GeneralExceptionPage.php b/tests/acceptance/features/lib/GeneralExceptionPage.php new file mode 100644 index 000000000000..bf894a8b0439 --- /dev/null +++ b/tests/acceptance/features/lib/GeneralExceptionPage.php @@ -0,0 +1,79 @@ + + * @copyright Copyright (c) 2019 Dipak Acharya dipak@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 + * + */ + +namespace Page; + +use Behat\Mink\Session; +use SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException; + +/** + * GeneralExceptionPage page. + */ +class GeneralExceptionPage extends OwncloudPage { + protected $exceptionTitleXpath = ".//span[@class='error error-wide']//h2[1]"; + protected $exceptionMessageXpath = ".//span[@class='error error-wide']//p[@class='hint']"; + + /** + * + * @throws ElementNotFoundException + * @return string + */ + public function getExceptionMessage() { + $exceptionMessageElement = $this->find("xpath", $this->exceptionMessageXpath); + $this->assertElementNotNull( + $exceptionMessageElement, + __METHOD__ . + " could not find exception message xpath: '$this->exceptionMessageXpath'" + ); + return $exceptionMessageElement->getText(); + } + + /** + * + * @throws ElementNotFoundException + * @return string + */ + public function getExceptionTitle() { + $exceptionTitleElement = $this->find("xpath", $this->exceptionTitleXpath); + $this->assertElementNotNull( + $exceptionTitleElement, + __METHOD__ . + " could not find exception title xpath: '$this->exceptionTitleXpath'" + ); + return $exceptionTitleElement->getText(); + } + + /** + * + * @param Session $session + * @param int $timeout_msec + * + * @return void + * @throws \Exception + */ + public function waitTillPageIsLoaded( + Session $session, + $timeout_msec = STANDARD_UI_WAIT_TIMEOUT_MILLISEC + ) { + $this->waitTillXpathIsVisible($this->exceptionTitleXpath, $timeout_msec); + } +}