Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworking testsuite to use page fixtures #162

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 153 additions & 3 deletions lib/utils/fixtures.ts
Original file line number Diff line number Diff line change
@@ -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<PomFixtures>({
page: async ({ page }, use, testInfo) => {
const autPage = new ConsoleDotAuthPage(page);

Expand Down Expand Up @@ -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);
},
});
19 changes: 4 additions & 15 deletions tests/console-dot/sa.spec.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
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;

// 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);

Expand Down
63 changes: 3 additions & 60 deletions tests/rhosak/access.spec.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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');
Expand All @@ -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');

Expand Down
Loading