diff --git a/playwright/tests/attributes.spec.ts b/playwright/tests/attributes.spec.ts index 1f0e684d936..7544f77ef77 100644 --- a/playwright/tests/attributes.spec.ts +++ b/playwright/tests/attributes.spec.ts @@ -1,20 +1,15 @@ import { ATTRIBUTES } from "@data/e2eTestData"; import { AttributesPage } from "@pages/attributesPage"; import { ConfigurationPage } from "@pages/configurationPage"; -import { BrowserContext, expect, test } from "@playwright/test"; +import { expect, test } from "@playwright/test"; import faker from "faker"; -let context: BrowserContext; +test.use({ storageState: "./playwright/.auth/admin.json" }); + let attributesPage: AttributesPage; let configurationPage: ConfigurationPage; -test.beforeEach(async ({ browser }) => { - context = await browser.newContext({ - storageState: "playwright/.auth/admin.json", - }); - - const page = await context.newPage(); - +test.beforeEach(({ page }) => { attributesPage = new AttributesPage(page); configurationPage = new ConfigurationPage(page); }); @@ -24,9 +19,12 @@ const attributeClasses = ["PRODUCT_TYPE", "PAGE_TYPE"]; for (const attr of attributeClasses) { for (const type of ATTRIBUTES.attributeTypesWithAbilityToAddValues.names) { - const uniqueSlug = `${attr}-${type.replace(" ", "-")}-${SALEOR_124_uuid}`; + const uniqueSlug = `${attr}-${type}-${SALEOR_124_uuid}`; - test(`TC: SALEOR_124 User should be able to create ${attr} ${type} attribute with ability to add values, required, public @e2e @attributes`, async () => { + test(`TC: SALEOR_124 User should be able to create ${attr} ${type} attribute with ability to add values, required, public @e2e @attributes`, async ({ + page, + }) => { + await page.context().storageState({ path: "./playwright/.auth/admin.json" }); await configurationPage.goToConfigurationView(); await configurationPage.openAttributes(); await attributesPage.clickCreateAttributeButton(); @@ -55,9 +53,12 @@ const SALEOR_125_uuid = faker.datatype.uuid(); for (const attr of attributeClasses) { for (const type of ATTRIBUTES.attributeTypesWithoutAbilityToAddValues.names) { - const uniqueSlug = `${attr}-${type.replace(" ", "-")}-${SALEOR_125_uuid}`; + const uniqueSlug = `${attr}-${type}-${SALEOR_125_uuid}`; - test(`TC: SALEOR_125 User should be able to create ${attr} ${type} attribute without ability to add values, NOT required, private @e2e @attributes`, async () => { + test(`TC: SALEOR_125 User should be able to create ${attr} ${type} attribute without ability to add values, NOT required, private @e2e @attributes`, async ({ + page, + }) => { + await page.context().storageState({ path: "./playwright/.auth/admin.json" }); await configurationPage.goToConfigurationView(); await configurationPage.openAttributes(); await attributesPage.waitForDOMToFullyLoad(); @@ -87,9 +88,12 @@ const SALEOR_126_uuid = faker.datatype.uuid(); for (const attr of attributeClasses) { for (const entity of ATTRIBUTES.attributeReferencesEntities.names) { - const uniqueSlug = `${attr}-${entity.replaceAll(" ", "-")}-${SALEOR_126_uuid}`; + const uniqueSlug = `${attr}-${entity}-${SALEOR_126_uuid}`; - test(`TC: SALEOR_126 User should be able to create ${attr} References attribute for ${entity}, NOT required, public @e2e @attributes`, async () => { + test(`TC: SALEOR_126 User should be able to create ${attr} References attribute for ${entity}, NOT required, public @e2e @attributes`, async ({ + page, + }) => { + await page.context().storageState({ path: "./playwright/.auth/admin.json" }); await configurationPage.goToConfigurationView(); await configurationPage.openAttributes(); await attributesPage.waitForDOMToFullyLoad(); @@ -97,7 +101,7 @@ for (const attr of attributeClasses) { await attributesPage.selectAttributeType(attr); await attributesPage.typeAttributeDefaultLabel(`${attr} - REFERENCES for ${entity}`); await attributesPage.fillAttributeSlug(uniqueSlug); - await attributesPage.selectAttributeInputType("Reference"); + await attributesPage.selectAttributeInputType("REFERENCE"); await attributesPage.selectAttributeEntityType(entity); await attributesPage.clickValueRequiredCheckbox(); await attributesPage.waitForNetworkIdleAfterAction(() => attributesPage.clickSaveButton()); @@ -129,7 +133,9 @@ const attributesWithValuesToBeUpdated = [productAttrWithValues, contentAttrWithV for (const attribute of attributesWithValuesToBeUpdated) { test(`TC: SALEOR_127 User should be able to update attribute values in existing ${attribute.name} attribute @e2e @attributes`, async () => { - await attributesPage.gotoExistingAttributePage(attribute.id, attribute.name); + await attributesPage.waitForNetworkIdleAfterAction(() => + attributesPage.gotoExistingAttributePage(attribute.id, attribute.name), + ); await attributesPage.clickDeleteAttrValueButton(attribute.valueToBeDeleted); await expect(attributesPage.dialog).toBeVisible(); await attributesPage.deleteAttributeValueDialog.deleteAttributeValue(); @@ -156,15 +162,20 @@ for (const attribute of attributesWithValuesToBeUpdated) { for (const attr of ATTRIBUTES.attributesToBeUpdated) { test(`TC: SALEOR_128 User should be able to edit existing ${attr.name} attribute @e2e @attributes`, async () => { - await attributesPage.gotoExistingAttributePage(attr.id, attr.name); + await attributesPage.waitForNetworkIdleAfterAction(() => + attributesPage.gotoExistingAttributePage(attr.id, attr.name), + ); await attributesPage.attributeDefaultLabelInput.clear(); await attributesPage.typeAttributeDefaultLabel(`updated ${attr.name}`); await attributesPage.expandMetadataSection(); await attributesPage.metadataAddFieldButton.click(); await attributesPage.fillMetadataFields("new key", "new value"); - await attributesPage.clickSaveButton(); + await attributesPage.waitForNetworkIdleAfterAction(() => attributesPage.clickSaveButton()); await attributesPage.expectSuccessBanner(); - await expect(attributesPage.attributeSelect).toHaveAttribute("aria-disabled", "true"); + await expect(attributesPage.attributeSelect.getByRole("button")).toHaveAttribute( + "aria-disabled", + "true", + ); await expect(attributesPage.metadataKeyInput).toHaveValue("new key"); await expect(attributesPage.metadataValueInput).toHaveValue("new value"); await expect(attributesPage.attributeDefaultLabelInput).toHaveValue(`updated ${attr.name}`);