‪TYPO3CMS  11.5
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  protected string ‪$sidebarSelector = '.sidebar.list-group';
27  protected string ‪$usernameSelector = '.frame-type-felogin_login input[name="user"]';
28  protected string ‪$passwordSelector = '.frame-type-felogin_login input[type="password"]';
29  protected string ‪$submitSelector = '.frame-type-felogin_login input[type=submit]';
30  protected 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  $I->waitForElement('#typo3-pagetree-tree .nodes .node', 5);
37  $pageTree->‪openPath(['styleguide frontend demo']);
38  $I->switchToContentFrame();
39  $I->waitForElementVisible('select[name=actionMenu]');
40  $I->selectOption('select[name=actionMenu]', 'Columns');
41  $I->wait(1);
42  $I->waitForElementVisible('.t3js-module-docheader-bar a[title="View webpage"]');
43  $I->wait(1);
44  $I->click('.t3js-module-docheader-bar a[title="View webpage"]');
45  $I->wait(1);
46  $I->executeInSelenium(static function (RemoteWebDriver $webdriver) {
47  $handles = $webdriver->getWindowHandles();
48  $lastWindow = end($handles);
49  $webdriver->switchTo()->window($lastWindow);
50  });
51  $I->wait(1);
52  $I->see('TYPO3 Styleguide Frontend', '.content');
53  $I->scrollTo('//a[contains(., "felogin_login")]');
54  $I->click('felogin_login', $this->sidebarSelector);
55  }
56 
57  public function ‪_after(‪ApplicationTester $I): void
58  {
59  // Close FE tab again and switch to BE to avoid side effects
60  $I->executeInSelenium(static function (RemoteWebDriver $webdriver) {
61  $handles = $webdriver->getWindowHandles();
62  // Avoid closing the main backend tab (holds the webdriver session) if the test failed to open the frontend tab
63  // (All subsequent tests would fail with "[Facebook\WebDriver\Exception\InvalidSessionIdException] invalid session id"
64  if (count($handles) > 1) {
65  $webdriver->close();
66  $firstWindow = current($handles);
67  $webdriver->switchTo()->window($firstWindow);
68  }
69  });
70  }
71 
72  public function ‪seeLoginFailed(‪ApplicationTester $I): void
73  {
74  $I->fillField($this->usernameSelector, 'username');
75  $I->fillField($this->passwordSelector, 'wrong password');
76  $I->click($this->submitSelector);
77  $I->see('Login failure', $this->frameSelector . ' > h3');
78  }
79 
81  {
82  $I->fillField($this->usernameSelector, 'styleguide-frontend-demo');
83  $I->fillField($this->passwordSelector, 'password');
84  $I->click($this->submitSelector);
85  $I->see('You are now logged in as \'styleguide-frontend-demo\'', $this->frameSelector);
86 
87  $I->amGoingTo('reload the page to see the logout button');
88  $I->scrollTo('//a[contains(., "felogin_login")]');
89  $I->click('felogin_login', $this->sidebarSelector);
90 
91  $I->see('Username styleguide-frontend-demo', $this->frameSelector);
92  $I->amGoingTo('log out');
93  $I->click($this->submitSelector);
94  }
95 }
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FrontendLoginCest\seeLoginFailed
‪seeLoginFailed(ApplicationTester $I)
Definition: FrontendLoginCest.php:72
‪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:27
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FrontendLoginCest\$passwordSelector
‪string $passwordSelector
Definition: FrontendLoginCest.php:28
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree\openPath
‪openPath(array $path)
Definition: PageTree.php:76
‪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:80
‪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:31
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FrontendLoginCest\_after
‪_after(ApplicationTester $I)
Definition: FrontendLoginCest.php:57