Skip to content

Commit

Permalink
Revert "[E2E] Fix auth file playwright and small refactor (#5065)" (#…
Browse files Browse the repository at this point in the history
…5085)

This reverts commit ce08614.

Co-authored-by: Paweł Chyła <[email protected]>
  • Loading branch information
michalina-graczyk and poulch authored Jul 31, 2024
1 parent 56e62b3 commit 8746d05
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 83 deletions.
5 changes: 0 additions & 5 deletions .changeset/pretty-masks-lay.md

This file was deleted.

2 changes: 1 addition & 1 deletion playwright/api/basics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ export class BasicApiService {
});
const loginResponseJson = await loginResponse.json();

return loginResponseJson;
return loginResponseJson as ApiResponse<TokenCreateResponse>;
}
}
1 change: 0 additions & 1 deletion playwright/pages/appPageThirdparty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class AppPage extends BasePage {
const appUrl = URL_LIST.apps + appId;

await this.page.goto(appUrl);
await this.pageHeader.waitFor({ state: "visible", timeout: 10000 });
}

async clickAppSettingsButton() {
Expand Down
1 change: 0 additions & 1 deletion playwright/pages/appsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export class AppsPage extends BasePage {

async gotoAppsList() {
await this.page.goto(URL_LIST.apps);
await this.waitForDOMToFullyLoad();
}

async typeManifestUrl(manifestUrl: string) {
Expand Down
4 changes: 3 additions & 1 deletion playwright/pages/shippingRatesPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export class ShippingRatesPage extends BasePage {
await this.assignDialogProductRow.filter({ hasText: name }).waitFor({ state: "visible" });
await this.assignProductsDialog.selectProduct(name);
await expect(this.assignProductsDialog.assignAndSaveButton).toBeEnabled();
await this.assignProductsDialog.assignAndSaveButton.click();
await this.waitForNetworkIdleAfterAction(() =>
this.assignProductsDialog.assignAndSaveButton.click(),
);
await this.assignProductsDialog.assignAndSaveButton.waitFor({
state: "hidden",
timeout: 5000,
Expand Down
6 changes: 5 additions & 1 deletion playwright/tests/apps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ test.skip("TC: SALEOR_119 User should be able to install and configure app from
page,
}) => {
await appsPage.gotoAppsList();
await appsPage.waitForDOMToFullyLoad();
await expect(appsPage.installExternalAppButton).toBeVisible();
await appsPage.installExternalAppButton.click();
await appsPage.typeManifestUrl("https://klaviyo.saleor.app/api/manifest");
Expand Down Expand Up @@ -49,7 +50,10 @@ test.skip("TC: SALEOR_119 User should be able to install and configure app from
await appsPage.expectSuccessBanner();
});
test("TC: SALEOR_120 User should be able to delete thirdparty app @e2e", async () => {
await appPage.goToExistingAppPage(APPS.appToBeDeleted.id);
await appPage.waitForNetworkIdleAfterAction(() =>
appPage.goToExistingAppPage(APPS.appToBeDeleted.id),
);
await appPage.pageHeader.waitFor({ state: "visible", timeout: 10000 });
await expect(appPage.pageHeader).toContainText("Saleor QA App");
await appPage.deleteButton.click();
await appPage.deleteAppDialog.clickDeleteButton();
Expand Down
65 changes: 19 additions & 46 deletions playwright/tests/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
import { BasicApiService } from "@api/basics";
import { permissions, USER_PERMISSION } from "@data/userPermissions";
import { APIRequestContext, expect, test as setup } from "@playwright/test";
import { permissions, USER_PERMISSION, UserPermissionType } from "@data/userPermissions";
import { APIRequestContext, test as setup } from "@playwright/test";
import fs from "fs";
import path from "path";

setup.describe.configure({ mode: "serial" });

const removeAuthFolder = () => {
const authDir = path.join(__dirname, "../.auth");

if (fs.existsSync(authDir)) {
fs.rmSync(authDir, { recursive: true });
console.log(".auth folder removed");
}
};

setup.beforeAll(() => {
removeAuthFolder();
});

const authenticateAndSaveState = async (
request: APIRequestContext,
email: string,
Expand All @@ -27,32 +14,19 @@ const authenticateAndSaveState = async (
) => {
const basicApiService = new BasicApiService(request);

const loginResponse = await basicApiService.logInUserViaApi({ email, password });
const errors = loginResponse.data.tokenCreate.errors;

if (
setup.info().title ===
"TC: SALEOR_137 Admin User should be able to deactivate other user @e2e @staff-members"
) {
await expect(errors[0].code).toEqual("INACTIVE");
} else {
await expect(errors).toEqual([]);
}
await basicApiService.logInUserViaApi({ email, password });

const loginJsonInfo = await request.storageState();

loginJsonInfo.origins = [
{
origin: process.env.BASE_URL!,
localStorage: [
{
name: "_saleorRefreshToken",
value: loginResponse.data.tokenCreate.refreshToken,
},
],
},
];

loginJsonInfo.origins.push({
origin: process.env.BASE_URL!,
localStorage: [
{
name: "_saleorRefreshToken",
value: loginJsonInfo.cookies[0].value,

Check failure on line 26 in playwright/tests/auth.setup.ts

View workflow job for this annotation

GitHub Actions / run-tests (1/2)

[setup] › auth.setup.ts:64:8 › Authenticate as staff user via API

1) [setup] › auth.setup.ts:64:8 › Authenticate as staff user via API ───────────────────────────── TypeError: Cannot read properties of undefined (reading 'value') 24 | { 25 | name: "_saleorRefreshToken", > 26 | value: loginJsonInfo.cookies[0].value, | ^ 27 | }, 28 | ], 29 | }); at authenticateAndSaveState (/home/runner/work/saleor-dashboard/saleor-dashboard/playwright/tests/auth.setup.ts:26:41) at authSetup (/home/runner/work/saleor-dashboard/saleor-dashboard/playwright/tests/auth.setup.ts:47:5) at /home/runner/work/saleor-dashboard/saleor-dashboard/playwright/tests/auth.setup.ts:65:5
},
],
});
fs.writeFileSync(filePath, JSON.stringify(loginJsonInfo, null, 2));
};
const authSetup = async (
Expand Down Expand Up @@ -83,12 +57,11 @@ setup("Authenticate as admin via API", async ({ request }) => {
);
});

setup("Authenticate permission users via API", async ({ request }) => {
for (const permission of permissions) {
const email = USER_PERMISSION[permission];
const password = process.env.E2E_PERMISSIONS_USERS_PASSWORD!;
const fileName = `${permission}.json`;
const user: UserPermissionType = USER_PERMISSION;
const password: string = process.env.E2E_PERMISSIONS_USERS_PASSWORD!;

await authSetup(request, email, password, fileName);
}
});
for (const permission of permissions) {
setup(`Authenticate as ${permission} user via API`, async ({ request }) => {
await authSetup(request, user[permission], password, `${permission}.json`);
});
}
28 changes: 10 additions & 18 deletions playwright/tests/singlePermissions/product.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,42 @@ import { CollectionsPage } from "@pages/collectionsPage";
import { HomePage } from "@pages/homePage";
import { MainMenuPage } from "@pages/mainMenuPage";
import { ProductPage } from "@pages/productPage";
import { BrowserContext, expect, test } from "@playwright/test";
import { expect, test } from "@playwright/test";

test.use({ storageState: "playwright/.auth/product.json" });

let context: BrowserContext;
let home: HomePage;
let mainMenuPage: MainMenuPage;
let productPage: ProductPage;
let categoriesPage: CategoriesPage;
let collectionsPage: CollectionsPage;

test.beforeEach(async ({ browser }) => {
context = await browser.newContext({
storageState: "playwright/.auth/product.json",
});

const page = await context.newPage();

test.beforeEach(({ page }) => {
productPage = new ProductPage(page);
home = new HomePage(page);
mainMenuPage = new MainMenuPage(page);
categoriesPage = new CategoriesPage(page);
collectionsPage = new CollectionsPage(page);

await home.goto();
await home.welcomeMessage.waitFor({ state: "visible", timeout: 30000 });
});

test.afterEach(async () => {
await context.close();
});

test("TC: SALEOR_23 User should be able to navigate to product list as a staff member using PRODUCT permission @e2e", async () => {
await home.goto();
await home.welcomeMessage.waitFor({ state: "visible", timeout: 30000 });
await mainMenuPage.openProducts();
await expect(productPage.addProductButton).toBeVisible();
await mainMenuPage.expectMenuItemsCount(6);
await productPage.expectGridToBeAttached();
});

test("TC: SALEOR_24 User should be able to navigate to collections list as a staff member using PRODUCT permission @e2e", async () => {
await home.goto();
await home.welcomeMessage.waitFor({ state: "visible", timeout: 30000 });
await mainMenuPage.openCollections();
await expect(collectionsPage.createCollectionButton).toBeVisible();
await mainMenuPage.expectMenuItemsCount(6);
await collectionsPage.expectGridToBeAttached();
});
test("TC: SALEOR_25 User should be able to navigate to categories list as a staff member using PRODUCT permission @e2e", async () => {
await home.goto();
await home.welcomeMessage.waitFor({ state: "visible", timeout: 30000 });
await mainMenuPage.openCategories();
await expect(categoriesPage.createCategoryButton).toBeVisible();
await mainMenuPage.expectMenuItemsCount(6);
Expand Down
16 changes: 7 additions & 9 deletions playwright/tests/singlePermissions/readonlyAppAccess.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { URL_LIST } from "@data/url";
import { permissions } from "@data/userPermissions";
import { AppDetailsPage } from "@pages/appDetailsPage";
import { AppPage } from "@pages/appPageThirdparty";
import { AppsPage } from "@pages/appsPage";
import { HomePage } from "@pages/homePage";
import { MainMenuPage } from "@pages/mainMenuPage";
import { expect, test } from "@playwright/test";

Expand All @@ -11,19 +11,17 @@ const permissionList = permissions.filter(item => item !== permissionToExclude);

for (const permission of permissionList) {
test.use({ storageState: `playwright/.auth/${permission}.json` });
test(`TC: SALEOR_131 User with ${permission} permissions should have readonly access to Apps @e2e @app`, async ({
test(`TC: SALEOR_131 User with ${permission} permissions should have readonly access to Apps @e2e @appp`, async ({
page,
}) => {
const home = new HomePage(page);
const mainMenuPage = new MainMenuPage(page);
const appsPage = new AppsPage(page);
const appPage = new AppPage(page);
const appDetailsPage = new AppDetailsPage(page);

await home.goto();
await home.welcomeMessage.waitFor({ state: "visible", timeout: 30000 });
await mainMenuPage.openApps();

await page.goto(URL_LIST.homePage);
await mainMenuPage.waitForNetworkIdleAfterAction(() => mainMenuPage.openApps());
await mainMenuPage.waitForDOMToFullyLoad();
await expect(appsPage.installExternalAppButton).not.toBeVisible();

const appLists = [
Expand All @@ -36,9 +34,9 @@ for (const permission of permissionList) {
await appsPage.waitForDOMToFullyLoad();
await expect(appList).toBeVisible();
}
await appsPage.installedAppRow.first().click();
await appsPage.waitForNetworkIdleAfterAction(() => appsPage.installedAppRow.first().click());
await expect(appPage.appSettingsButton).toBeVisible();
await appPage.appSettingsButton.click();
await appsPage.waitForNetworkIdleAfterAction(() => appPage.appSettingsButton.click());
await expect(appDetailsPage.appDetailsSection).toBeVisible();

const buttons = [
Expand Down

0 comments on commit 8746d05

Please sign in to comment.