Skip to content

Commit fb1a1fa

Browse files
E2E: Kafka connect flaky tests fixed (#1438)
Co-authored-by: German Osin <german.osin@gmail.com>
1 parent 036f514 commit fb1a1fa

File tree

2 files changed

+39
-51
lines changed

2 files changed

+39
-51
lines changed

e2e-playwright/src/services/commonFunctions.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { v4 as uuidv4 } from 'uuid';
2-
import { Page } from "@playwright/test";
2+
import { expect, Locator, Page } from "@playwright/test";
33

44
export const generateName = (prefix: string): string => {
55
return `${prefix}${uuidv4().slice(0, 8)}`;
@@ -17,6 +17,30 @@ export async function clearWithSelectAll(page: Page): Promise<void> {
1717
await page.keyboard.press('Backspace');
1818
}
1919

20-
// export const generateName = (prefix: string): string => {
21-
// return `${prefix}-${uuidv4().slice(0, 8)}`;
22-
// };
20+
export async function clickMenuThenItem(
21+
page: Page,
22+
expectable : Locator,
23+
result: Locator
24+
): Promise<void> {
25+
const VISIBLE_TIMEOUT = 5000;
26+
const ENABLED_TIMEOUT = 5000;
27+
const NETWORK_IDLE_TIMEOUT = 10000;
28+
29+
async function attemptClick() {
30+
await expect(expectable).toBeVisible({ timeout: VISIBLE_TIMEOUT });
31+
await expect(expectable).toBeEnabled({ timeout: ENABLED_TIMEOUT });
32+
await expectable.scrollIntoViewIfNeeded();
33+
await expectable.click();
34+
35+
await expect(result).toBeVisible({ timeout: VISIBLE_TIMEOUT });
36+
await result.click();
37+
}
38+
39+
try {
40+
await attemptClick();
41+
} catch {
42+
await page.reload({ waitUntil: 'domcontentloaded' });
43+
await page.waitForLoadState('networkidle', { timeout: NETWORK_IDLE_TIMEOUT }).catch(() => {});
44+
await attemptClick();
45+
}
46+
}

e2e-playwright/src/steps/KafkaConnect.steps.ts

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { Given, When, Then, setDefaultTimeout } from "@cucumber/cucumber";
33
import { expectVisibility } from "../services/uiHelper";
44
import { PlaywrightWorld } from "../support/PlaywrightWorld";
5-
import { expect } from "@playwright/test";
5+
import { clickMenuThenItem } from "../services/commonFunctions";
66

77
setDefaultTimeout(60 * 1000 * 2);
88

@@ -26,29 +26,11 @@ Given('KafkaConnect satus is: {string}, type is: {string}', async function(this:
2626
});
2727

2828
Given('KafkaConnect row menu menu item {string} is clicked', async function(this: PlaywrightWorld, menuItem: string) {
29-
const { page } = this;
30-
const rowMenu = this.locators.connectors.rowMenu;
31-
const rowMenuItem = this.locators.connectors.rowMenuItem(menuItem);
32-
33-
async function attemptClick() {
34-
await expect(rowMenu).toBeVisible({ timeout: 5000 });
35-
await expect(rowMenu).toBeEnabled({ timeout: 5000 });
36-
await rowMenu.scrollIntoViewIfNeeded();
37-
38-
await rowMenu.click();
39-
40-
await expect(rowMenuItem).toBeVisible({ timeout: 5000 });
41-
await rowMenuItem.click();
42-
}
43-
44-
try {
45-
await attemptClick();
46-
} catch (firstErr) {
47-
await page.reload({ waitUntil: 'domcontentloaded' });
48-
await page.waitForLoadState('networkidle', { timeout: 10000 }).catch(() => {});
49-
50-
await attemptClick();
51-
}
29+
await clickMenuThenItem(
30+
this.page,
31+
this.locators.connectors.rowMenu,
32+
this.locators.connectors.rowMenuItem(menuItem)
33+
);
5234
});
5335

5436
When('KafkaConnect connector named: {string} clicked', async function(this: PlaywrightWorld, name: string) {
@@ -64,29 +46,11 @@ Given('KafkaConnect connector page status is: {string}', async function(this: Pl
6446
});
6547

6648
When('KafkaConnect connector menu item {string} clicked', async function(this: PlaywrightWorld, menuItem: string) {
67-
const { page } = this;
68-
const menuButton = this.locators.connectors.internalMenuButton;
69-
const menuItemLocator = this.locators.connectors.internalMenuButtonItem(menuItem);
70-
71-
async function attemptClick() {
72-
await expect(menuButton).toBeVisible({ timeout: 5000 });
73-
await expect(menuButton).toBeEnabled({ timeout: 5000 });
74-
75-
await menuButton.click();
76-
77-
await expect(menuItemLocator).toBeVisible({ timeout: 5000 });
78-
await menuItemLocator.click();
79-
}
80-
81-
try {
82-
await attemptClick();
83-
} catch (firstErr) {
84-
await page.reload({ waitUntil: 'domcontentloaded' });
85-
86-
await page.waitForLoadState('networkidle', { timeout: 10000 }).catch(() => {});
87-
88-
await attemptClick();
89-
}
49+
await clickMenuThenItem(
50+
this.page,
51+
this.locators.connectors.internalMenuButton,
52+
this.locators.connectors.internalMenuButtonItem(menuItem)
53+
);
9054
});
9155

9256
Given('KafkaConnect connector page state is: {string}', async function(this: PlaywrightWorld, state: string) {

0 commit comments

Comments
 (0)