diff --git a/lib/utils/fixtures.ts b/lib/utils/fixtures.ts index f023d2b..deb0619 100644 --- a/lib/utils/fixtures.ts +++ b/lib/utils/fixtures.ts @@ -1,9 +1,32 @@ 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"; +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; + +// Declare the types of your fixtures. +type PomFixtures = { + page: Page; + serviceRegistryPage: ServiceRegistryPage; + serviceAccountPage: ServiceAccountPage; + kafkaInstancePage: KafkaInstancePage; + kafkaInstanceListPage: KafkaInstanceListPage; + kafkaAccessPage: AccessPage; + consoleDotAuthPage: ConsoleDotAuthPage; + consumerGroupsPage: ConsumerGroupsPage; + kafkaTopicPage: TopicListPage; +}; // 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 +73,132 @@ 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 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); + } + // Use fixture in test + await use(serviceRegistryPage); + // Teardown - Delete all Service Registry instances created during tests + 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 + await serviceAccountPage.gotoThroughMenu(); + + // Use fixture in test + await use(serviceAccountPage); + + // Teardown - Delete all Service accounts created during tests + 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(); + + 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 + 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 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/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/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'); diff --git a/tests/rhosak/kas.spec.ts b/tests/rhosak/kas.spec.ts index bce8fdc..8f79cfa 100644 --- a/tests/rhosak/kas.spec.ts +++ b/tests/rhosak/kas.spec.ts @@ -1,65 +1,36 @@ 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 kafkaInstanceListPage; 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 kafkaInstanceListPage; await page.getByText('Create Kafka instance').click(); await expect(page.getByText('Create a Kafka instance')).toHaveCount(1); @@ -89,11 +60,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 +72,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 +87,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 +98,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 ({ kafkaInstanceListPage}) => { + await kafkaInstanceListPage.createKafkaInstance(testInstanceName, false, CloudProviders.GCP); + await kafkaInstanceListPage.deleteKafkaInstance(testInstanceName); }); 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 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);