Skip to content

Commit

Permalink
[TASK] Stabilize Login->useExistingSession() for webserver
Browse files Browse the repository at this point in the history
A concrete `wait()` is added before waiting for the
login ready state for creating a user session. The
wait time is increased for retries.

Releases: main, 7, 6
  • Loading branch information
sbuerk committed Aug 16, 2023
1 parent 0f64df7 commit eb75e04
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Classes/Core/Acceptance/Helper/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Codeception\Module;
use Codeception\Module\WebDriver;
use Codeception\Util\Locator;
use Facebook\WebDriver\Exception\TimeoutException;
use TYPO3\CMS\Core\Security\JwtTrait;
use TYPO3\CMS\Core\Session\UserSession;

Expand Down Expand Up @@ -48,29 +49,43 @@ class Login extends Module
*/
public function useExistingSession($role = '')
{
// use retries + 1 seconds as wait time
$waitTime = 2;

$webDriver = $this->getWebDriver();
$webDriver->debugSection('useExistingSession', sprintf('For %s', $role));

$newUserSessionId = $this->getUserSessionIdByRole($role);

$webDriver->amOnPage('/typo3/index.php');
$webDriver->wait($waitTime);
$hasSession = $this->_loadSession();
if ($hasSession && $newUserSessionId !== '' && $newUserSessionId !== $this->getUserSessionId()) {
$webDriver->debugSection('useExistingSession', 'Session with invalid id found. Delete it.');
$webDriver->amOnPage('/typo3/index.php');
$webDriver->wait($waitTime);
$this->_deleteSession();
$hasSession = false;
}

if (!$hasSession) {
$webDriver->debugSection('useExistingSession', sprintf('No session, create new one for %s', $newUserSessionId));
$webDriver->amOnPage('/typo3/index.php');
$webDriver->wait($waitTime);
$webDriver->waitForElement('body[data-typo3-login-ready]');
$this->_createSession($newUserSessionId);
$webDriver->wait($waitTime);
}

// Reload the page to have a logged in backend.
$webDriver->amOnPage('/typo3/index.php');
$webDriver->wait($waitTime);

// Ensure main content frame is fully loaded, otherwise there are load-race-conditions ..
$webDriver->waitForElement('iframe[name="list_frame"]');
$webDriver->switchToIFrame('list_frame');
$webDriver->waitForElement(Locator::firstElement('div.module'));
$webDriver->wait($waitTime);
// .. and switch back to main frame.
$webDriver->switchToIFrame();
}
Expand Down

0 comments on commit eb75e04

Please sign in to comment.