Skip to content

Commit e913fb7

Browse files
committed
fix(e2e): resolve flaky plugin metadata test and service upstream validation
1 parent f67e0b5 commit e913fb7

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

e2e/tests/plugin_metadata.crud-all-fields.spec.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,29 @@ const deletePluginMetadata = async (req: typeof e2eReq, name: string) => {
3636
const getMonacoEditorValue = async (editPluginDialog: Locator) => {
3737
let editorValue = '';
3838
const textarea = editPluginDialog.locator('textarea');
39-
if (await textarea.count() > 0) {
40-
editorValue = await textarea.inputValue();
41-
}
42-
if (!editorValue || editorValue.trim() === '{') {
43-
const lines = await editPluginDialog.locator('.view-line').allTextContents();
44-
editorValue = lines.join('\n').replace(/\s+/g, ' ');
39+
40+
// Retry logic to handle potential race conditions where editor content isn't fully loaded
41+
for (let i = 0; i < 20; i++) {
42+
if (await textarea.count() > 0) {
43+
editorValue = await textarea.inputValue();
44+
}
45+
46+
// Fallback to reading view-lines if textarea value seems incomplete
47+
if (!editorValue || editorValue.trim() === '{') {
48+
const lines = await editPluginDialog.locator('.view-line').allTextContents();
49+
editorValue = lines.join('\n').replace(/\s+/g, ' ');
50+
}
51+
52+
// If we have a valid-looking value (not just '{'), return it
53+
if (editorValue && editorValue.trim() !== '{') {
54+
return editorValue;
55+
}
56+
57+
// Wait before retrying
58+
// eslint-disable-next-line playwright/no-wait-for-timeout
59+
await editPluginDialog.page().waitForTimeout(500);
4560
}
61+
4662
if (!editorValue || editorValue.trim() === '{') {
4763
const allText = await editPluginDialog.textContent();
4864
console.log('DEBUG: editorValue fallback failed, dialog text:', allText);

e2e/tests/services.crud-required-fields.spec.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,38 @@ test('should CRUD service with required fields', async ({ page }) => {
4242
await servicesPom.getAddServiceBtn(page).click();
4343
await servicesPom.isAddPage(page);
4444

45+
46+
47+
4548
await test.step('submit with required fields', async () => {
4649
await uiFillServiceRequiredFields(page, {
4750
name: serviceName,
4851
});
49-
52+
53+
// Ensure upstream is valid. In some configurations (e.g. http&stream),
54+
// the backend might require a valid upstream configuration.
55+
const upstreamSection = page.getByRole('group', { name: 'Upstream' }).first();
56+
const addNodeBtn = page.getByRole('button', { name: 'Add a Node' });
57+
await addNodeBtn.click();
58+
59+
const rows = upstreamSection.locator('tr.ant-table-row');
60+
await rows.first().locator('input').first().fill('127.0.0.1');
61+
await rows.first().locator('input').nth(1).fill('80');
62+
await rows.first().locator('input').nth(2).fill('1');
63+
5064
// Ensure the name field is properly filled before submitting
5165
const nameField = page.getByRole('textbox', { name: 'Name' }).first();
5266
await expect(nameField).toHaveValue(serviceName);
53-
67+
5468
await servicesPom.getAddBtn(page).click();
55-
69+
5670
// Wait for either success or error toast (longer timeout for CI)
5771
const alertMsg = page.getByRole('alert');
5872
await expect(alertMsg).toBeVisible({ timeout: 30000 });
59-
73+
6074
// Check if it's a success message
6175
await expect(alertMsg).toContainText('Add Service Successfully', { timeout: 5000 });
62-
76+
6377
// Close the toast
6478
await alertMsg.getByRole('button').click();
6579
await expect(alertMsg).toBeHidden();

0 commit comments

Comments
 (0)