From 26ccf89d26b9287b1887285cfcdb51337d328f24 Mon Sep 17 00:00:00 2001 From: Dominik Hlavac Duran Date: Wed, 24 May 2023 17:04:46 +0200 Subject: [PATCH 1/6] Non RHOSAK test reworked with PW fixtures --- lib/utils/fixtures.ts | 57 ++++++++++++++++++++++++++++++++++-- tests/console-dot/sa.spec.ts | 19 +++--------- tests/rhosr/srs.spec.ts | 37 ++--------------------- 3 files changed, 61 insertions(+), 52 deletions(-) diff --git a/lib/utils/fixtures.ts b/lib/utils/fixtures.ts index f023d2b..c87b9f8 100644 --- a/lib/utils/fixtures.ts +++ b/lib/utils/fixtures.ts @@ -1,9 +1,20 @@ import { config } from '@lib/config'; -import { test as base, expect } from '@playwright/test'; +import {test as base, expect, Page} from '@playwright/test'; import { ConsoleDotAuthPage } from '@lib/pom/auth'; +import {ServiceRegistryPage} from "@lib/pom/serviceRegistry/serviceRegistry"; +import {AbstractPage} from "@lib/pom/abstractPage"; +import {ServiceAccountPage} from "@lib/pom/serviceAccounts/sa"; + + +// Declare the types of your fixtures. +type PomFixtures = { + page: Page; + serviceRegistryPage: ServiceRegistryPage; + serviceAccountPage: ServiceAccountPage; +}; // Extend Playwright page to start always at config.startingPage -export const test = base.extend({ +export const test = base.extend({ page: async ({ page }, use, testInfo) => { const autPage = new ConsoleDotAuthPage(page); @@ -50,5 +61,45 @@ export const test = base.extend({ console.error(logEntry); } } - } + }, + + // Fixture to create a new page and initialize the ServiceRegistryPage + serviceRegistryPage: async ({ page }, use) => { + const serviceRegistryPage = new ServiceRegistryPage(page); + // Go to list of Service Registry instances + await serviceRegistryPage.gotoThroughMenu(); + // Wait for dismiss of loading spinner + await serviceRegistryPage.waitForSelector(AbstractPage.progressBarLocatorString, { + state: 'detached', + timeout: config.serviceRegistryInstanceCreationTimeout, + }); + // Wait for presence of button for Service Registry instance creation + await serviceRegistryPage.waitForSelector('button:has-text("Create Service Registry instance")'); + // Delete all existing Service Registry instances + for (const el of await serviceRegistryPage.locator(`tr >> a`).elementHandles()) { + // Get name of existing instance + const name = await el.textContent(); + // Delete instance + await serviceRegistryPage.deleteServiceRegistryInstance(name); + } + // Use fixture in test + await use(serviceRegistryPage); + // Teardown - Delete all Service Registry instances created during tests + await serviceRegistryPage.deleteAllServiceRegistries(); + }, + + serviceAccountPage: async ({ page }, use) => { + const serviceAccountPage = new ServiceAccountPage(page); + // Go to list of Service accounts instances + await serviceAccountPage.gotoThroughMenu(); + + // Use fixture in test + await use(serviceAccountPage); + + // Teardown - Delete all Service accounts created during tests + await serviceAccountPage.deleteAllServiceAccounts(); + }, + + }); + diff --git a/tests/console-dot/sa.spec.ts b/tests/console-dot/sa.spec.ts index 3430e6d..bf9768b 100644 --- a/tests/console-dot/sa.spec.ts +++ b/tests/console-dot/sa.spec.ts @@ -1,7 +1,6 @@ import { expect } from '@playwright/test'; import { test } from '@lib/utils/fixtures'; import { config } from '@lib/config'; -import { ServiceAccountPage } from '@lib/pom/serviceAccounts/sa'; const testServiceAccountPrefix = 'test-service-account-'; let testServiceAccountName; @@ -9,26 +8,16 @@ let testServiceAccountName; // Use admin user context test.use({ storageState: config.adminAuthFile }); -test.beforeEach(async ({ page }) => { - testServiceAccountName = `${testServiceAccountPrefix}${Date.now()}`; - const serviceAccountPage = new ServiceAccountPage(page); - await serviceAccountPage.gotoThroughMenu(); -}); - -test.afterEach(async ({ page }) => { - const serviceAccountPage = new ServiceAccountPage(page); - await serviceAccountPage.deleteAllServiceAccounts(); -}); // test_5sa.py test_sa_create -test('test service account creation', async ({ page }) => { - const serviceAccountPage = new ServiceAccountPage(page); +test('test service account creation', async ({ serviceAccountPage }) => { + testServiceAccountName = `${testServiceAccountPrefix}${Date.now()}`; await serviceAccountPage.createServiceAccount(testServiceAccountName); }); // test_5sa.py test_sa_reset -test('test service account credentials reset', async ({ page }) => { - const serviceAccountPage = new ServiceAccountPage(page); +test('test service account credentials reset', async ({ serviceAccountPage }) => { + testServiceAccountName = `${testServiceAccountPrefix}${Date.now()}`; const credentials = await serviceAccountPage.createServiceAccount(testServiceAccountName); const credentials_reset = await serviceAccountPage.resetServiceAccount(testServiceAccountName); diff --git a/tests/rhosr/srs.spec.ts b/tests/rhosr/srs.spec.ts index 00a2063..619cb4b 100644 --- a/tests/rhosr/srs.spec.ts +++ b/tests/rhosr/srs.spec.ts @@ -1,7 +1,5 @@ import { test } from '@lib/utils/fixtures'; import { config } from '@lib/config'; -import { ServiceRegistryPage } from '@lib/pom/serviceRegistry/serviceRegistry'; -import { AbstractPage } from '@lib/pom/abstractPage'; // Define name of Service Registry instance for this set of tests const testInstanceName = config.instanceName; @@ -9,39 +7,10 @@ const testInstanceName = config.instanceName; // Use admin user context test.use({ storageState: config.adminAuthFile }); -// Actions run before every test -test.beforeEach(async ({ page }) => { - // Login to console - const serviceRegistryPage = new ServiceRegistryPage(page); - // Go to list of Service Registry instances - await serviceRegistryPage.gotoThroughMenu(); - // Wait for dismiss of loading spinner - await page.waitForSelector(AbstractPage.progressBarLocatorString, { - state: 'detached', - timeout: config.serviceRegistryInstanceCreationTimeout - }); - // Wait for presence of button for Service Registry instance creation - await page.waitForSelector('button:has-text("Create Service Registry instance")'); - // Delete all existing Service Registry instances - for (const el of await page.locator(`tr >> a`).elementHandles()) { - // Get name of existing instance - const name = await el.textContent(); - // Delete instance - await serviceRegistryPage.deleteServiceRegistryInstance(name); - } -}); - -// Actions run after all tests -test.afterAll(async ({ page }) => { - // Delete all Service Registry instances created during tests - const serviceRegistryPage = new ServiceRegistryPage(page); - await serviceRegistryPage.deleteAllServiceRegistries(); -}); - -// Create and delete Service Registry instance with waiting for its readiness -test('create, wait for ready and delete a Service Registry instance', async ({ page }) => { +// Test: Create and delete Service Registry instance with waiting for its readiness +test('create, wait for ready and delete a Service Registry instance', + async ({ serviceRegistryPage }) => { // Create instance - const serviceRegistryPage = new ServiceRegistryPage(page); await serviceRegistryPage.createServiceRegistryInstance(testInstanceName); // Wait for instance readiness await serviceRegistryPage.waitForServiceRegistryReady(testInstanceName); From 27dd37a925b442e87cd04f756ecadabe2095157d Mon Sep 17 00:00:00 2001 From: Dominik Hlavac Duran Date: Mon, 29 May 2023 16:39:59 +0200 Subject: [PATCH 2/6] Added fixtures for Kafka access tests --- lib/utils/fixtures.ts | 69 +++++++++++++++++++++++++++++++++++++ tests/rhosak/access.spec.ts | 63 ++------------------------------- 2 files changed, 72 insertions(+), 60 deletions(-) diff --git a/lib/utils/fixtures.ts b/lib/utils/fixtures.ts index c87b9f8..b9fc4d7 100644 --- a/lib/utils/fixtures.ts +++ b/lib/utils/fixtures.ts @@ -4,13 +4,22 @@ import { ConsoleDotAuthPage } from '@lib/pom/auth'; import {ServiceRegistryPage} from "@lib/pom/serviceRegistry/serviceRegistry"; import {AbstractPage} from "@lib/pom/abstractPage"; import {ServiceAccountPage} from "@lib/pom/serviceAccounts/sa"; +import {KafkaInstanceListPage} from "@lib/pom/streams/kafkaInstanceList"; +import {KafkaInstancePage} from "@lib/pom/streams/kafkaInstance"; +import {AccessPage} from "@lib/pom/streams/instance/access"; +const testInstanceName = config.instanceName; // Declare the types of your fixtures. type PomFixtures = { page: Page; serviceRegistryPage: ServiceRegistryPage; serviceAccountPage: ServiceAccountPage; + kafkaInstancePage: KafkaInstancePage; + kafkaInstanceListPage: KafkaInstanceListPage; + kafkaAccessPage: AccessPage; + consoleDotAuthPage: ConsoleDotAuthPage + }; // Extend Playwright page to start always at config.startingPage @@ -88,6 +97,7 @@ export const test = base.extend({ await serviceRegistryPage.deleteAllServiceRegistries(); }, + // Fixture to create a new page and initialize the ServiceAccountPage serviceAccountPage: async ({ page }, use) => { const serviceAccountPage = new ServiceAccountPage(page); // Go to list of Service accounts instances @@ -100,6 +110,65 @@ export const test = base.extend({ await serviceAccountPage.deleteAllServiceAccounts(); }, + // Fixture to create a new page and initialize the kafkaInstanceListPage which returns list of Kafka instances + kafkaInstanceListPage: async ({ page }, use) => { + const kafkaInstancesListPage = new KafkaInstanceListPage(page); + await kafkaInstancesListPage.gotoThroughMenu(); + + // Use fixture in test + await use(kafkaInstancesListPage); + }, + + // Fixture to create a new page and initialize the consoleDotAuthPage + consoleDotAuthPage: async ({ page }, use) => { + const consoleDotAuthPage = new ConsoleDotAuthPage(page); + await consoleDotAuthPage.goto(); + + // Use fixture in test + await use(consoleDotAuthPage); + }, + + // Fixture to create a new page and initialize the kafkaInstancePage and create new kafka instance if not present + kafkaInstancePage: async ({ kafkaInstanceListPage,page }, use) => { + const kafkaInstancePage = new KafkaInstancePage(page, testInstanceName); + await kafkaInstanceListPage.gotoThroughMenu(); + + if ((await kafkaInstanceListPage.noKafkaInstancesText.count()) == 1) { + await kafkaInstanceListPage.createKafkaInstance(testInstanceName); + await kafkaInstanceListPage.waitForKafkaReady(testInstanceName); + } else { + // Test instance present, nothing to do! + try { + await expect(page.getByText(testInstanceName)).toHaveCount(1, { timeout: 2000 }); + } catch (e) { + await kafkaInstanceListPage.createKafkaInstance(testInstanceName); + await kafkaInstanceListPage.waitForKafkaReady(testInstanceName); + } + } + // Use fixture in test + await use(kafkaInstancePage); + + // Teardown - Delete all kafka instances created during tests + await kafkaInstanceListPage.gotoThroughMenu(); + + try { + await kafkaInstanceListPage.deleteKafkaInstance(testInstanceName); + } catch (error) { + //Ignore exception + } + }, + + // Fixture to create a new page and initialize the AccessPage + kafkaAccessPage: async ({ kafkaInstancePage, kafkaInstanceListPage }, use) => { + const kafkaAccessPage = new AccessPage(page, testInstanceName); + await kafkaInstanceListPage.waitForKafkaReady(testInstanceName); + await kafkaInstanceListPage.gotoThroughMenu(); + await kafkaInstancePage.gotoThroughMenu(); + await kafkaAccessPage.gotoThroughMenu(); + + // Use fixture in test + await use(kafkaAccessPage); + }, }); diff --git a/tests/rhosak/access.spec.ts b/tests/rhosak/access.spec.ts index 0d74709..d2b0de4 100644 --- a/tests/rhosak/access.spec.ts +++ b/tests/rhosak/access.spec.ts @@ -1,12 +1,8 @@ import { expect } from '@playwright/test'; import { test } from '@lib/utils/fixtures'; -import { ConsoleDotAuthPage } from '@lib/pom/auth'; import { config } from '@lib/config'; -import { KafkaInstanceListPage } from '@lib/pom/streams/kafkaInstanceList'; -import { AccessPage } from '@lib/pom/streams/instance/access'; -import { KafkaInstancePage } from '@lib/pom/streams/kafkaInstance'; -const testInstanceName = config.instanceName; +test.use({ storageState: config.adminAuthFile }); test.describe('kafka instance manage access tests', () => { test.skip( @@ -16,61 +12,10 @@ test.describe('kafka instance manage access tests', () => { //'Secondary user has to be defined for this test.' ); - test.beforeEach(async ({ page }) => { - const consoleDotAuthPage = new ConsoleDotAuthPage(page); - const kafkaInstancesPage = new KafkaInstanceListPage(page); - - await consoleDotAuthPage.login(); - await kafkaInstancesPage.gotoThroughMenu(); - - if ((await kafkaInstancesPage.noKafkaInstancesText.count()) == 1) { - await kafkaInstancesPage.createKafkaInstance(testInstanceName); - await kafkaInstancesPage.waitForKafkaReady(testInstanceName); - } else { - // Test instance present, nothing to do! - try { - await expect(page.getByText(testInstanceName)).toHaveCount(1, { timeout: 2000 }); - } catch (e) { - await kafkaInstancesPage.createKafkaInstance(testInstanceName); - await kafkaInstancesPage.waitForKafkaReady(testInstanceName); - } - } - }); - - test.afterAll(async ({ page }) => { - const consoleDotAuthPage = new ConsoleDotAuthPage(page); - const kafkaInstancesPage = new KafkaInstanceListPage(page); - - try { - if ((await consoleDotAuthPage.cancelButton.first().count()) === 1) { - await consoleDotAuthPage.cancelButton.click(); - } - await consoleDotAuthPage.checkUiIsVisible(); - await consoleDotAuthPage.logout(); - } catch { - // Do nothing - } - await consoleDotAuthPage.login(); - await kafkaInstancesPage.gotoThroughMenu(); - - try { - await kafkaInstancesPage.deleteKafkaInstance(testInstanceName); - } catch (error) { - //Ignore exception - } - }); - // This test needs to run as an org admin until the new UI with refactored access dialog is released. - test('test kafka manage access permission', async ({ page }) => { - const consoleDotAuthPage = new ConsoleDotAuthPage(page); - const kafkaInstancesPage = new KafkaInstanceListPage(page); - const kafkaInstancePage = new KafkaInstancePage(page, testInstanceName); - const kafkaAccessPage = new AccessPage(page, testInstanceName); + test('test kafka manage access permission', async ({ kafkaAccessPage, + consoleDotAuthPage }) => { - await kafkaInstancesPage.waitForKafkaReady(testInstanceName); - await kafkaInstancesPage.gotoThroughMenu(); - await kafkaInstancePage.gotoThroughMenu(); - await kafkaAccessPage.gotoThroughMenu(); await kafkaAccessPage.grantManageAccess(config.username_2); const row = await kafkaAccessPage.findAccessRow(config.username_2, '', 'Kafka Instance'); @@ -79,8 +24,6 @@ test.describe('kafka instance manage access tests', () => { await consoleDotAuthPage.logout(); await consoleDotAuthPage.login(config.username_2, config.password_2); - await kafkaInstancesPage.gotoThroughMenu(); - await kafkaInstancePage.gotoThroughMenu(); await kafkaAccessPage.gotoThroughMenu(); await kafkaAccessPage.grantManageAccess('All accounts'); From 7a4cd3b3c7439d18df5a908d0c98f763266cf850 Mon Sep 17 00:00:00 2001 From: Dominik Hlavac Duran Date: Mon, 29 May 2023 16:53:11 +0200 Subject: [PATCH 3/6] Fixed page selector in POM fixtures --- lib/utils/fixtures.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/utils/fixtures.ts b/lib/utils/fixtures.ts index b9fc4d7..dd4299a 100644 --- a/lib/utils/fixtures.ts +++ b/lib/utils/fixtures.ts @@ -78,14 +78,14 @@ export const test = base.extend({ // Go to list of Service Registry instances await serviceRegistryPage.gotoThroughMenu(); // Wait for dismiss of loading spinner - await serviceRegistryPage.waitForSelector(AbstractPage.progressBarLocatorString, { + await page.waitForSelector(AbstractPage.progressBarLocatorString, { state: 'detached', timeout: config.serviceRegistryInstanceCreationTimeout, }); // Wait for presence of button for Service Registry instance creation - await serviceRegistryPage.waitForSelector('button:has-text("Create Service Registry instance")'); + await page.waitForSelector('button:has-text("Create Service Registry instance")'); // Delete all existing Service Registry instances - for (const el of await serviceRegistryPage.locator(`tr >> a`).elementHandles()) { + for (const el of await page.locator(`tr >> a`).elementHandles()) { // Get name of existing instance const name = await el.textContent(); // Delete instance @@ -115,8 +115,16 @@ export const test = base.extend({ const kafkaInstancesListPage = new KafkaInstanceListPage(page); await kafkaInstancesListPage.gotoThroughMenu(); + await page.waitForSelector(AbstractPage.progressBarLocatorString, { + state: 'detached', + timeout: config.kafkaInstanceCreationTimeout + }); + // Use fixture in test await use(kafkaInstancesListPage); + + // Teardown - Delete all Kafka instances + await kafkaInstancesListPage.deleteAllKafkas(); }, // Fixture to create a new page and initialize the consoleDotAuthPage From 24c7ae97ae48d81123501bcce5b42a4636c65a32 Mon Sep 17 00:00:00 2001 From: Dominik Hlavac Duran Date: Mon, 29 May 2023 16:59:33 +0200 Subject: [PATCH 4/6] Reworked KAS tests to use fixtures --- lib/utils/fixtures.ts | 1 - tests/rhosak/kas.spec.ts | 78 ++++++++++------------------------------ 2 files changed, 19 insertions(+), 60 deletions(-) diff --git a/lib/utils/fixtures.ts b/lib/utils/fixtures.ts index dd4299a..849d99c 100644 --- a/lib/utils/fixtures.ts +++ b/lib/utils/fixtures.ts @@ -179,4 +179,3 @@ export const test = base.extend({ await use(kafkaAccessPage); }, }); - diff --git a/tests/rhosak/kas.spec.ts b/tests/rhosak/kas.spec.ts index bce8fdc..46b788f 100644 --- a/tests/rhosak/kas.spec.ts +++ b/tests/rhosak/kas.spec.ts @@ -1,65 +1,34 @@ import { expect } from '@playwright/test'; import { test } from '@lib/utils/fixtures'; import { config } from '@lib/config'; -import { KafkaInstanceListPage } from '@lib/pom/streams/kafkaInstanceList'; import { CloudProviders } from '@lib/enums/cloudproviders'; -import { ServiceAccountPage } from '@lib/pom/serviceAccounts/sa'; -import { AbstractPage } from '@lib/pom/abstractPage'; const testInstanceName = config.instanceName; // Use admin user context test.use({ storageState: config.adminAuthFile }); -test.beforeEach(async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - - await kafkaInstancesPage.gotoThroughMenu(); - - await page.waitForSelector(AbstractPage.progressBarLocatorString, { - state: 'detached', - timeout: config.kafkaInstanceCreationTimeout - }); - - for (const el of await page.locator(`tr >> a`).elementHandles()) { - const name = await el.textContent(); - await kafkaInstancesPage.deleteKafkaInstance(name); - } -}); - -test.afterAll(async ({ page }) => { - const serviceAccountPage = new ServiceAccountPage(page); - const kafkaInstancesPage = new KafkaInstanceListPage(page); - - await serviceAccountPage.deleteAllServiceAccounts(); - await kafkaInstancesPage.deleteAllKafkas(); -}); - // test_3kas.py test_kas_kafka_check_does_not_exist -test('check there are no Kafka instances', async ({ page }) => { +test('check there are no Kafka instances', async ({ kafkaInstanceListPage ,page}) => { await expect(page.getByText('No Kafka instances')).toHaveCount(1); }); // test_3kas.py test_kas_kafka_create_dont_wait_for_ready_delete_wait_for_delete -test('create and delete a Kafka instance', async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - await kafkaInstancesPage.gotoThroughMenu(); - await kafkaInstancesPage.createKafkaInstance(testInstanceName); - await kafkaInstancesPage.deleteKafkaInstance(testInstanceName); +test('create and delete a Kafka instance', async ({ kafkaInstanceListPage }) => { + await kafkaInstanceListPage.createKafkaInstance(testInstanceName); + await kafkaInstanceListPage.deleteKafkaInstance(testInstanceName); }); // test_3kas.py test_kas_kafka_create_wait_for_ready_delete_wait_for_delete -test('create, wait for ready and delete a Kafka instance', async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - await kafkaInstancesPage.gotoThroughMenu(); - await kafkaInstancesPage.createKafkaInstance(testInstanceName, false); - await kafkaInstancesPage.waitForKafkaReady(testInstanceName); - await kafkaInstancesPage.deleteKafkaInstance(testInstanceName); +test('create, wait for ready and delete a Kafka instance', async ({ kafkaInstanceListPage }) => { + await kafkaInstanceListPage.createKafkaInstance(testInstanceName, false); + await kafkaInstanceListPage.waitForKafkaReady(testInstanceName); + await kafkaInstanceListPage.deleteKafkaInstance(testInstanceName); }); // test_3kas.py test_kas_kafka_standard_kafka_test_slider // TODO: check if this is actually what the test is really doing -test('test Kafka creation units slider', async ({ page }) => { +test('test Kafka creation units slider', async ({ kafkaInstanceListPage,page }) => { await page.getByText('Create Kafka instance').click(); await expect(page.getByText('Create a Kafka instance')).toHaveCount(1); @@ -89,11 +58,8 @@ const filterByStatus = async function (page, status) { }; // test_3kas.py test_kas_kafka_filter_by_status -test('test Kafka list filtered by status', async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - await kafkaInstancesPage.gotoThroughMenu(); - - await kafkaInstancesPage.createKafkaInstance(testInstanceName); +test('test Kafka list filtered by status', async ({ page, kafkaInstanceListPage }) => { + await kafkaInstanceListPage.createKafkaInstance(testInstanceName); await expect(page.getByText(testInstanceName)).toBeVisible(); await filterByStatus(page, 'Suspended'); @@ -104,12 +70,12 @@ test('test Kafka list filtered by status', async ({ page }) => { // Reset the filter await resetFilter(page); - await kafkaInstancesPage.waitForKafkaReady(testInstanceName); + await kafkaInstanceListPage.waitForKafkaReady(testInstanceName); await filterByStatus(page, 'Ready'); await expect(page.getByText(testInstanceName)).toBeTruthy(); - await kafkaInstancesPage.deleteKafkaInstance(testInstanceName, false); + await kafkaInstanceListPage.deleteKafkaInstance(testInstanceName, false); // await for the kafka instance to be deleted await expect(page.getByText(`${testInstanceName}`, { exact: true })).toHaveCount(0, { @@ -119,13 +85,9 @@ test('test Kafka list filtered by status', async ({ page }) => { // test_3kas.py test_try_to_create_kafka_instance_with_same_name // NOTE: this test is expected to be pretty fragile as it needs that the current instance is in "early" `Creating` status -test('test fail to create Kafka instance with the same name', async ({ page }) => { +test('test fail to create Kafka instance with the same name', async ({ page, kafkaInstanceListPage }) => { test.skip(true, 'Need a different account'); - - const kafkaInstancesPage = new KafkaInstanceListPage(page); - await kafkaInstancesPage.gotoThroughMenu(); - - await kafkaInstancesPage.createKafkaInstance(testInstanceName, false); + await kafkaInstanceListPage.createKafkaInstance(testInstanceName, false); await page.getByText('Create Kafka instance').click(); await expect(page.getByText('Create a Kafka instance')).toHaveCount(1); @@ -134,12 +96,10 @@ test('test fail to create Kafka instance with the same name', async ({ page }) = await expect(page.getByText(`${testInstanceName} already exists. Please try a different name.`)).toHaveCount(1); await page.locator('#modalCreateKafka > button').click(); - await kafkaInstancesPage.deleteKafkaInstance(testInstanceName); + await kafkaInstanceListPage.deleteKafkaInstance(testInstanceName); }); -test('create GCP Kafka instance', async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - await kafkaInstancesPage.gotoThroughMenu(); - await kafkaInstancesPage.createKafkaInstance(testInstanceName, false, null, CloudProviders.GCP); - await kafkaInstancesPage.deleteKafkaInstance(testInstanceName); +test('create GCP Kafka instance', async ({ page , kafkaInstanceListPage}) => { + await kafkaInstanceListPage.createKafkaInstance(testInstanceName, false, CloudProviders.GCP); + await kafkaInstanceListPage.deleteKafkaInstance(testInstanceName); }); From a0943ee79d3da7619355a04ce1842091b62b218b Mon Sep 17 00:00:00 2001 From: Dominik Hlavac Duran Date: Tue, 30 May 2023 12:32:46 +0200 Subject: [PATCH 5/6] Fixed KAS test navigation with fixtures --- tests/rhosak/kas.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/rhosak/kas.spec.ts b/tests/rhosak/kas.spec.ts index 46b788f..8f79cfa 100644 --- a/tests/rhosak/kas.spec.ts +++ b/tests/rhosak/kas.spec.ts @@ -10,6 +10,7 @@ test.use({ storageState: config.adminAuthFile }); // test_3kas.py test_kas_kafka_check_does_not_exist test('check there are no Kafka instances', async ({ kafkaInstanceListPage ,page}) => { + await kafkaInstanceListPage; await expect(page.getByText('No Kafka instances')).toHaveCount(1); }); @@ -29,6 +30,7 @@ test('create, wait for ready and delete a Kafka instance', async ({ kafkaInstanc // test_3kas.py test_kas_kafka_standard_kafka_test_slider // TODO: check if this is actually what the test is really doing test('test Kafka creation units slider', async ({ kafkaInstanceListPage,page }) => { + await kafkaInstanceListPage; await page.getByText('Create Kafka instance').click(); await expect(page.getByText('Create a Kafka instance')).toHaveCount(1); @@ -99,7 +101,7 @@ test('test fail to create Kafka instance with the same name', async ({ page, kaf await kafkaInstanceListPage.deleteKafkaInstance(testInstanceName); }); -test('create GCP Kafka instance', async ({ page , kafkaInstanceListPage}) => { +test('create GCP Kafka instance', async ({ kafkaInstanceListPage}) => { await kafkaInstanceListPage.createKafkaInstance(testInstanceName, false, CloudProviders.GCP); await kafkaInstanceListPage.deleteKafkaInstance(testInstanceName); }); From b190516b4d4a6961d72630a48f768ced9959fc1e Mon Sep 17 00:00:00 2001 From: Dominik Hlavac Duran Date: Tue, 30 May 2023 12:59:50 +0200 Subject: [PATCH 6/6] Reworked KAS instance tests to use POM fixtures --- lib/utils/fixtures.ts | 31 +++- tests/rhosak/kas_with_instance.spec.ts | 199 ++++++++----------------- 2 files changed, 86 insertions(+), 144 deletions(-) diff --git a/lib/utils/fixtures.ts b/lib/utils/fixtures.ts index 849d99c..deb0619 100644 --- a/lib/utils/fixtures.ts +++ b/lib/utils/fixtures.ts @@ -7,6 +7,8 @@ import {ServiceAccountPage} from "@lib/pom/serviceAccounts/sa"; import {KafkaInstanceListPage} from "@lib/pom/streams/kafkaInstanceList"; import {KafkaInstancePage} from "@lib/pom/streams/kafkaInstance"; import {AccessPage} from "@lib/pom/streams/instance/access"; +import {ConsumerGroupsPage} from "@lib/pom/streams/instance/consumerGroups"; +import {TopicListPage} from "@lib/pom/streams/instance/topicList"; const testInstanceName = config.instanceName; @@ -18,8 +20,9 @@ type PomFixtures = { kafkaInstancePage: KafkaInstancePage; kafkaInstanceListPage: KafkaInstanceListPage; kafkaAccessPage: AccessPage; - consoleDotAuthPage: ConsoleDotAuthPage - + consoleDotAuthPage: ConsoleDotAuthPage; + consumerGroupsPage: ConsumerGroupsPage; + kafkaTopicPage: TopicListPage; }; // Extend Playwright page to start always at config.startingPage @@ -171,11 +174,31 @@ export const test = base.extend({ kafkaAccessPage: async ({ kafkaInstancePage, kafkaInstanceListPage }, use) => { const kafkaAccessPage = new AccessPage(page, testInstanceName); await kafkaInstanceListPage.waitForKafkaReady(testInstanceName); - await kafkaInstanceListPage.gotoThroughMenu(); - await kafkaInstancePage.gotoThroughMenu(); + await kafkaInstancePage; await kafkaAccessPage.gotoThroughMenu(); // Use fixture in test await use(kafkaAccessPage); }, + + // Fixture to create a new page and initialize the Kafkas's Consumer group page + consumerGroupsPage: async ({ kafkaInstancePage}, use) => { + const consumerGroupsPage = new ConsumerGroupsPage(page, testInstanceName); + await kafkaInstancePage; + + await consumerGroupsPage.gotoThroughMenu(); + + // Use fixture in test + await use(consumerGroupsPage); + }, + + // Fixture to create a new page and initialize the consoleDotAuthPage + kafkaTopicPage: async ({ kafkaInstancePage }, use) => { + const topicPage = new TopicListPage(page, testInstanceName); + await kafkaInstancePage; + await topicPage.gotoThroughMenu(); + + // Use fixture in test + await use(topicPage); + }, }); diff --git a/tests/rhosak/kas_with_instance.spec.ts b/tests/rhosak/kas_with_instance.spec.ts index d72e760..0256248 100644 --- a/tests/rhosak/kas_with_instance.spec.ts +++ b/tests/rhosak/kas_with_instance.spec.ts @@ -3,10 +3,7 @@ import { test } from '@lib/utils/fixtures'; import { config } from '@lib/config'; import { KafkaInstanceListPage } from '@lib/pom/streams/kafkaInstanceList'; import { TopicListPage } from '@lib/pom/streams/instance/topicList'; -import { ServiceAccountPage } from '@lib/pom/serviceAccounts/sa'; -import { AccessPage } from '@lib/pom/streams/instance/access'; import { AbstractPage } from '@lib/pom/abstractPage'; -import { ConsumerGroupsPage } from '@lib/pom/streams/instance/consumerGroups'; import { PropertiesPage } from '@lib/pom/streams/instance/topic/properties'; import { KafkaInstancePage } from '@lib/pom/streams/kafkaInstance'; import { TopicPage } from '@lib/pom/streams/instance/topic'; @@ -19,64 +16,23 @@ const testTopicName = `${testTopicNamePrefix}${config.sessionID}`; // Use admin user context test.use({ storageState: config.adminAuthFile }); -test.beforeEach(async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - - await kafkaInstancesPage.gotoThroughMenu(); - - if ((await kafkaInstancesPage.noKafkaInstancesText.count()) == 1) { - await kafkaInstancesPage.createKafkaInstance(testInstanceName); - await kafkaInstancesPage.waitForKafkaReady(testInstanceName); - } else { - // Test instance present, nothing to do! - try { - await expect(page.getByText(testInstanceName)).toHaveCount(1, { timeout: 2000 }); - } catch (e) { - await kafkaInstancesPage.createKafkaInstance(testInstanceName); - await kafkaInstancesPage.waitForKafkaReady(testInstanceName); - } - } -}); - -test.afterEach(async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - const kafkaInstancePage = new KafkaInstancePage(page, testInstanceName); - - await kafkaInstancesPage.gotoThroughMenu(); - await kafkaInstancePage.gotoThroughMenu(); +test.afterEach(async ({ page, kafkaInstancePage }) => { + await kafkaInstancePage; const topicPage = new TopicListPage(page, testInstanceName); await topicPage.deleteAllKafkaTopics(); - - await kafkaInstancesPage.gotoThroughMenu(); -}); - -test.afterAll(async ({ page }) => { - const serviceAccountPage = new ServiceAccountPage(page); - const kafkaInstancesPage = new KafkaInstanceListPage(page); - - await serviceAccountPage.deleteAllServiceAccounts(); - await kafkaInstancesPage.deleteAllKafkas(); }); // test_3kas.py test_number_of_shown_kafka_instances // & test_4kafka.py test_kafka_consumer_groups_empty & test_kafka_access_default -test('test shown Kafka instances and check access and consumer groups default', async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - const kafkaInstancePage = new KafkaInstancePage(page, testInstanceName); - const consumerGroupsPage = new ConsumerGroupsPage(page, testInstanceName); - const accessPage = new AccessPage(page, testInstanceName); - - await kafkaInstancesPage.gotoThroughMenu(); - await kafkaInstancePage.gotoThroughMenu(); - await consumerGroupsPage.gotoThroughMenu(); +test('test shown Kafka instances and check access and consumer groups default', async ({ page, + kafkaAccessPage, + consumerGroupsPage}) => { await consumerGroupsPage.waitForEmptyConsumerGroupsTable(); await expect(consumerGroupsPage.consumerGroupHeading).toHaveCount(1); - await kafkaInstancesPage.gotoThroughMenu(); - await kafkaInstancePage.gotoThroughMenu(); - await accessPage.gotoThroughMenu(); + await kafkaAccessPage; await expect(page.locator('th', { hasText: 'Account' })).toHaveCount(1); await expect(page.locator('th', { hasText: 'Permission' })).toHaveCount(1); await expect(page.locator('th', { hasText: 'Resource' })).toHaveCount(1); @@ -111,9 +67,9 @@ const filterByName = async function (page, name, skipClick = false) { }; // test_3kas.py test_kas_kafka_filter_by_name -test('test instances can be filtered by name', async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - await kafkaInstancesPage.gotoThroughMenu(); +test('test instances can be filtered by name', async ({ page, + kafkaInstanceListPage }) => { + await kafkaInstanceListPage; await filterByName(page, 'test'); await expect(page.getByText(testInstanceName)).toBeTruthy(); @@ -147,9 +103,9 @@ const filterByOwner = async function (page, name, skipClick = false) { }; // test_3kas.py test_kas_kafka_filter_by_owner -test('test instances can be filtered by owner', async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - await kafkaInstancesPage.gotoThroughMenu(); +test('test instances can be filtered by owner', async ({ page, + kafkaInstanceListPage }) => { + await kafkaInstanceListPage; await filterByOwner(page, config.adminUsername.substring(0, 5)); await expect(page.getByText(testInstanceName)).toBeTruthy(); @@ -165,9 +121,8 @@ test('test instances can be filtered by owner', async ({ page }) => { // test_3kas.py test_kas_kafka_filter_by_region // TODO: region can only be ordered, not filtered ??? -test('test instances can be filtered by region', async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - await kafkaInstancesPage.gotoThroughMenu(); +test('test instances can be filtered by region', async ({ page,kafkaInstanceListPage }) => { + await kafkaInstanceListPage; await page.locator('button', { hasText: 'Region' }).click(); await expect(page.getByText(testInstanceName)).toBeTruthy(); @@ -175,10 +130,9 @@ test('test instances can be filtered by region', async ({ page }) => { // test_3kas.py test_kas_kafka_filter_by_cloud_provider // TODO: cloud provider can only be ordered, not filtered ??? -test('test instances can be filtered by cloud provider', async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - await kafkaInstancesPage.gotoThroughMenu(); - +test('test instances can be filtered by cloud provider', async ({ page, + kafkaInstanceListPage}) => { + await kafkaInstanceListPage; await page.locator('button', { hasText: 'Cloud provider' }).click(); await expect(page.getByText(testInstanceName)).toBeTruthy(); }); @@ -194,33 +148,31 @@ test('test instance details on row click', async ({ page }) => { }); // test_3kas.py test_kas_kafka_view_details_by_menu_click_panel_opened -test('test instance details on menu click', async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - await kafkaInstancesPage.gotoThroughMenu(); - await kafkaInstancesPage.showElementActions(testInstanceName); +test('test instance details on menu click', async ({ page,kafkaInstanceListPage}) => { + await kafkaInstanceListPage; + await kafkaInstanceListPage.showElementActions(testInstanceName); - await kafkaInstancesPage.detailsButton.click(); + await kafkaInstanceListPage.detailsButton.click(); await expect(page.locator('h1', { hasText: `${testInstanceName}` })).toHaveCount(1); - await expect(kafkaInstancesPage.detailsButton).toHaveCount(1); + await expect(kafkaInstanceListPage.detailsButton).toHaveCount(1); await page.locator('button[aria-label="Close drawer panel"]').click(); }); // test_3kas.py test_kas_kafka_view_details_by_connection_menu_click_panel_opened // ... and more ... -test('test instance quick options', async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - await kafkaInstancesPage.gotoThroughMenu(); - await kafkaInstancesPage.showElementActions(testInstanceName); +test('test instance quick options', async ({ page,kafkaInstanceListPage}) => { + await kafkaInstanceListPage; + await kafkaInstanceListPage.showElementActions(testInstanceName); await page.locator('button', { hasText: 'Connection' }).click(); - await expect(kafkaInstancesPage.bootstrapField).toHaveCount(1); + await expect(kafkaInstanceListPage.bootstrapField).toHaveCount(1); await page.locator('button[aria-label="Close drawer panel"]').click(); - await kafkaInstancesPage.showElementActions(testInstanceName); + await kafkaInstanceListPage.showElementActions(testInstanceName); await page.getByRole('menuitem', { name: 'Change owner' }).click(); await expect(page.getByText('Current owner')).toHaveCount(1); @@ -230,13 +182,9 @@ test('test instance quick options', async ({ page }) => { }); // test_4kas.py test_kafka_dashboard_opened & test_kafka_dashboard_default -test('test instance dashboard on instance name click', async ({ page }) => { - const kafkaInstancesListPage = new KafkaInstanceListPage(page); - const kafkaInstancePage = new KafkaInstancePage(page, testInstanceName); - - await kafkaInstancesListPage.gotoThroughMenu(); - await kafkaInstancePage.gotoThroughMenu(); - +test('test instance dashboard on instance name click', async ({ page, + kafkaInstancePage}) => { + await kafkaInstancePage; await expect(kafkaInstancePage.kafkaInstanceHeading).toHaveCount(1); await expect(kafkaInstancePage.kafkaTabNavDashboard).toHaveCount(1); @@ -247,36 +195,25 @@ test('test instance dashboard on instance name click', async ({ page }) => { }); // test_4kafka.py test_kafka_topic_check_does_not_exist & test_kafka_topics_opened & test_kafka_topic_create -test('check Topic does not exist and create and delete', async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - const kafkaInstancePage = new KafkaInstancePage(page, testInstanceName); - const topicPage = new TopicListPage(page, testInstanceName); - await kafkaInstancesPage.gotoThroughMenu(); - await kafkaInstancePage.gotoThroughMenu(); - await topicPage.gotoThroughMenu(); - +test('check Topic does not exist and create and delete', async ({ page, + kafkaTopicPage}) => { + await kafkaTopicPage; await expect(page.locator('h2', { hasText: 'No topics' })).toBeVisible(); - await expect(topicPage.createTopicButton).toBeVisible(); + await expect(kafkaTopicPage.createTopicButton).toBeVisible(); // expecting not to find topic row await expect(page.locator('td', { hasText: `${testTopicName}` })).toHaveCount(0); - await topicPage.gotoThroughMenu(); - await topicPage.createKafkaTopic(testTopicName, true); - await topicPage.deleteKafkaTopic(testTopicName); + await kafkaTopicPage; + await kafkaTopicPage.createKafkaTopic(testTopicName, true); + await kafkaTopicPage.deleteKafkaTopic(testTopicName); }); // test_4kafka.py test_kafka_try_create_topic_with_same_name -test('test kafka try create topic with same name', async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - const kafkaInstancePage = new KafkaInstancePage(page, testInstanceName); - const topicPage = new TopicListPage(page, testInstanceName); - await kafkaInstancesPage.gotoThroughMenu(); - await kafkaInstancePage.gotoThroughMenu(); - - await topicPage.gotoThroughMenu(); - await topicPage.createKafkaTopic(testTopicName, true); +test('test kafka try create topic with same name', async ({ page, + kafkaTopicPage}) => { + await kafkaTopicPage.createKafkaTopic(testTopicName, true); await expect(page.locator('tr', { hasText: `${testTopicName}` })).toHaveCount(1); - await topicPage.createTopicButton.click(); + await kafkaTopicPage.createTopicButton.click(); await page.getByPlaceholder('Enter topic name').fill(testTopicName); // https://issues.redhat.com/browse/MGDX-386 await page.getByPlaceholder('Enter topic name').click(); @@ -285,18 +222,11 @@ test('test kafka try create topic with same name', async ({ page }) => { await expect(page.getByText('already exists. Try a different name')).toBeVisible(); }); -test('create Topic with properties different than default', async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - const kafkaInstancePage = new KafkaInstancePage(page, testInstanceName); - const topicListPage = new TopicListPage(page, testInstanceName); - const topicPage = new TopicPage(page, testInstanceName, testTopicName); +test('create Topic with properties different than default', async ({ page, + kafkaTopicPage }) => { const propertiesPage = new PropertiesPage(page, testInstanceName, testTopicName); - await kafkaInstancesPage.gotoThroughMenu(); - await kafkaInstancePage.gotoThroughMenu(); - await topicListPage.gotoThroughMenu(); - - await topicListPage.createKafkaTopic(testTopicName, false); - await topicPage.gotoThroughMenu(); + await kafkaTopicPage.createKafkaTopic(testTopicName, false); + await kafkaTopicPage; await propertiesPage.gotoThroughMenu(); // Checking phase @@ -316,17 +246,10 @@ test('create Topic with properties different than default', async ({ page }) => }); // test_4kafka.py test_edit_topic_properties_after_creation -test('edit topic properties after creation', async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - const kafkaInstancePage = new KafkaInstancePage(page, testInstanceName); - const topicListPage = new TopicListPage(page, testInstanceName); - const topicPage = new TopicPage(page, testInstanceName, testTopicName); +test('edit topic properties after creation', async ({ page, + kafkaTopicPage}) => { const propertiesPage = new PropertiesPage(page, testInstanceName, testTopicName); - await kafkaInstancesPage.gotoThroughMenu(); - await kafkaInstancePage.gotoThroughMenu(); - await topicListPage.gotoThroughMenu(); - - await topicListPage.createKafkaTopic(testTopicName, true); + await kafkaTopicPage.createKafkaTopic(testTopicName, false); const row = page.locator('tr', { hasText: testTopicName }); await row.locator(AbstractPage.actionsLocatorString).click(); @@ -375,10 +298,10 @@ test('edit topic properties after creation', async ({ page }) => { await page.waitForSelector(AbstractPage.progressBarLocatorString, { state: 'detached' }); - await expect(topicListPage.createTopicButton).toHaveCount(1); + await expect(kafkaTopicPage.createTopicButton).toHaveCount(1); // Here we begin the comparison - await topicPage.gotoThroughMenu(); + await kafkaTopicPage.gotoThroughMenu(); await propertiesPage.gotoThroughMenu(); const numPartitionsAfter: string = await propertiesPage.partitionsInput.getAttribute('value'); @@ -398,24 +321,20 @@ test('edit topic properties after creation', async ({ page }) => { await propertiesPage.deleteKafkaTopic(); }); -test('test kafka dashboard with multiple topics and partitions', async ({ page }) => { - const kafkaInstancesPage = new KafkaInstanceListPage(page); - const kafkaInstancePage = new KafkaInstancePage(page, testInstanceName); - const topicListPage = new TopicListPage(page, testInstanceName); - - await kafkaInstancesPage.gotoThroughMenu(); - await kafkaInstancePage.gotoThroughMenu(); +test('test kafka dashboard with multiple topics and partitions', async ({ page, + kafkaTopicPage, + kafkaInstancePage}) => { await kafkaInstancePage.setPartitionLimit(); // Create 3 topics and reach topic partitions limit-1 - await topicListPage.gotoThroughMenu(); - await topicListPage.createKafkaTopic( + await kafkaTopicPage.gotoThroughMenu(); + await kafkaTopicPage.createKafkaTopic( testTopicNamePrefix + Date.now(), false, kafkaInstancePage.maxTopicPartitionsNumber - 3 ); - await topicListPage.createKafkaTopic(testTopicNamePrefix + Date.now(), true); - await topicListPage.createKafkaTopic(testTopicNamePrefix + Date.now(), true); + await kafkaTopicPage.createKafkaTopic(testTopicNamePrefix + Date.now(), true); + await kafkaTopicPage.createKafkaTopic(testTopicNamePrefix + Date.now(), true); await kafkaInstancePage.kafkaTabNavDashboard.click(); // Metrics are not live, wait for update @@ -427,8 +346,8 @@ test('test kafka dashboard with multiple topics and partitions', async ({ page } await expect(kafkaInstancePage.nearTopicPartitionsLimit).toBeVisible({ timeout: 500 }); // Create another topic to reach partition limit - await topicListPage.gotoThroughMenu(); - await topicListPage.createKafkaTopic(testTopicNamePrefix + Date.now(), true); + await kafkaTopicPage.gotoThroughMenu(); + await kafkaTopicPage.createKafkaTopic(testTopicNamePrefix + Date.now(), true); await kafkaInstancePage.kafkaTabNavDashboard.click(); // Metrics are not live, wait for update