‪TYPO3CMS  ‪main
PasswordLogin.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 Codeception\Module;
21 use Codeception\Module\WebDriver;
22 use Codeception\Util\Locator;
23 use Facebook\WebDriver\WebDriverKeys;
24 
28 final class ‪PasswordLogin extends Module
29 {
33  protected array ‪$config = [
34  'passwords' => [],
35  ];
36 
47  public function ‪useExistingSession(string $role, float|int $waitTime = 0.5): void
48  {
49  $webDriver = $this->‪getWebDriver();
50 
51  $hasSession = $this->‪loadSession($role);
52 
53  $webDriver->amOnPage('/typo3');
54  $webDriver->wait($waitTime);
55 
56  if (!$hasSession) {
57  $webDriver->waitForElement('body[data-typo3-login-ready]');
58  $password = $this->_getConfig('passwords')[$role];
59  $webDriver->fillField('#t3-username', $role);
60  $webDriver->fillField('#t3-password', $password);
61  $webDriver->pressKey('#t3-password', WebDriverKeys::ENTER);
62  $webDriver->waitForElement('.t3js-scaffold-toolbar');
63  $webDriver->saveSessionSnapshot('login.' . $role);
64  }
65 
66  // Ensure main content frame is fully loaded, otherwise there are load-race-conditions ..
67  $webDriver->debugSection('IFRAME', 'Switch to list_frame');
68  $webDriver->waitForElement('iframe[name="list_frame"]');
69  $webDriver->switchToIFrame('list_frame');
70  $webDriver->waitForElement(Locator::firstElement('div.module'));
71  $webDriver->wait($waitTime);
72  // .. and switch back to main frame.
73  $webDriver->debugSection('IFRAME', 'Switch to main frame');
74  $webDriver->switchToIFrame();
75 
76  $webDriver->debug(sprintf('useExistingSession("%s", %s) finished.', $role, $waitTime));
77  }
78 
79  private function ‪loadSession(string $role): bool
80  {
81  $webDriver = $this->‪getWebDriver();
82  $webDriver->webDriver->manage()->deleteCookieNamed('be_typo_user');
83  $webDriver->webDriver->manage()->deleteCookieNamed('be_lastLoginProvider');
84  return $webDriver->loadSessionSnapshot('login.' . $role, false);
85  }
86 
87  private function ‪getWebDriver(): WebDriver
88  {
89  return $this->getModule('WebDriver');
90  }
91 }
‪TYPO3\CMS\Core\Tests\Acceptance\Helper\PasswordLogin\getWebDriver
‪getWebDriver()
Definition: PasswordLogin.php:87
‪TYPO3\CMS\Core\Tests\Acceptance\Helper\PasswordLogin
Definition: PasswordLogin.php:29
‪TYPO3\CMS\Core\Tests\Acceptance\Helper\PasswordLogin\$config
‪array $config
Definition: PasswordLogin.php:33
‪TYPO3\CMS\Core\Tests\Acceptance\Helper
Definition: PasswordLogin.php:18
‪TYPO3\CMS\Core\Tests\Acceptance\Helper\PasswordLogin\loadSession
‪loadSession(string $role)
Definition: PasswordLogin.php:79
‪TYPO3\CMS\Core\Tests\Acceptance\Helper\PasswordLogin\useExistingSession
‪useExistingSession(string $role, float|int $waitTime=0.5)
Definition: PasswordLogin.php:47