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

feat: add abstractions for flow builder create test #298

Open
wants to merge 4 commits into
base: trunk
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
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export * from './services/ShopInfo';
export * from './services/ImageHelper';
export * from './types/ShopwareTypes';
export * from './services/TestDataService';
export * from './services/ShopwareUIHelpers';

export { StorefrontPageObjects } from './page-objects/StorefrontPages';
export { AdminPageObjects } from './page-objects/AdministrationPages';
Expand Down
12 changes: 6 additions & 6 deletions src/page-objects/AdministrationPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ export const test = base.extend<FixtureTypes>({
await use(new FirstRunWizard(AdminPage, InstanceMeta));
},

AdminFlowBuilderCreate: async ({ AdminPage }, use) => {
await use(new FlowBuilderCreate(AdminPage));
AdminFlowBuilderCreate: async ({ AdminPage, InstanceMeta }, use) => {
await use(new FlowBuilderCreate(AdminPage, InstanceMeta));
},

AdminFlowBuilderListing: async ({ AdminPage }, use) => {
await use(new FlowBuilderListing(AdminPage));
AdminFlowBuilderListing: async ({ AdminPage, InstanceMeta }, use) => {
await use(new FlowBuilderListing(AdminPage, InstanceMeta));
},

AdminFlowBuilderDetail: async ({ AdminPage }, use) => {
await use(new FlowBuilderDetail(AdminPage));
AdminFlowBuilderDetail: async ({ AdminPage, InstanceMeta }, use) => {
await use(new FlowBuilderDetail(AdminPage, InstanceMeta));
},

AdminDataSharing: async ({ AdminPage }, use) => {
Expand Down
12 changes: 0 additions & 12 deletions src/page-objects/administration/CategoryDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ export class CategoryDetail implements PageObject {
this.customFieldSetTabCustomContent = this.customFieldCard.locator('.sw-tabs__custom-content');
}

async getCustomFieldSetCardContentByName(customFieldSetName: string): Promise<Record<string, Locator>> {

const customFieldCard = this.page.locator('.sw-card').filter({ hasText: 'Custom fields' });
const customFieldSetTab = customFieldCard.getByText(customFieldSetName);
const customFieldSetTabCustomContent = customFieldCard.locator(`.sw-custom-field-set-renderer-tab-content__${customFieldSetName}`);

return {
customFieldSetTab: customFieldSetTab,
customFieldSetTabCustomContent: customFieldSetTabCustomContent,
}
}

url(categoryUuid: string) {
return `#/sw/category/index/${categoryUuid}/base`
}
Expand Down
2 changes: 2 additions & 0 deletions src/page-objects/administration/CustomFieldDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class CustomFieldDetail extends CustomFieldCreate {
public readonly customFieldDeleteDialog: Locator;
public readonly customFieldDeleteCancelButton: Locator;
public readonly customFieldDeleteButton: Locator;
public readonly customFieldEditAvailableInShoppingCartCheckbox: Locator;

constructor(public readonly page: Page) {
super(page);
Expand All @@ -40,6 +41,7 @@ export class CustomFieldDetail extends CustomFieldCreate {
this.customFieldHelpTextEnglishGBInput = this.newCustomFieldDialog.getByLabel('Help text (English (GB))');

this.customFieldEditDialog = page.getByRole('dialog', { name: 'Edit custom field' });
this.customFieldEditAvailableInShoppingCartCheckbox = this.customFieldEditDialog.getByLabel('Available in shopping cart');
this.customFieldEditApplyButton = this.customFieldEditDialog.getByRole('button', { name: 'Apply changes' });

//Dialog - delete field
Expand Down
81 changes: 77 additions & 4 deletions src/page-objects/administration/FlowBuilderCreate.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,90 @@
import type { Page, Locator } from '@playwright/test';
import type { Locator, Page } from '@playwright/test';
import type { PageObject } from '../../types/PageObject';
import { satisfies } from 'compare-versions';
import { HelperFixtureTypes } from '../../fixtures/HelperFixtures';

export class FlowBuilderCreate implements PageObject {

//header
public readonly saveButton: Locator;
public readonly header: Locator;
public readonly smartBarHeader: Locator;
//tabs
public readonly generalTab: Locator;
public readonly flowTab: Locator;
//../general
public readonly nameField: Locator;
public readonly descriptionField: Locator;
public readonly priorityField: Locator;
public readonly activeSwitch: Locator;
//../flow
public readonly triggerSelectField: Locator;
public readonly modalAddButton: Locator;
public readonly sequenceSelectorConditionButton: Locator;
public readonly conditionSelectField: Locator;
public readonly sequenceSelectorActionButton: Locator;
public readonly actionSelectField: Locator;
public readonly selectFieldResultList: Locator;
public readonly trueBlockAddConditionButton: Locator;
public readonly trueBlockAddActionButton: Locator;
public readonly trueBlockActionSelectField: Locator;
public readonly trueBlockActionDescription: Locator;
public readonly mailSendModal: Locator;
public readonly mailSendModalTemplateSelectField: Locator;
public readonly falseBlockAddConditionButton: Locator;
public readonly falseBlockAddActionButton: Locator;
public readonly falseBlockActionSelectField: Locator;
public readonly falseBlockActionDescription: Locator;
public readonly tagModal: Locator;
public readonly tagModalTagsSelectField: Locator;
public readonly delayCard: Locator;
public readonly conditionRule: Locator;
public readonly sequenceSeparator: Locator;

constructor(public readonly page: Page) {
constructor(public readonly page: Page, public readonly instanceMeta: HelperFixtureTypes['InstanceMeta']) {
this.saveButton = page.locator('.sw-flow-detail__save');
this.header = page.locator('h2');
this.smartBarHeader = page.locator('.smart-bar__header');
this.generalTab = page.locator('.sw-flow-detail__tab-general');
this.triggerSelectField = page.locator('.sw-flow-detail-flow__trigger-card').getByRole('textbox');
if (satisfies(instanceMeta.version, '<6.7')) {
this.flowTab = page.locator('.sw-tabs__content').locator('.sw-flow-detail__tab-flow');
this.modalAddButton = page.locator('.sw-button--primary').getByText('Add action');
} else {
this.flowTab = page.locator('.mt-tabs').locator('.mt-tabs__item').getByText('Flow');
this.modalAddButton = page.locator('.mt-button--primary').getByText('Add action');
}
this.nameField = page.locator('.sw-flow-detail-general__general-name').getByLabel('Name');
this.descriptionField = page.locator('.sw-flow-detail-general__general-description').getByLabel('Description');
this.priorityField = page.locator('.sw-flow-detail-general__general-priority').getByLabel('Priority');
this.activeSwitch = page.locator('.sw-flow-detail-general__general-active').getByLabel('Active');
this.sequenceSelectorConditionButton = page.locator('.sw-flow-sequence-selector__actions').getByText('Add condition (IF)');
this.conditionSelectField = page.locator('.sw-flow-sequence-condition__select');
this.conditionRule = page.locator('.sw-flow-sequence-condition__rule-header');
this.sequenceSelectorActionButton = page.locator('.sw-flow-sequence-selector__actions').getByText('Add action (THEN)');
this.actionSelectField = page.locator('.sw-flow-sequence-action__content').locator('.sw-single-select__selection');
this.selectFieldResultList = page.locator('.sw-select-result-list__item-list');
this.trueBlockAddConditionButton = page.locator('.sw-flow-sequence__true-block').getByText('Add condition (IF)');
this.trueBlockAddActionButton = page.locator('.sw-flow-sequence__true-block').getByText('Add action (THEN)');
this.trueBlockActionSelectField = page.locator('.sw-flow-sequence__true-block').locator('.sw-single-select');
this.trueBlockActionDescription = page.locator('.sw-flow-sequence__true-block').locator('.sw-flow-sequence-action__action-description');
this.mailSendModal = page.locator('.sw-flow-mail-send-modal');
this.mailSendModalTemplateSelectField = page.locator('.sw-flow-mail-send-modal').locator('.sw-entity-single-select__selection');
this.falseBlockAddConditionButton = page.locator('.sw-flow-sequence__false-block').getByText('Add condition (IF)');
this.falseBlockAddActionButton = page.locator('.sw-flow-sequence__false-block').getByText('Add action (THEN)');
this.falseBlockActionSelectField = page.locator('.sw-flow-sequence__false-block').locator('.sw-single-select');
this.falseBlockActionDescription = page.locator('.sw-flow-sequence__false-block').locator('.sw-flow-sequence-action__actions');
this.tagModal = page.locator('.sw-flow-tag-modal');
this.tagModalTagsSelectField = page.locator('.sw-flow-tag-modal').locator('.sw-select__selection').getByLabel('Tags');
this.delayCard = page.locator('.sw-flow-delay-action__delay_card');
this.sequenceSeparator = page.locator('.sw-flow-detail-flow__position-connection');
}

url() {
return '#/sw/flow/create/general';
}
}
async getSelectedTrigger(): Promise<string> {
await this.page.locator('.sw-flow-detail-flow__trigger-card').getByRole('textbox').hover();
const tooltip = await this.page.waitForSelector('.sw-tooltip');

Check warning on line 87 in src/page-objects/administration/FlowBuilderCreate.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected use of page.waitForSelector()
return await tooltip.innerText();
}
}
24 changes: 15 additions & 9 deletions src/page-objects/administration/FlowBuilderDetail.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import type { Page, Locator } from '@playwright/test';
import type { PageObject } from '../../types/PageObject';
import { FlowBuilderCreate } from './FlowBuilderCreate';
import { satisfies } from 'compare-versions';
import { HelperFixtureTypes } from '../../fixtures/HelperFixtures';

export class FlowBuilderDetail implements PageObject {
export class FlowBuilderDetail extends FlowBuilderCreate implements PageObject {

public readonly successMessage: Locator;

constructor(public readonly page: Page, public readonly instanceMeta: HelperFixtureTypes['InstanceMeta']) {
super(page, instanceMeta);
if (satisfies(instanceMeta.version, '<6.7')) {
this.successMessage = page.locator('.sw-alert__title');
} else {
this.successMessage = page.locator('.mt-banner__title');
}

public readonly saveButton: Locator;
public readonly generalTab: Locator;
public readonly flowTab: Locator;

constructor(public readonly page: Page) {
this.saveButton = page.locator('.sw-flow-detail__save');
this.generalTab = page.locator('.sw-flow-detail__tab-general');
this.flowTab = page.locator('.sw-flow-detail__tab-flow');
}

url(flowId: string, tabName = 'general') {
url(flowId?: string, tabName = 'general') {
return `#/sw/flow/detail/${flowId}/${tabName}`
}
}
44 changes: 25 additions & 19 deletions src/page-objects/administration/FlowBuilderListing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Page, Locator } from '@playwright/test';
import type { PageObject } from '../../types/PageObject';
import { satisfies } from 'compare-versions';
import { HelperFixtureTypes } from '../../fixtures/HelperFixtures';

export class FlowBuilderListing implements PageObject {

Expand All @@ -17,22 +19,22 @@ export class FlowBuilderListing implements PageObject {
public readonly successAlert: Locator;
public readonly successAlertMessage: Locator;

constructor(public readonly page: Page) {
this.createFlowButton = page.locator('.sw-flow-list__create');
this.firstFlowName = page.locator('.sw-data-grid__cell--name a').first();
this.firstFlowContextButton = page.locator('.sw-data-grid__actions-menu').first();
this.flowContextMenu = page.locator('.sw-context-menu__content');
this.contextMenuDownload = this.flowContextMenu.locator('.sw-flow-list__item-download');
this.contextMenuDuplicate = this.flowContextMenu.locator('.sw-flow-list__item-duplicate');
this.contextMenuEdit = this.flowContextMenu.locator('.sw-flow-list__item-edit');
this.contextMenuDelete = this.flowContextMenu.locator('.sw-flow-list__item-delete');
this.flowDownloadModal = page.locator('.sw-flow-download-modal');
this.flowDeleteButton = page.getByRole('dialog')
.filter( {hasText: 'If you delete this flow, no more actions will be performed for the trigger. Are you sure you want to delete this flow?'} )
.getByRole('button', { name: 'Delete' });
this.downloadFlowButton = page.getByRole('button', { name: 'Download flow' });
this.successAlert = page.locator('.sw-alert__body');
this.successAlertMessage = page.locator('.sw-alert__message');
constructor(public readonly page: Page, public readonly instanceMeta: HelperFixtureTypes['InstanceMeta']) {
this.createFlowButton = page.locator('.sw-flow-list__create');
this.firstFlowName = page.locator('.sw-data-grid__cell--name a').first();
this.firstFlowContextButton = page.locator('.sw-data-grid__actions-menu').first();
this.flowContextMenu = page.locator('.sw-context-menu__content');
this.contextMenuDownload = this.flowContextMenu.locator('.sw-flow-list__item-download');
this.contextMenuDuplicate = this.flowContextMenu.locator('.sw-flow-list__item-duplicate');
this.contextMenuEdit = this.flowContextMenu.locator('.sw-flow-list__item-edit');
this.contextMenuDelete = this.flowContextMenu.locator('.sw-flow-list__item-delete');
this.flowDownloadModal = page.locator('.sw-flow-download-modal');
this.flowDeleteButton = page.getByRole('dialog')
.filter( {hasText: 'If you delete this flow, no more actions will be performed for the trigger. Are you sure you want to delete this flow?'} )
.getByRole('button', { name: 'Delete' });
this.downloadFlowButton = page.getByRole('button', { name: 'Download flow' });
this.successAlert = page.locator('.sw-alert__body');
this.successAlertMessage = page.locator('.sw-alert__message');
}

url() {
Expand All @@ -42,12 +44,16 @@ export class FlowBuilderListing implements PageObject {
async getLineItemByFlowName(flowName: string): Promise<Record<string, Locator>> {
const lineItem = this.page.locator('.sw-data-grid__row').filter({ hasText: flowName });
const flowSelectionCheckbox = lineItem.locator('.sw-data-grid__cell--selection').locator('.sw-field__checkbox');
const flowActiveCheckmark = lineItem.locator('.sw-data-grid__cell--active').locator('.icon--regular-checkmark-xs');
let flowActiveCheckmark
if (satisfies(this.instanceMeta.version, '<6.7')) {
flowActiveCheckmark = lineItem.locator('.sw-data-grid__cell--active').locator('.icon--regular-checkmark-xs');
} else {
flowActiveCheckmark = lineItem.locator('.sw-data-grid__cell--active').getByTestId('mt-icon__regular-checkmark-xs');
}
const flowDisabledCheckmark = lineItem.locator('.sw-data-grid__cell--active').locator('.icon--regular-times-s');
const flowNameText = lineItem.locator('.sw-data-grid__cell--name');
const flowEventNameText = lineItem.locator('.sw-data-grid__cell--eventName');
const flowContextMenuButton = lineItem.locator('.sw-data-grid__actions-menu');

return {
flowSelectionCheckbox: flowSelectionCheckbox,
flowActiveCheckmark: flowActiveCheckmark,
Expand All @@ -57,4 +63,4 @@ export class FlowBuilderListing implements PageObject {
flowContextMenuButton: flowContextMenuButton,
}
}
}
}
12 changes: 0 additions & 12 deletions src/page-objects/administration/ManufacturerDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ export class ManufacturerDetail extends ManufacturerCreate {
this.customFieldSetTabCustomContent = this.customFieldCard.locator('.sw-tabs__custom-content');
}

async getCustomFieldSetCardContentByName(customFieldSetName: string): Promise<Record<string, Locator>> {

const customFieldCard = this.page.locator('.sw-card').filter({hasText: 'Custom fields'});
const customFieldSetTab = customFieldCard.getByText(customFieldSetName);
const customFieldSetTabCustomContent = customFieldCard.locator(`.sw-custom-field-set-renderer-tab-content__${customFieldSetName}`);

return {
customFieldSetTab: customFieldSetTab,
customFieldSetTabCustomContent: customFieldSetTabCustomContent,
}
}

url(manufacturerUuid?: string) {
return `#/sw/manufacturer/detail/${manufacturerUuid}`
}
Expand Down
4 changes: 2 additions & 2 deletions src/page-objects/administration/OrderDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class OrderDetail implements PageObject {
this.orderTag = page.locator('.sw-select-selection-list__item');
}

url(orderId: string) {
return `#/sw/order/detail/${orderId}/general`;
url(orderId: string, tabName = 'general') {
return `#/sw/order/detail/${orderId}/${tabName}`;
}
}
12 changes: 0 additions & 12 deletions src/page-objects/administration/ProductDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,6 @@ export class ProductDetail implements PageObject {
this.customFieldCard = page.locator('.sw-card').getByText('Custom fields');
}

async getCustomFieldSetCardContentByName(customFieldSetName: string): Promise<Record<string, Locator>> {

const customFieldCard = this.page.locator('.sw-card').filter({ hasText: 'Custom fields' });
const customFieldSetTab = customFieldCard.getByText(customFieldSetName);
const customFieldSetTabCustomContent = customFieldCard.locator(`.sw-custom-field-set-renderer-tab-content__${customFieldSetName}`);

return {
customFieldSetTab: customFieldSetTab,
customFieldSetTabCustomContent: customFieldSetTabCustomContent,
}
}

url(productId: string) {
return `#/sw/product/detail/${productId}/base`
}
Expand Down
38 changes: 38 additions & 0 deletions src/services/ShopwareUIHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { type Page, type Locator } from '@playwright/test';

/**
* Returns the locator for a list item on a select field's result list.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow I don't like the approach of introducing a new silo for lots or functions where the purpose of the class is not specific enough. Let's think about it again.

I have already an idea:

  • create a service like CustomFieldCard which inject a page object so that we can manage there some card specific functions like getCustomFieldCardContent(). And use the functions within page objects which want to use it with:
import { getCustomFieldCardContent } from '../../services/ShopwareUIHelpers.ts';

export class ProductDetail implements PageObject {
    // ...

    public getCustomFieldCardContent(selectField: Locator, listItem: string) {
        return getCustomFieldCardContent(this.page, locator, listItem);
    }
}

so within your test you could call then:

const customFieldLocators = await AdminProductDetail.getCustomFieldCardContent(selectField, listItem: string);

@vanpham-sw and @yusufttur what do you think about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frobel I purposefully added the function to the UIHelpers class so that it would not have to be declared in every page object. With this test alone, we check 3-5 different detail pages and would thus have to add the function to each page object. I just found it easier to put it into the Helpers class once.

*
* @param pageObject - Page object that contains the select field.
* @param selectField - Locator for the select field.
* @param listItem - List item to select.
* @returns The locator for the list item.
*/
export const getResultListItem = async (pageObject: Page, selectField: Locator, listItem: string): Promise<Locator> => {
await selectField.click();
await pageObject.locator('.sw-select-result-list__item-list').waitFor({ state: 'visible' });
return pageObject.locator('.sw-select-result-list__content').getByRole('listitem').filter({ hasText: listItem });
};

/**
* Returns locators for assigned custom fields on entity detail pages.
*
* @param pageObject
* @param customFieldSetName
* @param customFieldName
* @returns Custom field locators on entity detail pages.
*/
export const getCustomFieldCardContent = async (pageObject: Page, customFieldSetName: string, customFieldName: string): Promise<Record<string, Locator>> => {

const customFieldCard = pageObject.locator('.sw-card').filter({ hasText: 'Custom fields' });
const customFieldSetTab = customFieldCard.getByText(customFieldSetName);
const customFieldLabel = customFieldCard.locator('.sw-custom-field-set-renderer').locator('.sw-field__label').getByText(customFieldName);
const customFieldSelect = customFieldCard.locator(`.sw-custom-field-set-renderer-tab-content__${customFieldSetName}`);

return {
customFieldCard: customFieldCard,
customFieldSetsTab: customFieldSetTab,
customFieldLabel: customFieldLabel,
customFieldSelect: customFieldSelect,
}
}
2 changes: 2 additions & 0 deletions src/tasks/shop-admin-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CreateLinkTypeCategory } from './shop-admin/Category/CreateLinkTypeCate
import { BulkEditProducts } from './shop-admin/Product/BulkEditProducts';
import { BulkEditCustomers } from './shop-admin/Customers/BulkEditCustomers';
import { AssignEntitiesToRule } from './shop-admin/Rule/AssignEntitiesToRule';
import { CreateFlow } from './shop-admin/Flow/CreateFlow';

export const test = mergeTests(
SaveProduct,
Expand All @@ -14,4 +15,5 @@ export const test = mergeTests(
BulkEditProducts,
BulkEditCustomers,
AssignEntitiesToRule,
CreateFlow,
);
Loading
Loading