add typescript test, update java test

This commit is contained in:
einhornimmond 2025-06-28 15:12:01 +02:00
parent f58276b655
commit bdb3b8f7a9
15 changed files with 226 additions and 6 deletions

View File

@ -12,6 +12,7 @@ import java.nio.file.Paths;
// Subclasses will inherit PER_CLASS behavior.
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class BaseTest {
protected Playwright playwright;
protected Browser browser;

View File

@ -6,15 +6,12 @@ import com.microsoft.playwright.Page;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class Toasts {
private final Page page;
public final Locator toastSlot;
public final Locator toastTypeError;
public final Locator toastTitle;
public final Locator toastMessage;
public Toasts(Page page) {
this.page = page;
toastSlot = page.locator("#__BVID__toaster-container");
toastTypeError = toastSlot.locator(".toast.text-bg-danger");
toastTitle = toastTypeError.locator(".gdd-toaster-title");
@ -22,7 +19,7 @@ public class Toasts {
}
public void assertErrorToastVisible() {
toastTypeError.waitFor(); // auf Fehler-Toast warten
toastTypeError.waitFor();
assertTrue(toastTitle.isVisible());
assertTrue(toastMessage.isVisible());
}

View File

@ -25,4 +25,8 @@ public class LoginPage {
submitButton.click();
});
}
public void navigate() {
page.navigate("http://localhost:3000/login");
}
}

View File

@ -18,7 +18,7 @@ public class InvalidLoginTest extends BaseTest {
@Test
void invalidUserSeesError() {
page.navigate("http://localhost:3000/login");
loginPage.navigate();
loginPage.login("peter@lustig.de", "wrongpass");
Toasts toast = new Toasts(page);
toast.assertErrorToastVisible();

View File

@ -19,7 +19,7 @@ public class ValidLoginTest extends BaseTest {
@Test
void validUserCanLogin() {
page.navigate("http://localhost:3000/login");
loginPage.navigate();
loginPage.login("peter@lustig.de", "Aa12345_");
page.waitForURL("http://localhost:3000/overview");
assertTrue(page.url().contains("/overview"));

View File

@ -0,0 +1,7 @@
# Playwright
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/

View File

@ -0,0 +1,22 @@
import type { Locator, Page } from '@playwright/test'
import { expect } from '@playwright/test'
export class Toasts {
public readonly toastSlot: Locator
public readonly toastTypeError: Locator
public readonly toastTitle: Locator
public readonly toastMessage: Locator
constructor(page: Page) {
this.toastSlot = page.locator('#__BVID__toaster-container')
this.toastTypeError = this.toastSlot.locator('.toast.text-bg-danger')
this.toastTitle = this.toastTypeError.locator('.gdd-toaster-title')
this.toastMessage = this.toastTypeError.locator('.gdd-toaster-body')
}
async assertErrorToastVisible(): Promise<void> {
await this.toastTypeError.waitFor({ state: 'visible' })
expect(this.toastTitle).toBeVisible()
expect(this.toastMessage).toBeVisible()
}
}

View File

@ -0,0 +1 @@
export const FRONTEND_URL = "http://localhost:3000"

View File

@ -0,0 +1,13 @@
{
"name": "typescript",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@playwright/test": "^1.53.1",
"@types/node": "^24.0.7"
},
"scripts": {
"test": "playwright test --reporter=list"
}
}

View File

@ -0,0 +1,28 @@
import type { Locator, Page } from '@playwright/test'
import { FRONTEND_URL } from '../config'
export class LoginPage {
readonly page: Page
readonly emailInput: Locator
readonly passwordInput: Locator
readonly submitButton: Locator
constructor(page: Page) {
this.page = page
this.emailInput = page.locator('#email-input-field')
this.passwordInput = page.locator('#password-input-field')
this.submitButton = page.locator("button[type='submit']")
}
async goto() {
await this.page.goto(`${FRONTEND_URL}/login`)
}
async login(email: string, password: string) {
await this.emailInput.fill(email)
await this.passwordInput.fill(password)
const responsePromise = this.page.waitForResponse('**/graphql')
await this.submitButton.click()
await responsePromise
}
}

View File

@ -0,0 +1,82 @@
import { defineConfig, devices } from '@playwright/test';
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
// Glob patterns or regular expressions that match test files.
testMatch: '*',
/* 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: 2,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? '90%' : '75%',
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* 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: 'http://localhost:3000',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
video: 'on-first-retry',
},
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },
/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],
/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://localhost:3000',
// reuseExistingServer: !process.env.CI,
// },
});

View File

@ -0,0 +1,13 @@
import { test, expect } from '@playwright/test'
import { LoginPage } from '../pages/LoginPage'
import { Toasts } from '../components/Toasts'
test('invalid login', async ({ page }) => {
const loginPage = new LoginPage(page)
await loginPage.goto()
await loginPage.login('peter@lustig.de', 'wrongpass')
const toast = new Toasts(page)
await toast.assertErrorToastVisible()
await page.waitForTimeout(50)
})

View File

@ -0,0 +1,11 @@
import { test, expect } from '@playwright/test'
import { LoginPage } from '../pages/LoginPage'
import { FRONTEND_URL } from '../config'
test('valid login', async ({ page }) => {
const loginPage = new LoginPage(page)
await loginPage.goto()
await loginPage.login('peter@lustig.de', 'Aa12345_')
await page.waitForURL(`${FRONTEND_URL}/overview`)
expect(page.url()).toContain('/overview')
})

View File

@ -0,0 +1,41 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@playwright/test@^1.53.1":
version "1.53.1"
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.53.1.tgz#3ad5a2ce334b4a78390fd91e0a9d8423c09bc808"
integrity sha512-Z4c23LHV0muZ8hfv4jw6HngPJkbbtZxTkxPNIg7cJcTc9C28N/p2q7g3JZS2SiKBBHJ3uM1dgDye66bB7LEk5w==
dependencies:
playwright "1.53.1"
"@types/node@^24.0.7":
version "24.0.7"
resolved "https://registry.yarnpkg.com/@types/node/-/node-24.0.7.tgz#ee580f7850c7eabaeef61ef96b8d8c04fdf94f53"
integrity sha512-YIEUUr4yf8q8oQoXPpSlnvKNVKDQlPMWrmOcgzoduo7kvA2UF0/BwJ/eMKFTiTtkNL17I0M6Xe2tvwFU7be6iw==
dependencies:
undici-types "~7.8.0"
fsevents@2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
playwright-core@1.53.1:
version "1.53.1"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.53.1.tgz#0b6f7a2006ccb6126ffcc3e3b2fa9efda23b6638"
integrity sha512-Z46Oq7tLAyT0lGoFx4DOuB1IA9D1TPj0QkYxpPVUnGDqHHvDpCftu1J2hM2PiWsNMoZh8+LQaarAWcDfPBc6zg==
playwright@1.53.1:
version "1.53.1"
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.53.1.tgz#86fb041b237a6868d163c87c4b9737fd1cac145e"
integrity sha512-LJ13YLr/ocweuwxyGf1XNFWIU4M2zUSo149Qbp+A4cpwDjsxRPj7k6H25LBrEHiEwxvRbD8HdwvQmRMSvquhYw==
dependencies:
playwright-core "1.53.1"
optionalDependencies:
fsevents "2.3.2"
undici-types@~7.8.0:
version "7.8.0"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-7.8.0.tgz#de00b85b710c54122e44fbfd911f8d70174cd294"
integrity sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw==