Repository navigation
Chore: Improve test for livechat #26527
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5e12d72
test: fix some selectors
weslley543 83a1524
Merge branch 'develop' into test/omni-livechat
weslley543 67429ec
fix: testing selectors
weslley543 e660673
Merge branch 'develop' into test/omni-livechat
weslley543 a98a9d5
fix: some selectors
weslley543 4f0f989
Merge branch 'develop' into test/omni-livechat
weslley543 33e85a4
lint: fix errors
weslley543 4a8e2a4
fix: lint
weslley543 b55acbf
test: ensure all livechat features are working
weslley543 2e39158
chore: make sugestions from pr
weslley543 7e418cf
chore: fixing function name
weslley543 17b9735
lint: fix import
weslley543 a94ef18
Merge branch 'develop' into test/omni-livechat
weslley543 afe6826
lint: fix lint
weslley543 46c7429
Merge branch 'develop' into test/omni-livechat
tassoevan 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 hidden or 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 hidden or 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,65 @@ | ||
| import { faker } from '@faker-js/faker'; | ||
| import type { Page } from '@playwright/test'; | ||
|
|
||
| import { test, expect } from './utils/test'; | ||
| import { HomeChannel, OmnichannelLiveChat } from './page-objects'; | ||
| import { createAuxContext } from './utils'; | ||
|
|
||
| const newUser = { | ||
| name: faker.name.firstName(), | ||
| email: faker.internet.email(), | ||
| }; | ||
| test.describe('Livechat', () => { | ||
| test.describe('Send message from user', () => { | ||
| let poLiveChat: OmnichannelLiveChat; | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| await page.goto('/livechat'); | ||
|
|
||
| poLiveChat = new OmnichannelLiveChat(page); | ||
| }); | ||
|
|
||
| test('expect send message to live chat', async () => { | ||
| await poLiveChat.btnOpenLiveChat('L').click(); | ||
| await poLiveChat.sendMessage(newUser); | ||
| }); | ||
|
|
||
| test.describe('Send message to online agent', () => { | ||
| let poAuxContext: { page: Page; poHomeChannel: HomeChannel }; | ||
| test.beforeAll(async ({ browser, api }) => { | ||
| await api.post('/livechat/users/agent', { username: 'user1' }); | ||
|
|
||
| poAuxContext = await createAuxContext(browser, 'user1-session.json'); | ||
| }); | ||
|
|
||
| test.afterAll(async () => { | ||
| await poAuxContext.page.close(); | ||
| }); | ||
|
|
||
| test('expect message is received from agent and user ', async ({ page }) => { | ||
| await poLiveChat.btnOpenLiveChat('R').click(); | ||
| await poLiveChat.sendMessage(newUser, false); | ||
|
|
||
| await poLiveChat.onlineAgentMessage.type('this_a_test_message_from_user'); | ||
| await poLiveChat.btnSendMessageToOnlineAgent.click(); | ||
|
|
||
| await expect(page.locator('div >>text="this_a_test_message_from_user"')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('expect after user close live chat screen dont show messages', async ({ page }) => { | ||
| await poLiveChat.btnOpenLiveChat('R').click(); | ||
| await expect(page.locator('[contenteditable="true"]')).not.toBeVisible(); | ||
| }); | ||
| }); | ||
| }); | ||
| test.describe('Verify message is received', () => { | ||
| test.use({ storageState: 'user1-session.json' }); | ||
| test('expect message is received from user', async ({ page }) => { | ||
| await page.goto('/'); | ||
| const poHomeChannel = new HomeChannel(page); | ||
| await poHomeChannel.sidenav.openChat(newUser.name); | ||
| await expect(poHomeChannel.content.lastUserMessage).toBeVisible(); | ||
| await expect(poHomeChannel.content.lastUserMessage).toContainText('this_a_test_message_from_user'); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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
51 changes: 51 additions & 0 deletions
51
apps/meteor/tests/e2e/page-objects/omnichannel-livechat.ts
This file contains hidden or 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,51 @@ | ||
| import type { Page, Locator } from '@playwright/test'; | ||
|
|
||
| export class OmnichannelLiveChat { | ||
| private readonly page: Page; | ||
|
|
||
| constructor(page: Page) { | ||
| this.page = page; | ||
| } | ||
|
|
||
| btnOpenLiveChat(label: string): Locator { | ||
| return this.page.locator(`[aria-label="${label}"]`); | ||
| } | ||
|
|
||
| get inputName(): Locator { | ||
| return this.page.locator('[name="name"]'); | ||
| } | ||
|
|
||
| get inputEmail(): Locator { | ||
| return this.page.locator('[name="email"]'); | ||
| } | ||
|
|
||
| get textAreaMessage(): Locator { | ||
| return this.page.locator('[name="message"]'); | ||
| } | ||
|
|
||
| btnSendMessage(btnText: string): Locator { | ||
| return this.page.locator(`[type="submit"] >> text="${btnText}"`); | ||
| } | ||
|
|
||
| get btnOk(): Locator { | ||
| return this.page.locator('button >> text="OK"'); | ||
| } | ||
|
|
||
| get onlineAgentMessage(): Locator { | ||
| return this.page.locator('[contenteditable="true"]'); | ||
| } | ||
|
|
||
| get btnSendMessageToOnlineAgent(): Locator { | ||
| return this.page.locator('footer div div div:nth-child(3) button'); | ||
| } | ||
|
|
||
| public async sendMessage(liveChatUser: { name: string; email: string }, isOffline = true): Promise<void> { | ||
| const buttonLabel = isOffline ? 'Send' : 'Start chat'; | ||
| await this.inputName.type(liveChatUser.name); | ||
| await this.inputEmail.type(liveChatUser.email); | ||
| if (isOffline) { | ||
| await this.textAreaMessage.type('any_message'); | ||
| } | ||
| await this.btnSendMessage(buttonLabel).click(); | ||
| } | ||
| } |
This file contains hidden or 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,15 @@ | ||
| import type { Browser, Page } from '@playwright/test'; | ||
|
|
||
| import { HomeChannel } from '../page-objects'; | ||
|
|
||
| /** | ||
| * createAuxContext: | ||
| * - Usefull to create a aux context for test will need many contexts | ||
| */ | ||
|
|
||
| export const createAuxContext = async (browser: Browser, storageState: string): Promise<{ page: Page; poHomeChannel: HomeChannel }> => { | ||
| const page = await browser.newPage({ storageState }); | ||
| const poHomeChannel = new HomeChannel(page); | ||
| await page.goto('/'); | ||
| return { page, poHomeChannel }; | ||
| }; |
This file contains hidden or 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 +1,2 @@ | ||
| export * from './create-target-channel'; | ||
| export * from './create-aux-context'; |
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.
Uh oh!
There was an error while loading. Please reload this page.