Skip to content

Commit

Permalink
Migrate attributes critical tests to playwright (#4383)
Browse files Browse the repository at this point in the history
* attributes critical test migrated to playwright

* changeset added

* Update playwright/tests/attributes.spec.ts

Co-authored-by: Paweł Chyła <chyla1988@gmail.com>

* Update playwright/tests/attributes.spec.ts

Co-authored-by: Paweł Chyła <chyla1988@gmail.com>

---------

Co-authored-by: Paweł Chyła <chyla1988@gmail.com>
  • Loading branch information
wojteknowacki and poulch authored Nov 7, 2023
1 parent 85770f6 commit 308e579
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-points-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

Attributes critical test migrated to playwright
8 changes: 3 additions & 5 deletions cypress/e2e/checkout/purchaseWithProductTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import {
getShippingMethodIdFromCheckout,
updateShippingInCheckout,
} from "../../support/api/utils/ordersUtils";
import {
createDigitalAndPhysicalProductWithNewDataAndDefaultChannel,
} from "../../support/api/utils/products/productsUtils";
import { createDigitalAndPhysicalProductWithNewDataAndDefaultChannel } from "../../support/api/utils/products/productsUtils";

describe("As an unlogged customer I want to order physical and digital products", () => {
const startsWith = `CyPurchaseByType`;
Expand Down Expand Up @@ -60,7 +58,7 @@ describe("As an unlogged customer I want to order physical and digital products"
});

it(
"should purchase digital product as unlogged customer. TC: SALEOR_0402",
"should purchase digital product as unlogged customer. TC: SALEOR_0402 - should not be migrated to playwright",
{ tags: ["@checkout", "@allEnv", "@stable", "@oldRelease", "@critical"] },
() => {
createAndCompleteCheckoutWithoutShipping({
Expand All @@ -84,7 +82,7 @@ describe("As an unlogged customer I want to order physical and digital products"
);

it(
"should purchase physical product as unlogged customer. TC: SALEOR_0403",
"should purchase physical product as unlogged customer. TC: SALEOR_0403 should not be migrated to playwright",
{ tags: ["@checkout", "@allEnv", "@stable", "@oldRelease", "@critical"] },
() => {
createWaitingForCaptureOrder({
Expand Down
15 changes: 4 additions & 11 deletions cypress/e2e/configuration/attributes/createProductAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@

import faker from "faker";

import {
ATTRIBUTES_DETAILS,
} from "../../../elements/attribute/attributes_details";
import { ATTRIBUTES_DETAILS } from "../../../elements/attribute/attributes_details";
import { ATTRIBUTES_LIST } from "../../../elements/attribute/attributes_list";
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
import {
attributeDetailsUrl,
urlList,
} from "../../../fixtures/urlList";
import { attributeDetailsUrl, urlList } from "../../../fixtures/urlList";
import {
createAttribute,
getAttribute,
} from "../../../support/api/requests/Attribute";
import {
expectCorrectDataInAttribute,
} from "../../../support/api/utils/attributes/checkAttributeData";
import { expectCorrectDataInAttribute } from "../../../support/api/utils/attributes/checkAttributeData";
import {
createAttributeWithInputType,
fillUpAttributeNameAndCode,
Expand All @@ -27,7 +20,7 @@ import {
describe("As an admin I want to create product attribute", () => {
const startsWith = "AttrCreate" + Date.now();
const attributesTypes = [
{ type: "DROPDOWN", testCase: "SALEOR_0501" },
{ type: "DROPDOWN", testCase: "SALEOR_0501" }, // migration in progress - to delete when done
{ type: "MULTISELECT", testCase: "SALEOR_0502" },
{ type: "RICH_TEXT", testCase: "SALEOR_0504" },
{ type: "BOOLEAN", testCase: "SALEOR_0505" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe("As a staff user I want to create shipping zone and rate", () => {
});

it(
"should be able to create price based shipping method and assign it to checkout. TC: SALEOR_0803",
"should be able to create price based shipping method and assign it to checkout. TC: SALEOR_0803 should not be migrated to playwright",
{ tags: ["@shipping", "@allEnv", "@stable", "@oldRelease", "@critical"] },
() => {
const shippingName = `${startsWith}${faker.datatype.number()}`;
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/homePage/homePageAnalitics.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe("As an admin I want to see correct information on dashboard home page",
});

it(
"should display correct information on dashboard home page. SALEOR_2004",
"should display correct information on dashboard home page. SALEOR_2004 - migration in progress - to delete when done",
{ tags: ["@homePage", "@allEnv", "@critical"] },
() => {
cy.visit(urlList.homePage);
Expand Down
10 changes: 3 additions & 7 deletions cypress/e2e/products/productsList/columnPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
/// <reference types="../../../support"/>

import { SHARED_ELEMENTS } from "../../../elements";
import {
PRODUCTS_LIST,
} from "../../../elements/catalog/products/products-list";
import { PRODUCTS_LIST } from "../../../elements/catalog/products/products-list";
import { LOCAL_STORAGE_FOR_COLUMN_PICKER } from "../../../fixtures";
import { urlList } from "../../../fixtures/urlList";
import {
ensureCanvasStatic,
} from "../../../support/customCommands/sharedElementsOperations/canvas";
import { ensureCanvasStatic } from "../../../support/customCommands/sharedElementsOperations/canvas";
import { columnPickerPage } from "../../../support/pages";

describe("As an admin I should be able to use column picker", () => {
Expand All @@ -18,7 +14,7 @@ describe("As an admin I should be able to use column picker", () => {
});

it(
"should be able to add new dynamic column to grid on product list via search. TC: SALEOR_2610",
"should be able to add new dynamic column to grid on product list via search. TC: SALEOR_2610 should not be migrated to playwright as critical",
{ tags: ["@critical", "@allEnv", "@stable"] },
() => {
const dynamicColumnToBeSearched = "ABV";
Expand Down
1 change: 1 addition & 0 deletions playwright/data/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const URL_LIST = {
addPageType: "pages/add?page-type-id=",
apps: "custom-apps/",
attributes: "attributes/",
addAttributes: "attributes/add",
categories: "categories/",
channels: "channels/",
collections: "collections/",
Expand Down
57 changes: 57 additions & 0 deletions playwright/pages/attributesPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { AddValueDialog } from "@pages/dialogs/addValueDialog";
import type { Locator, Page } from "@playwright/test";

import { BasePage } from "./basePage";

export class AttributesPage {
readonly page: Page;
readonly addValueDialog: AddValueDialog;
readonly basePage: BasePage;
readonly createAttributeButton: Locator;
readonly attributeSelect: Locator;
readonly attributesRows: Locator;
readonly attributeDefaultLabelInput: Locator;
readonly attributeCodeInput: Locator;
readonly assignAttributeValueButton: Locator;
readonly saveButton: Locator;
readonly valueRequiredCheckbox: Locator;

constructor(page: Page) {
this.page = page;
this.addValueDialog = new AddValueDialog(page);
this.basePage = new BasePage(page);
this.createAttributeButton = page.getByTestId("create-attribute-button");
this.valueRequiredCheckbox = page.getByLabel("Value Required");
this.saveButton = page.getByTestId("button-bar-confirm");
this.attributesRows = page.getByTestId("attributes-rows");
this.assignAttributeValueButton = page.getByTestId("assign-value-button");
this.attributeSelect = page.getByTestId("attribute-type-select");
this.attributeDefaultLabelInput = page
.getByTestId("attribute-default-label-input")
.locator("input");
this.attributeCodeInput = page
.getByTestId("attribute-code-input")
.locator("input");
}

async clickCreateAttributeButton() {
await this.createAttributeButton.click();
}
async clickValueRequiredCheckbox() {
await this.valueRequiredCheckbox.click();
}
async clickSaveButton() {
await this.saveButton.click();
}
async selectAttributeType(attributeType = "DROPDOWN") {
await this.attributeSelect.click();
await this.page.getByTestId(`select-field-option-${attributeType}`).click();
}
async clickAssignAttributeValueButton() {
await this.assignAttributeValueButton.click();
}

async typeAttributeDefaultLabel(attributeDefaultLabel: string) {
await this.attributeDefaultLabelInput.fill(attributeDefaultLabel);
}
}
4 changes: 4 additions & 0 deletions playwright/pages/basePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ export class BasePage {
.waitFor({ state: "visible", timeout: 15000 });
await expect(this.errorBanner).not.toBeVisible();
}

async getRandomInt(max: number) {
return Math.floor(Math.random() * (max + 1));
}
}
5 changes: 5 additions & 0 deletions playwright/pages/configurationPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class ConfigurationPage {
readonly siteSettingsButton: Locator;
readonly staffMembersButton: Locator;
readonly shippingMethodsButton: Locator;
readonly attributesButton: Locator;

constructor(page: Page) {
this.page = page;
Expand All @@ -27,6 +28,7 @@ export class ConfigurationPage {
);
this.productTypesButton = page.locator("[data-test-id*='product-types']");
this.webhooksAndEventsButton = page.locator("[data-test-id*='webhooks']");
this.attributesButton = page.locator("[data-test-id*='attributes']");
this.pageTypesButton = page.locator(
"[data-test-id*='configuration-menu-page-type']",
);
Expand Down Expand Up @@ -62,4 +64,7 @@ export class ConfigurationPage {
async openWebhooksAndEvents() {
await this.webhooksAndEventsButton.click();
}
async openAttributes() {
await this.attributesButton.click();
}
}
18 changes: 18 additions & 0 deletions playwright/pages/dialogs/addValueDialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Locator, Page } from "@playwright/test";

export class AddValueDialog {
readonly page: Page;
readonly nameInput: Locator;
readonly saveButton: Locator;

constructor(page: Page) {
this.page = page;
this.nameInput = page.getByTestId("value-name").locator("input");
this.saveButton = page.getByTestId("submit");
}

async typeAndSaveAttributeValue(value = "XXL") {
await this.nameInput.fill(value);
await this.saveButton.click();
}
}
50 changes: 50 additions & 0 deletions playwright/tests/attributes.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { URL_LIST } from "@data/url";
import { AttributesPage } from "@pages/attributesPage";
import { ConfigurationPage } from "@pages/configurationPage";
import { expect, test } from "@playwright/test";

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

test("TC: SALEOR_34 User should be able to create Dropdown attribute, required, Product attribute @basic-regression", async ({

page,
}) => {
const configurationPage = new ConfigurationPage(page);
const attributesPage = new AttributesPage(page);
const attributeDefaultLabel = `attribute default label - ${await attributesPage.basePage.getRandomInt(
1000000,
)}`;

await page.goto(URL_LIST.configuration);

await configurationPage.openAttributes();
await attributesPage.clickCreateAttributeButton();
await attributesPage.typeAttributeDefaultLabel(attributeDefaultLabel);
await attributesPage.selectAttributeType("DROPDOWN");
await attributesPage.clickAssignAttributeValueButton();
await attributesPage.addValueDialog.typeAndSaveAttributeValue();
await attributesPage.clickSaveButton();
await attributesPage.basePage.expectSuccessBanner();
await expect(await attributesPage.attributesRows.count()).toEqual(1);
await expect(attributesPage.valueRequiredCheckbox).toBeEnabled();
expect(await attributesPage.valueRequiredCheckbox.isChecked()).toBeTruthy();
});
test("TC: SALEOR_35 User should be able to create Plain Text attribute, not required, Product attribute @basic-regression", async ({

page,
}) => {
const attributesPage = new AttributesPage(page);
const attributeDefaultLabel = `attribute default label - ${await attributesPage.basePage.getRandomInt(
1000000,
)}`;

await page.goto(URL_LIST.addAttributes);

await attributesPage.typeAttributeDefaultLabel(attributeDefaultLabel);
await attributesPage.selectAttributeType("PLAIN_TEXT");
await attributesPage.clickValueRequiredCheckbox();
await attributesPage.clickSaveButton();
await attributesPage.basePage.expectSuccessBanner();
await expect(attributesPage.valueRequiredCheckbox).toBeEnabled();
expect(await attributesPage.valueRequiredCheckbox.isChecked()).toBeFalsy();
});
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = props => {
/>
<CardContent>
<TextField
data-test-id="attribute-default-label-input"
disabled={disabled}
error={!!formApiErrors.name}
label={intl.formatMessage(messages.attributeLabel)}
Expand All @@ -163,6 +164,7 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = props => {
/>
<FormSpacer />
<TextField
data-test-id="attribute-code-input"
disabled={disabled}
error={!!formApiErrors.slug}
label={intl.formatMessage(messages.attributeSlug)}
Expand All @@ -177,7 +179,10 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = props => {
onChange={onChange}
/>
<FormSpacer />
<div className={classes.inputTypeSection}>
<div
className={classes.inputTypeSection}
data-test-id="attribute-type-select"
>
<SingleSelectField
choices={inputTypeChoices}
disabled={disabled || !canChangeType}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ const AttributeValues: React.FC<AttributeValuesProps> = ({
values,
(value, valueIndex) => (
<SortableTableRow<"row">
data-test-id="attributes-rows"
className={!!value ? classes.link : undefined}
hover={!!value}
onClick={!!value ? () => onValueUpdate(value.id) : undefined}
Expand Down

0 comments on commit 308e579

Please sign in to comment.