-
Notifications
You must be signed in to change notification settings - Fork 5
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
GitEvil
wants to merge
4
commits into
trunk
Choose a base branch
from
next-39672/flow-builder-create-new-flow
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
return await tooltip.innerText(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
* | ||
* @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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
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?
There was a problem hiding this comment.
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.