Skip to content

Commit d4f48b6

Browse files
committed
Ksql first part
1 parent de47aeb commit d4f48b6

File tree

9 files changed

+190
-7
lines changed

9 files changed

+190
-7
lines changed

e2e-playwright/config/cucumber.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable */
22
module.exports = {
33
default: {
4-
timeout: 30000,
4+
timeout: 60000,
55
tags: process.env.npm_config_TAGS || "",
66
formatOptions: {
77
snippetInterface: "async-await"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Feature: Ksqldb page visibility
2+
3+
Scenario: KSQL DB elements visibility
4+
Given KSQL DB is visible
5+
When click on KSQL DB link
6+
Then KSQL DB heading visible
7+
Then the part of current URL should be "ksqldb"
8+
Given KSQL DB Tables header visible is: "true"
9+
Given KSQL DB Streams header visible is: "true"
10+
Given KSQL DB Tables link visible is: "true"
11+
Given KSQL DB Streams link visible is: "true"
12+
When KSQL DB ExecuteKSQLRequest click
13+
Given KSQL DB Clear visible is: "true"
14+
Given KSQL DB Execute visible is: "true"
15+
16+
Scenario: KSQL DB queries
17+
Given KSQL DB is visible
18+
When click on KSQL DB link
19+
Then KSQL DB heading visible
20+
Then the part of current URL should be "ksqldb"
21+
Given KSQL DB Tables header visible is: "true"
22+
Given KSQL DB Streams header visible is: "true"
23+
Given KSQL DB Tables link visible is: "true"
24+
Given KSQL DB Streams link visible is: "true"
25+
26+
When KSQL DB ExecuteKSQLRequest click
27+
Given KSQL DB textbox visible is: "true"
28+
Given KSQL DB KSQL for stream starts with: "STREAM_ONE", kafka_topic starts with: "NewAutoTopic", value_format: "json"
29+
Then KSQL DB stream created
30+
When KSQL DB Stream clicked
31+
Then KSQL DB stream starts with: "STREAM_ONE" visible is: "true"
32+
33+
When KSQL DB ExecuteKSQLRequest click
34+
Given KSQL DB textbox visible is: "true"
35+
Then KSQL DB KSQL for table starts with: "TABLE_ONE", stream starts with: "STREAM_ONE"
36+
Then KSQL DB table created
37+
When KSQL DB Table clicked
38+
Then KSQL DB table starts with: "TABLE_ONE" visible is: "true"
39+

e2e-playwright/src/hooks/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Before(async function(this: PlaywrightWorld, { pickle }) {
3030
await this.init(context, scenarioName);
3131
});
3232

33-
After({ timeout: 30000 }, async function(this: PlaywrightWorld, { pickle, result }) {
33+
After({ timeout: 60000 }, async function(this: PlaywrightWorld, { pickle, result }) {
3434
let img: Buffer | undefined;
3535
const path = `./test-results/trace/${pickle.id}.zip`;
3636
try {

e2e-playwright/src/pages/KSQLDB/ksqldbLocators.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,12 @@ export default class ksqlDbLocators {
1111
get executeKSQLREquestButton(): Locator { return this.page.getByRole('button', { name: 'Execute KSQL Request' })};
1212
get tablesLink(): Locator { return this.page.getByRole('link', { name: 'Tables' })};
1313
get streamsLink(): Locator { return this.page.getByRole('link', { name: 'Streams' })};
14-
14+
get tablesHeader(): Locator { return this.page.getByTitle('Tables').locator('div')};
15+
get streamsHeader(): Locator { return this.page.getByTitle('Streams').locator('div')};
16+
get textField(): Locator { return this.page.locator('.ace_content')};
17+
get clear(): Locator { return this.page.getByRole('button', { name: 'Clear', exact: true })};
18+
get execute(): Locator { return this.page.getByRole('button', { name: 'Execute', exact: true })};
19+
get success(): Locator { return this.page.getByRole('cell', { name: 'SUCCESS' })};
20+
get streamCSreated(): Locator { return this.page.getByRole('cell', { name: 'Stream created' })};
21+
get clearResults(): Locator { return this.page.getByRole('button', { name: 'Clear results' })};
1522
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
export function createStreamQuery(
3+
streamName: string,
4+
topicName: string,
5+
valueFormat: string = "json",
6+
partitions: number = 1
7+
): string {
8+
return `CREATE STREAM ${streamName} (profileId VARCHAR, latitude DOUBLE, longitude DOUBLE ) WITH (kafka_topic='${topicName}', value_format='${valueFormat}', partitions=${partitions});`;
9+
}
10+
11+
export function createTableQuery(tableName: string, streamName: string): string {
12+
return `CREATE TABLE ${tableName} AS SELECT profileId, LATEST_BY_OFFSET(latitude) AS la, LATEST_BY_OFFSET(longitude) AS lo FROM ${streamName} GROUP BY profileId EMIT CHANGES;`;
13+
}
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import { v4 as uuidv4 } from 'uuid';
2+
import { Page } from "@playwright/test";
23

34
export const generateName = (prefix: string): string => {
4-
return `${prefix}-${uuidv4().slice(0, 8)}`;
5+
return `${prefix}${uuidv4().slice(0, 8)}`;
56
};
7+
8+
export async function Delete(page: Page, times: number = 5): Promise<void> {
9+
for (let i = 0; i < times; i++) {
10+
await page.keyboard.press('Delete');
11+
}
12+
}
13+
14+
// export const generateName = (prefix: string): string => {
15+
// return `${prefix}-${uuidv4().slice(0, 8)}`;
16+
// };

e2e-playwright/src/services/uiHelper.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Locator } from '@playwright/test';
22
import expect from "../helper/util/expect";
3+
import { Page } from "@playwright/test";
34

45
export const expectVisibility = async(locator: Locator, visibleString: string): Promise<void> => {
56
if (visibleString === "true") {
@@ -54,4 +55,9 @@ export const expectVisuallyActive = async(
5455
style.cursor !== 'not-allowed';
5556

5657
expect(isClickable).toBe(shouldBeClickable);
57-
};
58+
};
59+
60+
export async function refreshPageAfterDelay(page: Page, delayMs: number = 35000): Promise<void> {
61+
await page.waitForTimeout(delayMs);
62+
await page.reload();
63+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/* eslint-disable no-unused-vars */
2+
import { Given, When, Then, setDefaultTimeout } from "@cucumber/cucumber";
3+
import { expect } from "@playwright/test";
4+
import { expectVisibility, refreshPageAfterDelay } from "../services/uiHelper";
5+
import { PlaywrightWorld } from "../support/PlaywrightWorld";
6+
import { createStreamQuery, createTableQuery } from "../services/KsqlScripts";
7+
import { generateName, Delete } from "../services/commonFunctions";
8+
9+
setDefaultTimeout(60 * 1000 * 4);
10+
11+
Given('KSQL DB Tables header visible is: {string}', async function(this: PlaywrightWorld, visible: string) {
12+
await expectVisibility(this.locators.ksqlDb.tablesHeader, visible);
13+
});
14+
15+
Given('KSQL DB Streams header visible is: {string}', async function(this: PlaywrightWorld, visible: string) {
16+
await expectVisibility(this.locators.ksqlDb.streamsHeader, visible);
17+
});
18+
19+
Given('KSQL DB Tables link visible is: {string}', async function(this: PlaywrightWorld, visible: string) {
20+
await expectVisibility(this.locators.ksqlDb.tablesLink, visible);
21+
});
22+
23+
Given('KSQL DB Streams link visible is: {string}', async function(this: PlaywrightWorld, visible: string) {
24+
await expectVisibility(this.locators.ksqlDb.streamsLink, visible);
25+
});
26+
27+
When('KSQL DB ExecuteKSQLRequest click', async function(this: PlaywrightWorld) {
28+
await this.locators.ksqlDb.executeKSQLREquestButton.click();
29+
});
30+
31+
Given('KSQL DB Clear visible is: {string}', async function(this: PlaywrightWorld, visible: string) {
32+
await expectVisibility(this.locators.ksqlDb.clear, visible);
33+
});
34+
35+
Given('KSQL DB Execute visible is: {string}', async function(this: PlaywrightWorld, visible: string) {
36+
await expectVisibility(this.locators.ksqlDb.execute, visible);
37+
});
38+
39+
Given('KSQL DB textbox visible is: {string}', async function(this: PlaywrightWorld, visible: string) {
40+
await expectVisibility(this.locators.ksqlDb.textField, visible);
41+
});
42+
43+
Given('KSQL DB KSQL for stream starts with: {string}, kafka_topic starts with: {string}, value_format: {string}',
44+
async function(this: PlaywrightWorld, stream: string, topic: string, format: string) {
45+
const topicName = generateName(topic);
46+
const streamName = generateName(stream).toUpperCase();
47+
const query = createStreamQuery(streamName, topicName, format);
48+
49+
await this.locators.ksqlDb.clear.click();
50+
const textbox = this.locators.ksqlDb.textField;
51+
await textbox.click();
52+
await textbox.type(query);
53+
await Delete(this.page);
54+
await this.locators.ksqlDb.execute.click();
55+
56+
this.setValue(`topicName-${topic}`, topicName);
57+
this.setValue(`streamName-${stream}`, streamName);
58+
}
59+
);
60+
61+
Then('KSQL DB stream created', async function(this: PlaywrightWorld) {
62+
await expectVisibility(this.locators.ksqlDb.success, "true");
63+
await expectVisibility(this.locators.ksqlDb.streamCSreated, "true");
64+
});
65+
66+
Then(
67+
'KSQL DB KSQL for table starts with: {string}, stream starts with: {string}',
68+
async function(this: PlaywrightWorld, table: string, stream: string) {
69+
70+
const tableName = generateName(table);
71+
const streamName = this.getValue<string>(`streamName-${stream}`);
72+
const query = createTableQuery(tableName, streamName);
73+
74+
await this.locators.ksqlDb.clear.click();
75+
const textbox = this.locators.ksqlDb.textField;
76+
await textbox.click();
77+
await textbox.type(query);
78+
await Delete(this.page);
79+
await this.locators.ksqlDb.execute.click();
80+
81+
this.setValue(`tableName-${table}`, tableName);
82+
}
83+
);
84+
85+
Then('KSQL DB table created', async function(this: PlaywrightWorld) {
86+
await expectVisibility(this.locators.ksqlDb.success, "true");
87+
});
88+
89+
When('KSQL DB Stream clicked', async function(this: PlaywrightWorld) {
90+
await this.locators.ksqlDb.streamsLink.click();
91+
});
92+
93+
When('KSQL DB Table clicked', async function(this: PlaywrightWorld) {
94+
await this.locators.ksqlDb.tablesLink.click();
95+
});
96+
97+
Then('KSQL DB stream starts with: {string} visible is: {string}', async function(this: PlaywrightWorld, name: string, visible: string) {
98+
const streamName = this.getValue<string>(`streamName-${name}`);
99+
await refreshPageAfterDelay(this.page);
100+
await expectVisibility(this.page.getByRole('cell', { name: streamName }), visible);
101+
});
102+
103+
Then('KSQL DB table starts with: {string} visible is: {string}', async function(this: PlaywrightWorld, name: string, visible: string) {
104+
const tableName = this.getValue<string>(`tableName-${name}`);
105+
await refreshPageAfterDelay(this.page);
106+
await expectVisibility(this.page.getByRole('cell', { name: tableName }).first(), visible);
107+
});

e2e-playwright/src/steps/ProduceMessages.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint-disable no-unused-vars */
22
import { Given, When, Then, setDefaultTimeout } from "@cucumber/cucumber";
33
import { expect } from "@playwright/test";
4-
import { expectVisibility, expectVisuallyActive } from "../services/uiHelper";
4+
import { expectVisibility, expectVisuallyActive, refreshPageAfterDelay } from "../services/uiHelper";
55
import { PlaywrightWorld } from "../support/PlaywrightWorld";
66

7-
setDefaultTimeout(60 * 1000 * 2);
7+
setDefaultTimeout(60 * 1000 * 4);
88

99
Given('Topics TopicName partitions is: {int}', async function(this: PlaywrightWorld, count: number) {
1010
await expectVisibility(this.locators.topicTopicName.partitions(count.toString()), 'true');

0 commit comments

Comments
 (0)