Skip to content

Commit

Permalink
improve playwright tests with refactoring and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
prakashsvmx committed May 11, 2023
1 parent 93f010b commit 1ab1926
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 45 deletions.
10 changes: 5 additions & 5 deletions portal-ui/e2e/auth.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
import { test as setup } from "@playwright/test";
import { minioadminFile } from "./consts";
import { pagePort } from "./consts";
import { adminAccessKey, adminSecretKey, minioadminFile } from "./consts";
import { BUCKET_LIST_PAGE } from "./consts";

setup("authenticate as admin", async ({ page }) => {
// Perform authentication steps. Replace these actions with your own.
await page.goto(pagePort);
await page.goto(BUCKET_LIST_PAGE);
await page.getByPlaceholder("Username").click();
await page.getByPlaceholder("Username").fill("minioadmin");
await page.getByPlaceholder("Username").fill(adminAccessKey);
await page.getByPlaceholder("Password").click();
await page.getByPlaceholder("Password").fill("minioadmin");
await page.getByPlaceholder("Password").fill(adminSecretKey);
await page.getByRole("button", { name: "Login" }).click();

// we need to give the browser time to store the cookies
Expand Down
11 changes: 9 additions & 2 deletions portal-ui/e2e/buckets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
import { expect } from "@playwright/test";
import { generateUUID, test } from "./fixtures/baseFixture";
import { minioadminFile } from "./consts";
import { pagePort } from "./consts";
import { BUCKET_LIST_PAGE } from "./consts";

test.use({ storageState: minioadminFile });

test.beforeEach(async ({ page }) => {
await page.goto(pagePort);
await page.goto(BUCKET_LIST_PAGE);
});

test("create a new bucket", async ({ page }) => {
Expand All @@ -34,6 +34,13 @@ test("create a new bucket", async ({ page }) => {
await page.getByLabel("Bucket Name*").fill(bucketName);
await page.getByRole("button", { name: "Create Bucket" }).click();
await expect(page.locator(`#manageBucket-${bucketName}`)).toBeTruthy();
const bucketLocatorEl = `#manageBucket-${bucketName}`;
await page.locator(bucketLocatorEl).click();
await page.locator("#delete-bucket-button").click();
//confirm modal
await page.locator("#confirm-ok").click();
const listItemsCount = await page.locator(bucketLocatorEl).count();
await expect(listItemsCount).toEqual(0);
});

test("invalid bucket name", async ({ page }) => {
Expand Down
7 changes: 6 additions & 1 deletion portal-ui/e2e/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

export const minioadminFile = "playwright/.auth/admin.json";
export const pagePort = "http://localhost:9090/buckets";

export const SERVER_ENDPOINT = "http://localhost:9090";
export const BUCKET_LIST_PAGE = `${SERVER_ENDPOINT}/buckets`;

export const adminAccessKey = "minioadmin";
export const adminSecretKey = "minioadmin";
4 changes: 2 additions & 2 deletions portal-ui/e2e/groups.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import { expect } from "@playwright/test";
import { generateUUID, test } from "./fixtures/baseFixture";
import { minioadminFile } from "./consts";
import { pagePort } from "./consts";
import { BUCKET_LIST_PAGE } from "./consts";

test.use({ storageState: minioadminFile });

test.beforeEach(async ({ page }) => {
await page.goto(pagePort);
await page.goto(BUCKET_LIST_PAGE);
});

test("Add a new group", async ({ page }) => {
Expand Down
132 changes: 104 additions & 28 deletions portal-ui/e2e/lifecycle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,113 @@
import { expect } from "@playwright/test";
import { test } from "./fixtures/baseFixture";
import { minioadminFile } from "./consts";
import { pagePort } from "./consts";
import { BUCKET_LIST_PAGE } from "./consts";

test.use({ storageState: minioadminFile });

test.beforeEach(async ({ page }) => {
await page.goto(pagePort);
});
const bucketListLocPrefix = "#manageBucket";
const versionedBucketName = "versioned-bucket";
const nonVersionedBucketName = "non-versioned-bucket";

test("Test if Object Version selector is present in Lifecycle rule modal", async ({
page,
}) => {
await page.locator("#create-bucket").click();
await page.getByLabel("Bucket Name*").click();
await page.getByLabel("Bucket Name*").fill("versioned-bucket");
await page.locator("#versioned").check();
await page.getByRole("button", { name: "Create Bucket" }).click();
await page.locator("#manageBucket-versioned-bucket").click();
await page.getByRole("tab", { name: "Lifecycle" }).click();
await page.getByRole("button", { name: "Add Lifecycle Rule" }).click();
await expect(await page.locator("#object_version")).toBeTruthy();
});
test.describe("Add Lifecycle Rule Modal in bucket settings tests for object version ", () => {
test.beforeEach(async ({ page }) => {
await page.goto(BUCKET_LIST_PAGE);
});

test("Test if Object Version selector is present in Lifecycle rule modal", async ({
page,
}) => {
const bucketLocatorEl = `${bucketListLocPrefix}-${versionedBucketName}`;

await test.step(`Create bucket`, async () => {
await page.locator("#create-bucket").click();
await page.getByLabel("Bucket Name*").click();
await page.getByLabel("Bucket Name*").type(versionedBucketName);
await page.locator("#versioned").check();
await page.getByRole("button", { name: "Create Bucket" }).click();
});

await test.step("Navigate to manage bucket", async () => {
await page.locator(bucketLocatorEl).click();
await page.getByRole("tab", { name: "Lifecycle" }).click();
});

const result =
await test.step("Trigger Add Lifecycle Rule Modal and verify", async () => {
await page.getByRole("button", { name: "Add Lifecycle Rule" }).click();
return await page.locator("#object_version");
});

await expect(result).toBeTruthy();

await test.step("Close confirm Modal", async () => {
await page.locator("#close").click();
});

await test.step("List Bucket", async () => {
await page.goto(BUCKET_LIST_PAGE);
await page.locator(bucketLocatorEl).click();
});

await test.step("Click on delete bucket and confirm", async () => {
await page.locator("#delete-bucket-button").click();
await page.locator("#confirm-ok").click();
});

const bucketListItemCount =
await test.step("Verify the bucket deletion ", async () => {
const listItemsCount = await page.locator(bucketLocatorEl);
return listItemsCount.count();
});

await expect(bucketListItemCount).toEqual(0);
});

test("Test if Object Version selector is not present when bucket is not versioned", async ({
page,
}) => {
const bucketLocatorEl = `${bucketListLocPrefix}-${nonVersionedBucketName}`;

await test.step(`Create bucket`, async () => {
await page.locator("#create-bucket").click();
await page.getByLabel("Bucket Name*").click();
await page.getByLabel("Bucket Name*").type(nonVersionedBucketName);
await page.getByRole("button", { name: "Create Bucket" }).click();
});

await test.step("Navigate to manage bucket", async () => {
await page.locator(bucketLocatorEl).click();
await page.getByRole("tab", { name: "Lifecycle" }).click();
});

const result =
await test.step("Trigger Add Lifecycle Rule Modal and verify", async () => {
await page.getByRole("button", { name: "Add Lifecycle Rule" }).click();
return await page.locator("#object_version").count();
});

await expect(result).toEqual(0);

await test.step("Close confirm Modal", async () => {
await page.locator("#close").click();
});

await test.step("List bucket", async () => {
await page.goto(BUCKET_LIST_PAGE);
await page.locator(bucketLocatorEl).click();
});

await test.step("Delete bucket ", async () => {
await page.locator("#delete-bucket-button").click();
await page.locator("#confirm-ok").click();
});

const bucketListItemCount =
await test.step("Verify the bucket deletion ", async () => {
const listItemsCount = await page.locator(bucketLocatorEl);
return listItemsCount.count();
});

test("Test if Object Version selector is not present when bucket is not versioned", async ({
page,
}) => {
await page.locator("#create-bucket").click();
await page.getByLabel("Bucket Name*").click();
await page.getByLabel("Bucket Name*").fill("non-versioned-bucket");
await page.getByRole("button", { name: "Create Bucket" }).click();
await page.locator("#manageBucket-non-versioned-bucket").click();
await page.getByRole("tab", { name: "Lifecycle" }).click();
await page.getByRole("button", { name: "Add Lifecycle Rule" }).click();
await expect(await page.locator("#object_version").count()).toEqual(0);
await expect(bucketListItemCount).toEqual(0);
});
});
8 changes: 4 additions & 4 deletions portal-ui/e2e/login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { test, expect } from "@playwright/test";
import { pagePort } from "./consts";
import { adminAccessKey, adminSecretKey, BUCKET_LIST_PAGE } from "./consts";

test("Basic `minioadmin` Login", async ({ page, context }) => {
await page.goto(pagePort);
await page.goto(BUCKET_LIST_PAGE);
await page.getByPlaceholder("Username").click();
await page.getByPlaceholder("Username").fill("minioadmin");
await page.getByPlaceholder("Username").fill(adminAccessKey);
await page.getByPlaceholder("Password").click();
await page.getByPlaceholder("Password").fill("minioadmin");
await page.getByPlaceholder("Password").fill(adminSecretKey);
await page.getByRole("button", { name: "Login" }).click();
await context.storageState({ path: "storage/minioadmin.json" });
await expect(page.getByRole("main").getByText("Object Browser")).toBeTruthy();
Expand Down
6 changes: 3 additions & 3 deletions portal-ui/e2e/policies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
import { expect } from "@playwright/test";
import { generateUUID, test } from "./fixtures/baseFixture";
import { minioadminFile } from "./consts";
import { pagePort } from "./consts";
import { BUCKET_LIST_PAGE } from "./consts";

test.use({ storageState: minioadminFile });

test.beforeEach(async ({ page }) => {
await page.goto(pagePort);
await page.goto(BUCKET_LIST_PAGE);
});

test("Can create a policy", async ({ page }) => {
await page.getByRole("link", { name: "Policies Policies" }).click();
await page.getByRole("link", { name: "Policies" }).click();
await page.getByRole("button", { name: "Create Policy" }).click();
await page.getByLabel("Policy Name").click();

Expand Down

0 comments on commit 1ab1926

Please sign in to comment.