Skip to content

Commit a2a42b7

Browse files
ndoschekplanger
authored andcommittedAug 22, 2023
playwright: Update to latest versions and add new page objects
- Update `playwright` to the latest version - Extend page objects for compact and nested folders - Extend ExplorerView tests with compact folders Signed-off-by: Nina Doschek <ndoschek@eclipsesource.com>
1 parent d8f7729 commit a2a42b7

File tree

5 files changed

+115
-36
lines changed

5 files changed

+115
-36
lines changed
 

‎examples/playwright/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
"src"
3030
],
3131
"dependencies": {
32-
"@playwright/test": "^1.32.1",
32+
"@playwright/test": "^1.37.1",
3333
"fs-extra": "^9.0.8"
3434
},
3535
"devDependencies": {
3636
"@types/fs-extra": "^9.0.8",
37-
"allure-commandline": "^2.21.0",
38-
"allure-playwright": "^2.1.0",
37+
"allure-commandline": "^2.23.1",
38+
"allure-playwright": "^2.5.0",
3939
"rimraf": "^2.6.1",
4040
"typescript": "~4.5.5"
4141
},

‎examples/playwright/src/tests/theia-explorer-view.test.ts

+45
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ test.describe('Theia Explorer View', () => {
110110
});
111111

112112
test('should be able to check if compact folder "sampleFolderCompact/nestedFolder1/nestedFolder2" exists', async () => {
113+
const fileStatElements = await explorer.visibleFileStatNodes();
113114
// default setting `explorer.compactFolders=true` renders folders in a compact form - single child folders will be compressed in a combined tree element
114115
expect(await explorer.existsDirectoryNode('sampleFolderCompact/nestedFolder1/nestedFolder2', true /* compact */)).toBe(true);
116+
// the `existsDirectoryNode` function will expand the folder, hence we wait for the file nodes to increase as we expect a txt child file node
117+
await explorer.waitForFileNodesToIncrease(fileStatElements.length);
115118
});
116119

117120
test('should provide file stat node by path of compact folder "sampleFolderCompact/nestedFolder1/nestedFolder2/sampleFile1-1.txt"', async () => {
@@ -141,4 +144,46 @@ test.describe('Theia Explorer View', () => {
141144
expect(await explorer.existsFileNode('sample.txt')).toBe(true);
142145
});
143146

147+
test('should open context menu on nested folder segment "nestedFolder1"', async () => {
148+
expect(await explorer.existsDirectoryNode('sampleFolderCompact/nestedFolder1/nestedFolder2', true /* compact */)).toBe(true);
149+
const folder = await explorer.getFileStatNodeByLabel('sampleFolderCompact/nestedFolder1/nestedFolder2', true /* compact */);
150+
const menu = await folder.openContextMenuOnSegment('nestedFolder1');
151+
expect(await menu.isOpen()).toBe(true);
152+
153+
const menuItems = await menu.visibleMenuItems();
154+
expect(menuItems).toContain('New File...');
155+
expect(menuItems).toContain('New Folder...');
156+
expect(menuItems).toContain('Open in Terminal');
157+
expect(menuItems).toContain('Find in Folder...');
158+
159+
await menu.close();
160+
expect(await menu.isOpen()).toBe(false);
161+
});
162+
163+
test('should rename compact folder "sampleFolderCompact" to "sampleDirectoryCompact', async () => {
164+
expect(await explorer.existsDirectoryNode('sampleFolderCompact/nestedFolder1/nestedFolder2', true /* compact */)).toBe(true);
165+
await explorer.renameNode(
166+
'sampleFolderCompact/nestedFolder1/nestedFolder2', 'sampleDirectoryCompact',
167+
true /* confirm */, 'sampleFolderCompact' /* nodeSegmentLabel */);
168+
expect(await explorer.existsDirectoryNode('sampleDirectoryCompact/nestedFolder1/nestedFolder2', true /* compact */)).toBe(true);
169+
});
170+
171+
test('should delete nested folder "sampleDirectoryCompact/nestedFolder1/nestedFolder2"', async () => {
172+
const fileStatElements = await explorer.visibleFileStatNodes();
173+
expect(await explorer.existsDirectoryNode('sampleDirectoryCompact/nestedFolder1/nestedFolder2', true /* compact */)).toBe(true);
174+
await explorer.deleteNode('sampleDirectoryCompact/nestedFolder1/nestedFolder2', true /* confirm */, 'nestedFolder2' /* nodeSegmentLabel */);
175+
await explorer.waitForFileNodesToDecrease(fileStatElements.length);
176+
const updatedFileStatElements = await explorer.visibleFileStatNodes();
177+
expect(updatedFileStatElements.length).toBe(fileStatElements.length - 1);
178+
});
179+
180+
test('should delete compact folder "sampleDirectoryCompact/nestedFolder1"', async () => {
181+
const fileStatElements = await explorer.visibleFileStatNodes();
182+
expect(await explorer.existsDirectoryNode('sampleDirectoryCompact/nestedFolder1', true /* compact */)).toBe(true);
183+
await explorer.deleteNode('sampleDirectoryCompact/nestedFolder1', true /* confirm */, 'sampleDirectoryCompact' /* nodeSegmentLabel */);
184+
await explorer.waitForFileNodesToDecrease(fileStatElements.length);
185+
const updatedFileStatElements = await explorer.visibleFileStatNodes();
186+
expect(updatedFileStatElements.length).toBe(fileStatElements.length - 1);
187+
});
188+
144189
});

‎examples/playwright/src/theia-explorer-view.ts

+33-11
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export class TheiaExplorerFileStatNode extends TheiaTreeNode {
4747
return elementContainsClass(this.elementHandle, 'theia-DirNode');
4848
}
4949

50-
async getMenuItemByNamePath(...names: string[]): Promise<TheiaMenuItem> {
51-
const contextMenu = await this.openContextMenu();
50+
async getMenuItemByNamePath(names: string[], nodeSegmentLabel?: string): Promise<TheiaMenuItem> {
51+
const contextMenu = nodeSegmentLabel ? await this.openContextMenuOnSegment(nodeSegmentLabel) : await this.openContextMenu();
5252
const menuItem = await contextMenu.menuItemByNamePath(...names);
5353
if (!menuItem) { throw Error('MenuItem could not be retrieved by path'); }
5454
return menuItem;
@@ -106,8 +106,8 @@ export class TheiaExplorerView extends TheiaView {
106106
return [];
107107
}
108108

109-
async getFileStatNodeByLabel(label: string): Promise<TheiaExplorerFileStatNode> {
110-
const file = await this.fileStatNode(label);
109+
async getFileStatNodeByLabel(label: string, compact = false): Promise<TheiaExplorerFileStatNode> {
110+
const file = await this.fileStatNode(label, compact);
111111
if (!file) { throw Error('File stat node could not be retrieved by path fragments'); }
112112
return file;
113113
}
@@ -202,11 +202,11 @@ export class TheiaExplorerView extends TheiaView {
202202
return nodeId;
203203
}
204204

205-
async clickContextMenuItem(file: string, path: string[]): Promise<void> {
205+
async clickContextMenuItem(file: string, path: string[], nodeSegmentLabel?: string): Promise<void> {
206206
await this.activate();
207-
const fileStatNode = await this.fileStatNode(file);
207+
const fileStatNode = await this.fileStatNode(file, !!nodeSegmentLabel);
208208
if (!fileStatNode) { throw Error('File stat node could not be retrieved by path fragments'); }
209-
const menuItem = await fileStatNode.getMenuItemByNamePath(...path);
209+
const menuItem = await fileStatNode.getMenuItemByNamePath(path, nodeSegmentLabel);
210210
await menuItem.click();
211211
}
212212

@@ -248,19 +248,19 @@ export class TheiaExplorerView extends TheiaView {
248248
return fileStatElements.length;
249249
}
250250

251-
async deleteNode(path: string, confirm = true): Promise<void> {
251+
async deleteNode(path: string, confirm = true, nodeSegmentLabel?: string): Promise<void> {
252252
await this.activate();
253-
await this.clickContextMenuItem(path, ['Delete']);
253+
await this.clickContextMenuItem(path, ['Delete'], nodeSegmentLabel);
254254

255255
const confirmDialog = new TheiaDialog(this.app);
256256
await confirmDialog.waitForVisible();
257257
confirm ? await confirmDialog.clickMainButton() : await confirmDialog.clickSecondaryButton();
258258
await confirmDialog.waitForClosed();
259259
}
260260

261-
async renameNode(path: string, newName: string, confirm = true): Promise<void> {
261+
async renameNode(path: string, newName: string, confirm = true, nodeSegmentLabel?: string): Promise<void> {
262262
await this.activate();
263-
await this.clickContextMenuItem(path, ['Rename']);
263+
await this.clickContextMenuItem(path, ['Rename'], nodeSegmentLabel);
264264

265265
const renameDialog = new TheiaRenameDialog(this.app);
266266
await renameDialog.waitForVisible();
@@ -285,4 +285,26 @@ export class TheiaExplorerView extends TheiaView {
285285
}
286286
}
287287

288+
async waitForFileNodesToIncrease(numberBefore: number): Promise<void> {
289+
const fileStatNodesSelector = `${this.viewSelector} .theia-FileStatNode`;
290+
await this.page.waitForFunction(
291+
(predicate: { selector: string; numberBefore: number; }) => {
292+
const elements = document.querySelectorAll(predicate.selector);
293+
return !!elements && elements.length > predicate.numberBefore;
294+
},
295+
{ selector: fileStatNodesSelector, numberBefore }
296+
);
297+
}
298+
299+
async waitForFileNodesToDecrease(numberBefore: number): Promise<void> {
300+
const fileStatNodesSelector = `${this.viewSelector} .theia-FileStatNode`;
301+
await this.page.waitForFunction(
302+
(predicate: { selector: string; numberBefore: number; }) => {
303+
const elements = document.querySelectorAll(predicate.selector);
304+
return !!elements && elements.length < predicate.numberBefore;
305+
},
306+
{ selector: fileStatNodesSelector, numberBefore }
307+
);
308+
}
309+
288310
}

‎examples/playwright/src/theia-tree-node.ts

+12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { TheiaMenu } from './theia-menu';
2323
export class TheiaTreeNode {
2424

2525
labelElementCssClass = '.theia-TreeNodeSegmentGrow';
26+
nodeSegmentLabelCssClass = '.theia-tree-compressed-label-part';
2627
expansionToggleCssClass = '.theia-ExpansionToggle';
2728
collapsedCssClass = '.theia-mod-collapsed';
2829

@@ -66,4 +67,15 @@ export class TheiaTreeNode {
6667
return TheiaContextMenu.open(this.app, () => this.elementHandle.waitForSelector(this.labelElementCssClass));
6768
}
6869

70+
async openContextMenuOnSegment(nodeSegmentLabel: string): Promise<TheiaMenu> {
71+
const treeNodeLabel = await this.elementHandle.waitForSelector(this.labelElementCssClass);
72+
const treeNodeLabelSegments = await treeNodeLabel.$$(`span${this.nodeSegmentLabelCssClass}`);
73+
for (const segmentLabel of treeNodeLabelSegments) {
74+
if (await segmentLabel.textContent() === nodeSegmentLabel) {
75+
return TheiaContextMenu.open(this.app, () => Promise.resolve(segmentLabel));
76+
}
77+
}
78+
throw new Error('Could not find tree node segment label "' + nodeSegmentLabel + '"');
79+
}
80+
6981
}

‎yarn.lock

+22-22
Original file line numberDiff line numberDiff line change
@@ -1556,13 +1556,13 @@
15561556
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
15571557
integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==
15581558

1559-
"@playwright/test@^1.32.1":
1560-
version "1.35.1"
1561-
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.35.1.tgz#a596b61e15b980716696f149cc7a2002f003580c"
1562-
integrity sha512-b5YoFe6J9exsMYg0pQAobNDR85T1nLumUYgUTtKm4d21iX2L7WqKq9dW8NGJ+2vX0etZd+Y7UeuqsxDXm9+5ZA==
1559+
"@playwright/test@^1.37.1":
1560+
version "1.37.1"
1561+
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.37.1.tgz#e7f44ae0faf1be52d6360c6bbf689fd0057d9b6f"
1562+
integrity sha512-bq9zTli3vWJo8S3LwB91U0qDNQDpEXnw7knhxLM0nwDvexQAwx9tO8iKDZSqqneVq+URd/WIoz+BALMqUTgdSg==
15631563
dependencies:
15641564
"@types/node" "*"
1565-
playwright-core "1.35.1"
1565+
playwright-core "1.37.1"
15661566
optionalDependencies:
15671567
fsevents "2.3.2"
15681568

@@ -2733,25 +2733,25 @@ ajv@^8.0.0, ajv@^8.0.1, ajv@^8.6.3, ajv@^8.9.0:
27332733
require-from-string "^2.0.2"
27342734
uri-js "^4.2.2"
27352735

2736-
allure-commandline@^2.21.0:
2737-
version "2.23.0"
2738-
resolved "https://registry.yarnpkg.com/allure-commandline/-/allure-commandline-2.23.0.tgz#fdea57adee905808c0953ac51a234e474e9f5c27"
2739-
integrity sha512-bfAbyQzke0Gj48bxIAhHOcJ6DluYeR4uz3iQ1wJWx7TgGA1gazN1PXUtpr+wnX9eXCTRApEuggaJIduLik7Wsg==
2736+
allure-commandline@^2.23.1:
2737+
version "2.23.1"
2738+
resolved "https://registry.yarnpkg.com/allure-commandline/-/allure-commandline-2.23.1.tgz#b72ee444f586ab6ea403006960dfb4e641524c76"
2739+
integrity sha512-Qi1P8aFTwcD2XOYr4xqysPbgXFrl5JLY9jDBVQfOb6xkZ7/UtISfW6j0sAyVgMXyXQqYiQDSBcVS2wr1bm1Xlg==
27402740

2741-
allure-js-commons@2.4.0:
2742-
version "2.4.0"
2743-
resolved "https://registry.yarnpkg.com/allure-js-commons/-/allure-js-commons-2.4.0.tgz#1f75ff0ac153e30aaf4a4eb835fc6e55ee6610c6"
2744-
integrity sha512-mIQKAA91ihtMPzHJh7fQib/8MhZaUQ0oYtqFzS//5/Q+ILbMWW3WD2ISWtwniFAF2XWdRFjZ013IfUuKusbh1g==
2741+
allure-js-commons@2.5.0:
2742+
version "2.5.0"
2743+
resolved "https://registry.yarnpkg.com/allure-js-commons/-/allure-js-commons-2.5.0.tgz#ea589a25d61bbd9b117ba62d06ee2bc3e138bfad"
2744+
integrity sha512-CqhzJciKfM0fxImbfRSctPXTxnzxhD2rM1tX/ZkcyKyWzNmjdCn1n5j3/r5gPYeRfIT1NthLYcUF802tJ05QDg==
27452745
dependencies:
27462746
properties "^1.2.1"
27472747
uuid "^8.3.0"
27482748

2749-
allure-playwright@^2.1.0:
2750-
version "2.4.0"
2751-
resolved "https://registry.yarnpkg.com/allure-playwright/-/allure-playwright-2.4.0.tgz#8b8ce4ac27290dbc87120029d12aefc8b1477b75"
2752-
integrity sha512-YtOdQXKPUFFfXVEPUaH5ebNf/2tLmJ1q898l+TPCPBeTQWVpKxLJm5yQkBbu+cmbsN+FGCsfDHFiqcS/r6f71w==
2749+
allure-playwright@^2.5.0:
2750+
version "2.5.0"
2751+
resolved "https://registry.yarnpkg.com/allure-playwright/-/allure-playwright-2.5.0.tgz#734662971a4377f32ba341555c141f128a8ef453"
2752+
integrity sha512-DjkC9PLwmakzr9TrJ7jjv2tZBtO0i1vTDuvJcO9EhcqhejkGecupc5VtczxrDAlR7wWS4GCeOHTCT8mchBonxQ==
27532753
dependencies:
2754-
allure-js-commons "2.4.0"
2754+
allure-js-commons "2.5.0"
27552755

27562756
anser@^2.0.1:
27572757
version "2.1.1"
@@ -8895,10 +8895,10 @@ pkg-up@^3.1.0:
88958895
dependencies:
88968896
find-up "^3.0.0"
88978897

8898-
playwright-core@1.35.1:
8899-
version "1.35.1"
8900-
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.35.1.tgz#52c1e6ffaa6a8c29de1a5bdf8cce0ce290ffb81d"
8901-
integrity sha512-pNXb6CQ7OqmGDRspEjlxE49w+4YtR6a3X6mT1hZXeJHWmsEz7SunmvZeiG/+y1yyMZdHnnn73WKYdtV1er0Xyg==
8898+
playwright-core@1.37.1:
8899+
version "1.37.1"
8900+
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.37.1.tgz#cb517d52e2e8cb4fa71957639f1cd105d1683126"
8901+
integrity sha512-17EuQxlSIYCmEMwzMqusJ2ztDgJePjrbttaefgdsiqeLWidjYz9BxXaTaZWxH1J95SHGk6tjE+dwgWILJoUZfA==
89028902

89038903
postcss-modules-extract-imports@^3.0.0:
89048904
version "3.0.0"

0 commit comments

Comments
 (0)
Please sign in to comment.