Skip to content

Commit

Permalink
[WIP] playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
achimfritz committed Jan 18, 2025
1 parent 9d29e35 commit 525091a
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace ContainerTests\DatasetImport\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\DataSet;

/**
* CLI command for setting up TYPO3 via CLI
*/
#[AsCommand('dataset:import', 'Import Dataset')]
class DatasetImportCommand extends Command
{
protected function configure(): void
{
$this->addArgument('path', InputArgument::REQUIRED, 'Path to CSV dataset to import');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
if (!class_exists(DataSet::class)) {
$io = new SymfonyStyle($input, $output);
$io->getErrorStyle()->error('Missing typo3/testing-framework dependency.');
return Command::FAILURE;
}
DataSet::import($input->getArgument('path'));
return Command::SUCCESS;
}

}
8 changes: 8 additions & 0 deletions Tests/Packages/dataset_import/Configuration/Services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

ContainerTests\DatasetImport\:
resource: '../Classes/*'
20 changes: 20 additions & 0 deletions Tests/Packages/dataset_import/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "containertests/dataset-import",
"type": "typo3-cms-extension",
"description": "Support extension providing dataset:import command",
"license": "GPL-2.0-or-later",
"require": {
"typo3/cms-core": "^13.4",
"typo3/testing-framework": "*"
},
"extra": {
"typo3/cms": {
"extension-key": "dataset_import"
}
},
"autoload": {
"psr-4": {
"ContainerTests\\DatasetImport\\": "Classes/"
}
}
}
7 changes: 7 additions & 0 deletions Tests/playwright/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/.state/
/.env
1 change: 1 addition & 0 deletions Tests/playwright/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22.2.0
16 changes: 16 additions & 0 deletions Tests/playwright/e2e/backend/form_framework.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const {test, expect} = require('@playwright/test');

test.beforeEach(async ({page}) => {
await page.goto('http://webserver:80/typo3/index.php');
})

test('Form Framework Module loads', async ({page}) => {
await page.click('[data-modulemenu-identifier="web_FormFormbuilder"]');
await page.waitForLoadState('networkidle');
const contentFrame = await page.frameLocator('#typo3-contentIframe');
expect(await contentFrame.locator('.module-body')).toBeVisible();
expect(await contentFrame.locator('.module-body > h1')).toHaveText('Form Management');
// TODO
// await betterTimes();
});

14 changes: 14 additions & 0 deletions Tests/playwright/e2e/helper/backend-login.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {test as setup, expect} from '@playwright/test';

setup('Backend login', async ({page}) => {
//await page.goto('/typo3/index.php');
await page.goto('http://webserver:80/typo3/index.php');
await page.fill('#t3-username', process.env.BE_USER || 'admin');
await page.fill('#t3-password', process.env.BE_USER_PASSWORD || 'Password.1');
await page.waitForTimeout(500);
await page.click('#t3-login-submit');
await page.waitForLoadState('networkidle');
await expect(await page.locator('.topbar-header-site-title')).toBeVisible();

await page.context().storageState({path: './.state/backend-login.json'});
});
15 changes: 15 additions & 0 deletions Tests/playwright/fixtures/backend/basic.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"pages"
,"uid","pid","sorting","deleted","t3_origuid","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","title","is_siteroot","slug"
,1,0,256,0,0,0,0,0,0,"Root Page",1,"/"
,2,1,256,0,0,0,0,0,0,"Another Page",0,"/another-page"
,155,1,256,0,0,0,0,0,0,"404 Page not found",0,"/404-page-not-found"
"tt_content"
,"uid","pid","sorting","deleted","sys_language_uid","l18n_parent","t3_origuid","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","header"
,1,1,256,0,0,0,0,0,0,0,0,"Regular Element #1"
,2,1,512,0,0,0,0,0,0,0,0,"Regular Element #2"
,3,155,512,0,0,0,0,0,0,0,0,"404 Welcome to nowhere"
"be_users"
,"uid","pid","tstamp","username","password","admin","disable","starttime","endtime","options","crdate","workspace_perms","deleted","TSconfig","lastlogin","workspace_id","db_mountpoints","usergroup","realName"
# password of both users is "password"
,1,0,1366642540,"admin","$1$tCrlLajZ$C0sikFQQ3SWaFAZ1Me0Z/1",1,0,0,0,0,1366642540,1,0,,1371033743,0,0,0,"Klaus"

15 changes: 15 additions & 0 deletions Tests/playwright/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "playwright",
"version": "1.0.0",
"main": "index.js",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"@playwright/test": "^1.49.0",
"@types/node": "^20.12.13",
"dotenv": "^16.4.5"
}
}
71 changes: 71 additions & 0 deletions Tests/playwright/playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// @ts-check
const {defineConfig, devices} = require('@playwright/test');
const path = require("node:path");
import dotenv from 'dotenv';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// Read from GitLab file variable $PLAYWRIGHT_ENV if set. ".env" file otherwise
dotenv.config({ path: process.env.PLAYWRIGHT_ENV || path.resolve(__dirname, '.env') });

/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
testDir: './e2e',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 3 : 0,
/* Opt out of parallel tests on CI. */
workers: 1,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [
['html', {open: 'never'}],
['list', {printSteps: true}],
['junit'],
],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: process.env.BASE_URL ? process.env.BASE_URL : 'https://foo.ddev.site',
baseURL: "http://webserver:80/",
ignoreHTTPSErrors: true,

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
screenshot: 'on',
},

/* Configure projects for major browsers */
projects: [
{
name: 'frontend-cookie',
testMatch: 'helper/frontend-cookie.setup.js',
},
{
name: 'backend-login',
testMatch: 'helper/backend-login.setup.js',
},
{
name: 'frontend',
testMatch: 'frontend/**/*.spec.js',
dependencies: ['frontend-cookie'],
use: {
storageState: path.join(__dirname, '.state/frontend-cookie.json'),
},
},
{
name: 'backend',
testMatch: 'backend/**/*.spec.js',
dependencies: ['backend-login'],
use: {
storageState: path.join(__dirname, '.state/backend-login.json'),
},
},
],
});
46 changes: 46 additions & 0 deletions Tests/playwright/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@playwright/test@^1.49.0":
version "1.49.1"
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.49.1.tgz#55fa360658b3187bfb6371e2f8a64f50ef80c827"
integrity sha512-Ky+BVzPz8pL6PQxHqNRW1k3mIyv933LML7HktS8uik0bUXNCdPhoS/kLihiO1tMf/egaJb4IutXd7UywvXEW+g==
dependencies:
playwright "1.49.1"

"@types/node@^20.12.13":
version "20.17.12"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.17.12.tgz#ee3b7d25a522fd95608c1b3f02921c97b93fcbd6"
integrity sha512-vo/wmBgMIiEA23A/knMfn/cf37VnuF52nZh5ZoW0GWt4e4sxNquibrMRJ7UQsA06+MBx9r/H1jsI9grYjQCQlw==
dependencies:
undici-types "~6.19.2"

dotenv@^16.4.5:
version "16.4.7"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.7.tgz#0e20c5b82950140aa99be360a8a5f52335f53c26"
integrity sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==

[email protected]:
version "2.3.2"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==

[email protected]:
version "1.49.1"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.49.1.tgz#32c62f046e950f586ff9e35ed490a424f2248015"
integrity sha512-BzmpVcs4kE2CH15rWfzpjzVGhWERJfmnXmniSyKeRZUs9Ws65m+RGIi7mjJK/euCegfn3i7jvqWeWyHe9y3Vgg==

[email protected]:
version "1.49.1"
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.49.1.tgz#830266dbca3008022afa7b4783565db9944ded7c"
integrity sha512-VYL8zLoNTBxVOrJBbDuRgDWa3i+mfQgDTrL8Ah9QXZ7ax4Dsj0MSq5bYgytRnDVVe+njoKnfsYkH3HzqVj5UZA==
dependencies:
playwright-core "1.49.1"
optionalDependencies:
fsevents "2.3.2"

undici-types@~6.19.2:
version "6.19.8"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02"
integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==

0 comments on commit 525091a

Please sign in to comment.