‪TYPO3CMS  ‪main
FrontendLoginCest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Facebook\WebDriver\Remote\RemoteWebDriver;
23 
25 {
26  private string ‪$sidebarSelector = '.sidebar.list-group';
27  private string ‪$usernameSelector = '.frame-type-felogin_login input[name="user"]';
28  private string ‪$passwordSelector = '.frame-type-felogin_login input[type="password"]';
29  private string ‪$submitSelector = '.frame-type-felogin_login input[type=submit]';
30  private string ‪$frameSelector = '.frame-type-felogin_login';
31 
32  public function ‪_before(‪ApplicationTester $I, ‪PageTree $pageTree): void
33  {
34  $I->useExistingSession('admin');
35  $I->click('Page');
36  $pageTree->‪openPath(['styleguide frontend demo']);
37  $I->switchToContentFrame();
38  $I->waitForElementVisible('select[name=actionMenu]');
39  $I->selectOption('select[name=actionMenu]', 'Layout');
40  $I->waitForElementVisible('.t3js-module-docheader-bar a[title="View webpage"]');
41  $I->wait(1);
42  $I->click('.t3js-module-docheader-bar a[title="View webpage"]');
43  $I->wait(1);
44  $I->executeInSelenium(static function (RemoteWebDriver $webdriver) {
45  $handles = $webdriver->getWindowHandles();
46  $lastWindow = end($handles);
47  $webdriver->switchTo()->window($lastWindow);
48  });
49  $I->wait(1);
50  $I->see('TYPO3 Styleguide Frontend', '.content');
51  $I->scrollTo('//a[contains(., "felogin_login")]');
52  $I->click('felogin_login', $this->sidebarSelector);
53  }
54 
55  public function ‪_after(‪ApplicationTester $I): void
56  {
57  // Close FE tab again and switch to BE to avoid side effects
58  $I->executeInSelenium(static function (RemoteWebDriver $webdriver) {
59  $handles = $webdriver->getWindowHandles();
60  // Avoid closing the main backend tab (holds the webdriver session) if the test failed to open the frontend tab
61  // (All subsequent tests would fail with "[Facebook\WebDriver\Exception\InvalidSessionIdException] invalid session id"
62  if (count($handles) > 1) {
63  $webdriver->close();
64  $firstWindow = current($handles);
65  $webdriver->switchTo()->window($firstWindow);
66  }
67  });
68  }
69 
70  public function ‪seeLoginFailed(‪ApplicationTester $I): void
71  {
72  $I->fillField($this->usernameSelector, 'username');
73  $I->fillField($this->passwordSelector, 'wrong password');
74  $I->click($this->submitSelector);
75  $I->see('Login failure', $this->frameSelector . ' > h3');
76  }
77 
79  {
80  $I->fillField($this->usernameSelector, 'styleguide-frontend-demo');
81  $I->fillField($this->passwordSelector, 'password');
82  $I->click($this->submitSelector);
83  $I->see('You are now logged in as \'styleguide-frontend-demo\'', $this->frameSelector);
84 
85  $I->amGoingTo('reload the page to see the logout button');
86  $I->scrollTo('//a[contains(., "felogin_login")]');
87  $I->click('felogin_login', $this->sidebarSelector);
88 
89  $I->see('Username styleguide-frontend-demo', $this->frameSelector);
90  $I->amGoingTo('log out');
91  $I->click($this->submitSelector);
92  }
93 }
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FrontendLoginCest\seeLoginFailed
‪seeLoginFailed(ApplicationTester $I)
Definition: FrontendLoginCest.php:70
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FrontendLoginCest\$sidebarSelector
‪string $sidebarSelector
Definition: FrontendLoginCest.php:26
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FrontendLoginCest\$frameSelector
‪string $frameSelector
Definition: FrontendLoginCest.php:30
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FrontendLoginCest
Definition: FrontendLoginCest.php:25
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FrontendLoginCest\$usernameSelector
‪string $usernameSelector
Definition: FrontendLoginCest.php:27
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend
Definition: ContentElementsCest.php:18
‪TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester
Definition: ApplicationTester.php:28
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FrontendLoginCest\$passwordSelector
‪string $passwordSelector
Definition: FrontendLoginCest.php:28
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\AbstractTree\openPath
‪openPath(array $path)
Definition: AbstractTree.php:55
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FrontendLoginCest\_before
‪_before(ApplicationTester $I, PageTree $pageTree)
Definition: FrontendLoginCest.php:32
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FrontendLoginCest\seeLoginSuccessAndLogout
‪seeLoginSuccessAndLogout(ApplicationTester $I)
Definition: FrontendLoginCest.php:78
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FrontendLoginCest\$submitSelector
‪string $submitSelector
Definition: FrontendLoginCest.php:29
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree
Definition: PageTree.php:26
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FrontendLoginCest\_after
‪_after(ApplicationTester $I)
Definition: FrontendLoginCest.php:55