Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/playwright-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Playwright tests

on:
push:
branches:
- main

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed

- '[0-9]+.[0-9]+'
pull_request: ~

jobs:
playwright-oss:
name: "Playwright/OSS"
uses: ibexa/gh-workflows/.github/workflows/playwright-browser-tests.yml@ibx-11740-playwright

Check failure on line 13 in .github/workflows/playwright-tests.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use full commit SHA hash for this dependency.

See more on https://sonarcloud.io/project/issues?id=ibexa_admin-ui&issues=AZ701bIVbb0SHGvLlmsi&open=AZ701bIVbb0SHGvLlmsi&pullRequest=1947
with:
project-edition: 'oss'
test-package: 'admin-ui'
secrets: inherit

Check warning on line 17 in .github/workflows/playwright-tests.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Only pass required secrets to this workflow.

See more on https://sonarcloud.io/project/issues?id=ibexa_admin-ui&issues=AZ701bIVbb0SHGvLlmse&open=AZ701bIVbb0SHGvLlmse&pullRequest=1947

playwright-headless:
name: "Playwright/Headless"
uses: ibexa/gh-workflows/.github/workflows/playwright-browser-tests.yml@ibx-11740-playwright

Check failure on line 21 in .github/workflows/playwright-tests.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use full commit SHA hash for this dependency.

See more on https://sonarcloud.io/project/issues?id=ibexa_admin-ui&issues=AZ71BLJSjzY0enYhtimc&open=AZ71BLJSjzY0enYhtimc&pullRequest=1947
with:
project-edition: 'headless'
test-package: 'admin-ui'
secrets: inherit

Check warning on line 25 in .github/workflows/playwright-tests.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Only pass required secrets to this workflow.

See more on https://sonarcloud.io/project/issues?id=ibexa_admin-ui&issues=AZ701bIVbb0SHGvLlmsf&open=AZ701bIVbb0SHGvLlmsf&pullRequest=1947

playwright-experience:
name: "Playwright/Experience"
uses: ibexa/gh-workflows/.github/workflows/playwright-browser-tests.yml@ibx-11740-playwright

Check failure on line 29 in .github/workflows/playwright-tests.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use full commit SHA hash for this dependency.

See more on https://sonarcloud.io/project/issues?id=ibexa_admin-ui&issues=AZ71BLJSjzY0enYhtimd&open=AZ71BLJSjzY0enYhtimd&pullRequest=1947
with:
project-edition: 'experience'
test-package: 'admin-ui'
secrets: inherit

Check warning on line 33 in .github/workflows/playwright-tests.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Only pass required secrets to this workflow.

See more on https://sonarcloud.io/project/issues?id=ibexa_admin-ui&issues=AZ701bIVbb0SHGvLlmsg&open=AZ701bIVbb0SHGvLlmsg&pullRequest=1947

playwright-commerce:
name: "Playwright/Commerce"
uses: ibexa/gh-workflows/.github/workflows/playwright-browser-tests.yml@ibx-11740-playwright

Check failure on line 37 in .github/workflows/playwright-tests.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use full commit SHA hash for this dependency.

See more on https://sonarcloud.io/project/issues?id=ibexa_admin-ui&issues=AZ701bIVbb0SHGvLlmsl&open=AZ701bIVbb0SHGvLlmsl&pullRequest=1947
with:
project-edition: 'commerce'
test-package: 'admin-ui'
secrets: inherit

Check warning on line 41 in .github/workflows/playwright-tests.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Only pass required secrets to this workflow.

See more on https://sonarcloud.io/project/issues?id=ibexa_admin-ui&issues=AZ701bIVbb0SHGvLlmsh&open=AZ701bIVbb0SHGvLlmsh&pullRequest=1947
9 changes: 9 additions & 0 deletions tests/playwright-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.env
.auth/
playwright-report/
test-results/
node_modules/
dist/
# un-ignore files excluded by root .gitignore
!tsconfig.json
!package-lock.json
107 changes: 107 additions & 0 deletions tests/playwright-tests/Pages/ContentManagementPage.ts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page file seems like a mix of different pages and components in Behat notation and some code overlaps with https://github.com/ibexa/cohesivo-playwright/blob/5.0/src/pages/admin/AdminUiPage.ts - .ie https://github.com/ibexa/cohesivo-playwright/blob/5b13038a8e17b0b0e01c99d9d67b765f9e69ff12/src/pages/admin/AdminUiPage.ts#L22 and https://github.com/ibexa/admin-ui/pull/1947/changes#diff-46711842a811d22853c02fa9e2fee52d5502bf751dcae9f71e6994d45139d23eR87 do the same thing.

My recommendation is to scrap https://github.com/ibexa/cohesivo-playwright/blob/5.0/src/pages/admin/AdminUiPage.ts (leave maybe login stuff in ibexa/cohesivo-playwright as login stuff is also implemented in ibexa/behat) and to break this file into proper pages (as in behat admin-ui pages https://github.com/ibexa/admin-ui/tree/6.0/src/lib/Behat/Page).

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { Page, expect } from '@playwright/test';
import { AdminUiPage, UniversalDiscoveryWidget } from '@ibexa/cohesivo-playwright';

export class ContentManagementPage extends AdminUiPage {
readonly udw: UniversalDiscoveryWidget;

constructor(page: Page) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add all css locators to the constructor, so they can be reused and code looks cleaner.

On the other hand - sometimes getBy locators are used, is it possible to switch completely to getBy locators? Copilot suggests something like:

Element | Preferred locator
Button | getByRole()
Link | getByRole()
Checkbox | getByRole()
Text field | getByLabel()
Image | getByAltText()
Static text | getByText()
Custom component | getByTestId()
Loading spinner | CSS
Overlay | CSS
Toast | CSS or getByTestId()
Animation | CSS

super(page);
this.udw = new UniversalDiscoveryWidget(page);
}

async open(contentId: number, locationId: number): Promise<void> {
await this.page.goto(`/admin/view/content/${contentId}/full/1/${locationId}`);
await expect(this.page.locator('.ibexa-context-menu')).toBeVisible({ timeout: 20_000 });
}

/**
* Clicks an action button in the context menu by its visible label text.
* Handles both primary (visible) buttons and items hidden behind the "More" overflow button.
*/
async performAction(label: string): Promise<void> {
const contextMenu = this.page.locator('.ibexa-context-menu');
await expect(contextMenu.locator('.ibexa-btn').first()).toBeVisible({ timeout: 10_000 });

const primaryButton = contextMenu
.locator('.ibexa-context-menu__item:not(.ibexa-context-menu__item--more) .ibexa-btn')
.filter({ hasText: label })
.first();

// A primary button can be present in the DOM but covered by the "More" overflow.
// Probe with elementFromPoint (read-only, no failed click attempt in the report)
// and only then click for real, with Playwright's actionability checks intact.
const isClickable = await primaryButton.count() > 0 && await primaryButton.evaluate((el) => {
const box = el.getBoundingClientRect();
const topmost = document.elementFromPoint(box.x + box.width / 2, box.y + box.height / 2);
return topmost !== null && (el === topmost || el.contains(topmost));
});

if (isClickable) {
await primaryButton.click();
return;
}

await contextMenu.locator('.ibexa-btn--more').click();

// The multilevel popup branch is appended to <body>; visibility is toggled
// via the ibexa-popup-menu--hidden CSS class.
const popupItem = this.page
.locator('.ibexa-multilevel-popup-menu__branch:not(.ibexa-popup-menu--hidden) .ibexa-popup-menu__item:not(.ibexa-popup-menu__item--hidden)')
.filter({ hasText: label })
.first();
await expect(popupItem, `Action '${label}' not found in context menu`).toBeVisible({ timeout: 5_000 });
await popupItem.click();
}

async sendToTrash(): Promise<void> {
await this.performAction('Send to trash');

const modal = this.page.locator('#trash-location-modal, .ibexa-modal--trash-location').first();
await expect(modal).toBeVisible({ timeout: 10_000 });

// For items with children/relations the modal requires ticking confirmation
// checkboxes before the submit button becomes enabled.
const submitButton = modal.locator('.ibexa-btn--confirm-send-to-trash');
if (await submitButton.isDisabled()) {
const checkboxes = modal.locator('input[type="checkbox"]:not(:checked)');
const count = await checkboxes.count();
for (let i = 0; i < count; i++) {
await checkboxes.nth(i).check({ force: true });
}
}

await expect(submitButton).toBeEnabled({ timeout: 5_000 });
await submitButton.click();
await expect(modal).toBeHidden({ timeout: 10_000 });
}

async hide(): Promise<void> {
await this.performAction('Hide');
// "Hide" opens the "Schedule hiding" panel; confirm with the default "Hide now" option
await expect(
this.page.getByRole('heading', { name: 'Schedule hiding' }).filter({ visible: true }).first(),
).toBeVisible({ timeout: 10_000 });
await this.page.getByRole('button', { name: 'Confirm' }).filter({ visible: true }).first().click();
}

async assertOnContentView(itemName: string): Promise<void> {
await expect(this.page.locator('.ibexa-page-title h1')).toContainText(itemName, { timeout: 10_000 });
}

async assertSubitemPresent(name: string): Promise<void> {
const subItems = this.page.locator('.m-sub-items');
await expect(
subItems.locator('.ibexa-table__row').filter({ hasText: name }).first(),
).toBeVisible({ timeout: 10_000 });
}

async assertSubitemAbsent(name: string): Promise<void> {
// .m-sub-items is a React mount point — anchor on the rendered table
// (or its empty state) before asserting absence, to avoid passing on a blank mount.
const subItems = this.page.locator('.m-sub-items');
await expect(
subItems.locator('.ibexa-table, .ibexa-table__empty-table-text').first(),
).toBeVisible({ timeout: 10_000 });
await expect(subItems.locator('.ibexa-table__row').filter({ hasText: name })).toHaveCount(0);
}
}
86 changes: 86 additions & 0 deletions tests/playwright-tests/Pages/TrashPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Page, expect } from '@playwright/test';
import { AdminUiPage, UniversalDiscoveryWidget } from '@ibexa/cohesivo-playwright';

export class TrashPage extends AdminUiPage {
readonly udw: UniversalDiscoveryWidget;

constructor(page: Page) {
super(page);
this.udw = new UniversalDiscoveryWidget(page);
}

async open(): Promise<void> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Navigation between tabs should be done in specific page/component.

await this.navigateTo(`/admin/trash/list`);
}

async assertNotEmpty(): Promise<void> {
await expect(this.page.locator('.ibexa-table__row').first()).toBeVisible({ timeout: 10_000 });
}

async assertEmpty(): Promise<void> {
const emptyEl = this.page.locator('.ibexa-table__empty-table-text')
.or(this.page.getByText('Trash is empty'))
.or(this.page.getByText('No items'));
await expect(emptyEl.first()).toBeVisible({ timeout: 10_000 });
}

async emptyTrash(): Promise<void> {
const emptyBtn = this.page.locator('.ibexa-context-menu .ibexa-btn').filter({ hasText: 'Empty Trash' })
.or(this.page.locator('.ibexa-context-menu .ibexa-btn').filter({ hasText: 'Empty' })).first();
await emptyBtn.click();
await this.confirmDialogButton('Delete');
await this.assertEmpty();
}

async assertItemInTrash(name: string): Promise<void> {
await this.assertTableRowPresent(name);
}

async assertItemNotInTrash(name: string): Promise<void> {
await this.assertTableRowAbsent(name);
}

async deleteFromTrash(items: string[]): Promise<void> {
for (const item of items) {
await this.checkTableRow(item);
}
const deleteBtn = this.page.locator('button:not([data-bs-dismiss])').filter({ hasText: 'Delete' }).first();
await deleteBtn.click();
await this.confirmDialogButton('Delete');
}

async restoreFromTrash(items: string[]): Promise<void> {
for (const item of items) {
await this.checkTableRow(item);
}
// Find "Restore" button (not "Restore in a new location") by matching inner text exactly
const restoreBtn = this.page.locator('button').filter({ hasNotText: 'in a new location' }).filter({ hasText: 'Restore' }).first();
await restoreBtn.click();
}

/**
* Restores the checked items under the location given by path (e.g. "Media/Files"),
* driving the whole flow: restore button → UDW navigation → UDW confirm.
*/
async restoreUnderNewLocation(items: string[], newLocationPath: string): Promise<void> {
for (const item of items) {
await this.checkTableRow(item);
}
const restoreBtn = this.page.locator('button').filter({ hasText: 'Restore in a new location' })
.or(this.page.locator('button.ibexa-btn--open-udw')).first();
await restoreBtn.click();

await this.udw.selectPath(newLocationPath);
await this.udw.confirm();
}

async searchInTrash(query: string): Promise<void> {
const url = this.page.url().split('?')[0];
await this.page.goto(`${url}?trash_search[content_name]=${encodeURIComponent(query)}`);

@tomaszszopinski tomaszszopinski Jul 21, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this code work the same as in behat? Is seems like it bypasses UI interaction by using page.goto()

In behat it looked like:
$this->trashSearch->submitSearchText($searchQuery); $this->trashSearch->confirmSearch();
so, add text to the input -> click search.

}

async filterByContentType(contentTypeName: string): Promise<void> {
const select = this.page.locator('select').first();
await select.selectOption({ label: contentTypeName });
}
}
135 changes: 135 additions & 0 deletions tests/playwright-tests/Tests/Trash.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { test, expect } from '@playwright/test';
import { TrashPage } from '../Pages/TrashPage';
import { ContentManagementPage } from '../Pages/ContentManagementPage';
import { IbexaApiClient } from '@ibexa/cohesivo-playwright';


test.describe('Trash management', { tag: ['@IbexaOSS', '@IbexaHeadless', '@IbexaExperience', '@IbexaCommerce'] }, () => {
let api: IbexaApiClient;
let trashTestLocationId: number;
let trashTestContentId: number;
let runId: string;

test.beforeAll(async () => {
api = new IbexaApiClient();
await api.init();
runId = Date.now().toString().slice(-6);

trashTestContentId = await api.createFolder(`TrashTest${runId}`, 2);
trashTestLocationId = await api.getMainLocationId(trashTestContentId);
});

test.afterAll(async () => {
await api.deleteContent(trashTestContentId);
});

test('Trash can be emptied', async ({ page }) => {
const childId = await api.createFolder(`FolderToTrash${runId}`, trashTestLocationId);
const childLocId = await api.getMainLocationId(childId);

const contentPage = new ContentManagementPage(page);
await contentPage.open(childId, childLocId);
await contentPage.sendToTrash();

const trash = new TrashPage(page);
await trash.open();
await trash.assertNotEmpty();
await trash.emptyTrash();
await trash.assertEmpty();
});

test('Content can be moved to trash', async ({ page }) => {
const name = `FolderToTrashManually${runId}`;
const childId = await api.createFolder(name, trashTestLocationId);
const childLocId = await api.getMainLocationId(childId);

const contentPage = new ContentManagementPage(page);
await contentPage.open(childId, childLocId);
await contentPage.sendToTrash();

await contentPage.assertSuccessNotification(`Location '${name}' moved to Trash`);

const trash = new TrashPage(page);
await trash.open();
await trash.assertItemInTrash(name);
});

test('Element in trash can be deleted', async ({ page }) => {
const name = `DeleteFromTrash${runId}`;
const childId = await api.createFolder(name, trashTestLocationId);
const childLocId = await api.getMainLocationId(childId);

const contentPage = new ContentManagementPage(page);
await contentPage.open(childId, childLocId);
await contentPage.sendToTrash();

const trash = new TrashPage(page);
await trash.open();
await trash.assertItemInTrash(name);
await trash.deleteFromTrash([name]);
await trash.assertSuccessNotification('Deleted selected item(s) from Trash');
await trash.assertItemNotInTrash(name);
});

test('Element in trash can be restored', async ({ page }) => {
const name = `RestoreFromTrash${runId}`;
const childId = await api.createFolder(name, trashTestLocationId);
const childLocId = await api.getMainLocationId(childId);

const contentPage = new ContentManagementPage(page);
await contentPage.open(childId, childLocId);
await contentPage.sendToTrash();

const trash = new TrashPage(page);
await trash.open();
await trash.assertItemInTrash(name);
await trash.restoreFromTrash([name]);
await trash.assertSuccessNotification('Restored content to its original Location');
await trash.assertItemNotInTrash(name);
});

test('Element in trash can be restored under new location', async ({ page }) => {
const name = `RestoreFromTrashNewLocation${runId}`;
const childId = await api.createFolder(name, trashTestLocationId);
const childLocId = await api.getMainLocationId(childId);

const contentPage = new ContentManagementPage(page);
await contentPage.open(childId, childLocId);
await contentPage.sendToTrash();

const trash = new TrashPage(page);
await trash.open();
await trash.assertItemInTrash(name);
await trash.restoreUnderNewLocation([name], 'Media/Files');

await trash.assertSuccessNotification("Restored content under Location 'Files'");
await trash.assertItemNotInTrash(name);

// Verify the content actually landed under Media/Files (path resolution throws if absent)
const restoredContentId = await api.getContentIdByPath(`Media/Files/${name}`);
expect(restoredContentId).toBe(childId);

await api.deleteContent(childId);
});

test('Element in trash can be found by search', async ({ page }) => {
const name1 = `TrashSearch1${runId}`;
const name2 = `TrashSearch2${runId}`;
const childId1 = await api.createFolder(name1, trashTestLocationId);
const childLocId1 = await api.getMainLocationId(childId1);
const childId2 = await api.createFolder(name2, trashTestLocationId);
const childLocId2 = await api.getMainLocationId(childId2);

const contentPage = new ContentManagementPage(page);
await contentPage.open(childId1, childLocId1);
await contentPage.sendToTrash();
await contentPage.open(childId2, childLocId2);
await contentPage.sendToTrash();

const trash = new TrashPage(page);
await trash.open();
await trash.searchInTrash(name1);
await trash.assertItemInTrash(name1);
await trash.assertItemNotInTrash(name2);
});
});
Loading
Loading