Skip to content

Commit

Permalink
[FEATURE] changed logic for be login and prepare acceptance tests for…
Browse files Browse the repository at this point in the history
… execution and ensure they run successfully

Related: https://projekte.in2code.de/issues/69945
  • Loading branch information
PatFischer91 committed Mar 5, 2025
1 parent 95993d5 commit f0cd350
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ TYPO3_INSTALL_SITE_SETUP_TYPE=no
TYPO3_INSTALL_WEB_SERVER_CONFIG=apache

# CodeCeption
# Important: Backend username and password must be configured before starting Docker.
# If Docker is already running, restart using: make stop start
BE_USER=
BE_PASSWORD=
SELENIARM_PORT_4442=61000
SELENIARM_PORT_4443=61001
SELENIARM_PORT_4444=61002
Expand Down
85 changes: 79 additions & 6 deletions Tests/Acceptance/_support/Helper/BackendTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,87 @@

namespace In2code\Lux\Tests\Helper;

use In2code\Lux\Tests\Utility\ViewPortUtility;

class BackendTester extends \Codeception\Module
{
public function loginToBackend($I, $username = 'akellner', $password = 'akellner')
protected $backendConfig = [
'backendCookieValue' => '',
];

/**
* @return string
*/
public function getBackendCookieValue()
{
$I->amOnPage('/typo3/');
$I->fillField('#t3-username', $username);
$I->fillField('#t3-password', $password);
$I->click('Login');
$I->waitForElement('#typo3-cms-backend-backend-toolbaritems-systeminformationtoolbaritem');
return $this->backendConfig['backendCookieValue'];
}

/**
* @param string $backendCookieValue
*/
public function setBackendCookieValue(string $backendCookieValue)
{
$this->backendConfig['backendCookieValue'] = $backendCookieValue;
}

/**
* @param $tester
*/
public function loginToBackend($tester)
{
if (empty($_ENV['BE_USER']) || empty($_ENV['BE_PASSWORD'])) {
$this->getBackendUserAndPassword();
}

$tester->amOnPage('/typo3');

$tester->fillField('#t3-username', $_ENV['BE_USER']);
$tester->fillField('#t3-password', $_ENV['BE_PASSWORD']);

$tester->click('#t3-login-submit');

$cookie = $tester->grabCookie('be_typo_user');
$this->setBackendCookieValue($cookie);
}

/**
* @return void
*/
public function getBackendUserAndPassword(): void
{
echo "\r\n";
echo 'Backend Login needed!';
echo "\r\n";

echo 'Backend User:';
$_ENV['BE_USER'] = trim(fgets(STDIN));

echo 'Backend User Password:';
system('stty -echo');

$_ENV['BE_PASSWORD'] = trim(fgets(STDIN));

system('stty echo');

echo "\r\n";
echo 'Backend User and Password set';
}

/**
* @param $tester
*/
public function backendLogout($tester)
{
$tester->amOnPage('/typo3');
$tester->resizeWindow(ViewPortUtility::DESKTOP, 1080);

if (!empty($this->getBackendCookieValue())) {
$tester->setCookie('be_typo_user', $this->getBackendCookieValue());

$this->setBackendCookieValue('');
} else {
var_dump('ALREADY LOGGED OUT!');
}
}
}
22 changes: 22 additions & 0 deletions Tests/Acceptance/_support/Utility/ViewPortUtility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace In2code\Lux\Tests\Utility;

class ViewPortUtility
{
const MOBILE = 576;
const TABLET = 768;
const DESKTOP = 1400;

const HEIGHT_MOBILE = 852;
const HEIGHT_TABLET = 1024;
const HEIGHT_DESKTOP = 1080;
const WIDTH_MOBILE = 393;
const WIDTH_TABLET = 768;
const WIDTH_DESKTOP = 1400;
const MAX_HEIGHT = 14999;

const HEADER_OFFSET_Y_DESKTOP = -115;
const HEADER_OFFSET_Y_TABLET = -115;
const HEADER_OFFSET_Y_MOBILE = -63;
}
7 changes: 2 additions & 5 deletions Tests/Acceptance/acceptance.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: https://local.lux.de
url: '%TEST_URL%'
browser: chrome
host: seleniarm-hub
port: 4444
path: '/wd/hub'
window_size: 1920x1080
connection_timeout: 5
restart: true
capabilities:
browserName: "chrome"
acceptInsecureCerts: true
'goog:chromeOptions':
args: ["--no-sandbox", "--headless", "--disable-gpu", "--ignore-certificate-errors"]
args: ["--ignore-certificate-errors" ]
- \In2code\Lux\Tests\Helper\BackendTester
step_decorators: ~
62 changes: 51 additions & 11 deletions Tests/Acceptance/acceptance/Backend/AnalyseDashboardCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,61 @@ public function _before(AcceptanceTester $I)

public function loginToBackendSuccessfully(AcceptanceTester $I)
{
$I->click('Analyse');
$I->waitForElement('.modulemenu', 30);

// Warte auf den Container, in dem die AJAX-Inhalte geladen werden
$I->waitForElement('.panel-heading', 30);
$I->scrollTo('//span[contains(@class, "modulemenu-name") and text()="LUX"]');

// Alternative Methoden zum Warten:
$I->waitForText('Top 10', 30); // Wartet bis zu 30 Sekunden auf den Text
// ODER
$I->waitForAjax(30); // Wartet auf AJAX-Requests
$luxButton = '//button[@data-modulemenu-identifier="lux_module"]';
$isExpanded = $I->grabAttributeFrom($luxButton, 'aria-expanded');

// Jetzt erst nach dem Text suchen
$I->see('Top 10');
if ($isExpanded !== 'true') {
$I->click($luxButton);
}

// Optional: Debug-Hilfen
$I->makeScreenshot('after_ajax_load');
$I->wait(1);

$I->scrollTo('//span[contains(@class, "modulemenu-name") and text()="Analysis"]');
$I->click('//span[contains(@class, "modulemenu-name") and text()="Analysis"]');

$I->wait(2);

$I->switchToIFrame('list_frame');
$I->waitForElementVisible('body', 10); // Wartet darauf, dass das Body-Element im IFrame sichtbar ist

$dashboardElements = [
'//h3[contains(@class, "panel-title") and contains(text(), "Pagevisits")]',
'//h3[contains(@class, "panel-title") and contains(text(), "Downloads")]',
'//h3[contains(@class, "panel-title") and contains(text(), "Activity log")]'
];

foreach ($dashboardElements as $element) {
$I->seeElement($element);
}

$topSections = [
'//h3[contains(@class, "panel-title") and contains(text(), "Top 10 most visited pages")]',
'//h3[contains(@class, "panel-title") and contains(text(), "Top 10 downloads")]',
'//h3[contains(@class, "panel-title") and contains(text(), "Top 10 most visited news")]',
'//h3[contains(@class, "panel-title") and contains(text(), "Top 10 most used searchterms")]',
'//h3[contains(@class, "panel-title") and contains(text(), "Top Social Media Sources")]'
];

foreach ($topSections as $section) {
$I->seeElement($section);
}

$expectedContent = [
'//span[@data-page-identifier="UID1" and contains(text(), "Start")]',
'//span[@data-download-uid="3" and contains(text(), "productb.pdf")]',
'//span[@data-news-identifier="2" and contains(text(), "Testnews 2")]',
'//span[contains(text(), "LUX TYPO3")]'
];

foreach ($expectedContent as $content) {
$I->seeElement($content);
}

$I->switchToIFrame(); // Zurück zum Hauptkontext

// Weitere Tests...
//$I->see('Seitenaufrufe');
Expand Down
15 changes: 13 additions & 2 deletions Tests/Acceptance/acceptance/Backend/ModulesExistingCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,20 @@ public function _before(AcceptanceTester $I)

public function loginToBackendSuccessfully(AcceptanceTester $I)
{
$I->scrollTo('//span[contains(@class, "modulemenu-name") and text()="LUX"]');

$luxButton = '//button[@data-modulemenu-identifier="lux_module"]';
$isExpanded = $I->grabAttributeFrom($luxButton, 'aria-expanded');

if ($isExpanded !== 'true') {
$I->click($luxButton);
}

$I->wait(1);

$I->see('LUX');
$I->see('Analyse');
$I->see('Analysis');
$I->see('Leads');
$I->see('Kampagnen');
$I->see('Campaigns');
}
}
2 changes: 2 additions & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace: In2code\Lux\Tests
params:
- env
paths:
tests: Tests/Acceptance
output: Tests/Acceptance/_output
Expand Down

0 comments on commit f0cd350

Please sign in to comment.