-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: write workflow snapshot tests (#381)
## Changes - N/A ticket: [AC-4068] ## How to run test & test plan [link](https://sendbird.atlassian.net/wiki/spaces/AC/pages/2610724994/Widget+snapshot+test+plan) ## Checklist Before requesting a code review, please check the following: - [x] **[Required]** CI has passed all checks. - [ ] **[Required]** A self-review has been conducted to ensure there are no minor mistakes. - [ ] **[Required]** Unnecessary comments/debugging code have been removed. - [ ] **[Required]** All requirements specified in the ticket have been accurately implemented. - [ ] Ensure the ticket has been updated with the sprint, status, and story points. [AC-4068]: https://sendbird.atlassian.net/browse/AC-4068?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --------- Co-authored-by: Hyungu Kang | Airen <[email protected]>
- Loading branch information
Showing
43 changed files
with
440 additions
and
15 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,7 @@ dist-ssr | |
*.njsproj | ||
*.sln | ||
*.sw? | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
Binary file added
BIN
+28 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/100-1-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.4 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/100-1-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+32.5 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/100-2-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+40.9 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/100-2-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+34.3 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/100-3-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+43.6 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/100-3-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.8 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/100-4-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.5 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/100-4-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.3 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/101-1-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+41.3 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/101-1-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+164 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/102-1-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+220 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/102-1-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+32.6 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/103-1-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+40.1 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/103-1-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.9 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/103-2-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.8 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/103-2-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.3 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/103-3-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+43.3 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/103-3-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+158 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/103-4-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+216 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/103-4-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+108 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/103-5-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+148 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/103-5-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+28 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/103-6-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.4 KB
__visual_tests__/__snapshots__/workflow-tests.spec.ts/103-6-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,15 @@ | ||
const appId = process.env.SNAPSHOT_TEST_APP_ID; | ||
const botId = process.env.SNAPSHOT_TEST_BOT_ID; | ||
|
||
export const TEST_URL = `http://localhost:5173/chat-ai-widget/?app_id=${appId}&bot_id=${botId}&snapshot=true`; | ||
|
||
export const WidgetComponentIds = { | ||
WIDGET: '#aichatbot-widget-window', | ||
WIDGET_BUTTON: '#aichatbot-widget-button', | ||
MESSAGE_INPUT: '#sendbird-message-input-text-field', | ||
SUGGESTED_REPLIES_OPTIONS: '.sendbird-suggested-replies__option', | ||
BUTTON: 'button.sendbird-button--primary', | ||
INPUT: '.sendbird-input__input', | ||
CHIPS_CONTAINER: '.sendbird-form-chip__container', | ||
FORM: '#aichatbot-widget-form', | ||
}; |
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,31 @@ | ||
import { expect, Page } from '@playwright/test'; | ||
|
||
import { WidgetComponentIds } from './const'; | ||
|
||
export async function assertScreenshot(page: Page, screenshotName: string, browserName: string) { | ||
const name = `${screenshotName}.${browserName}.${process.platform}.png`; // Include the browser and OS architecture info in the filename | ||
await expect(page.locator(WidgetComponentIds.WIDGET)).toHaveScreenshot(name, { | ||
omitBackground: false, | ||
maxDiffPixelRatio: 0.01, // Need this because Sendbird logo is slightly differently rendered in CI. | ||
}); | ||
} | ||
|
||
export async function loadWidget(page: Page) { | ||
await page.click(WidgetComponentIds.WIDGET_BUTTON); | ||
// NOTE: below fails sometimes in CI. | ||
const widgetWindow = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
await widgetWindow.waitFor({ state: 'visible' }); | ||
// await page.waitForTimeout(3000); | ||
} | ||
|
||
export async function sendTextMessage(page: Page, text: string, waitTime = 1000) { | ||
const input = page.locator(WidgetComponentIds.MESSAGE_INPUT); | ||
await input.fill(text); | ||
await input.press('Enter'); | ||
await page.waitForTimeout(waitTime); | ||
} | ||
|
||
export async function clickNthChip(page: Page, nth: number) { | ||
const chipContainer = page.locator(WidgetComponentIds.CHIPS_CONTAINER); | ||
await chipContainer.locator(':scope > *').nth(nth).click(); | ||
} |
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,129 @@ | ||
import { test } from '@playwright/test'; | ||
|
||
import { TEST_URL, WidgetComponentIds } from './const'; | ||
import { assertScreenshot, clickNthChip, loadWidget, sendTextMessage } from './utils'; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto(TEST_URL); | ||
const widgetWindow = page.locator(WidgetComponentIds.WIDGET_BUTTON); | ||
await widgetWindow.waitFor({ state: 'visible' }); | ||
}); | ||
|
||
/** | ||
* 100 | ||
* Workflow - Form message | ||
* Steps: | ||
* 1. Send the trigger message: "Give me a food order form" | ||
* 2. Submit form without filling the required fields. | ||
* 3. Submit form with at least one invalid value. | ||
* 4. Submit form with valid values. | ||
*/ | ||
test('100', async ({ page, browserName }) => { | ||
await loadWidget(page); | ||
|
||
// 1 | ||
await sendTextMessage(page, 'Give me a food order form', 0); | ||
const widgetWindow = page.locator(WidgetComponentIds.FORM); | ||
await widgetWindow.waitFor({ state: 'visible' }); | ||
await assertScreenshot(page, '100-1', browserName); | ||
|
||
// 2 | ||
let submitButton = page.locator(WidgetComponentIds.BUTTON); | ||
await submitButton.click(); | ||
await assertScreenshot(page, '100-2', browserName); | ||
|
||
// 3 | ||
const inputs = page.locator(WidgetComponentIds.INPUT); | ||
await inputs.nth(0).fill('guy ordering food'); | ||
await inputs.nth(2).fill('not a number'); | ||
await inputs.nth(3).fill('not.a.valid.email.com'); | ||
await inputs.nth(4).fill('123_456_7890'); | ||
await clickNthChip(page, 4); | ||
submitButton = page.locator(WidgetComponentIds.BUTTON); | ||
await page.waitForTimeout(1000); | ||
await assertScreenshot(page, '100-3', browserName); | ||
|
||
// 4 | ||
await inputs.nth(2).fill('2'); | ||
await inputs.nth(3).fill('[email protected]'); | ||
await inputs.nth(4).fill('123-456-7890'); | ||
await submitButton.click(); | ||
await page.waitForTimeout(1000); | ||
await assertScreenshot(page, '100-4', browserName); | ||
}); | ||
|
||
/** | ||
* 101 | ||
* Workflow - Function calls: user message | ||
* Steps: | ||
* 1. Send the trigger message: "Tell me about one cat breed" | ||
*/ | ||
test('101', async ({ page, browserName }) => { | ||
await loadWidget(page); | ||
// 1 | ||
await sendTextMessage(page, 'Tell me about one cat breed', 2000); | ||
await assertScreenshot(page, '101-1', browserName); | ||
}); | ||
|
||
/** | ||
* 102 | ||
* Workflow - File message | ||
* Steps: | ||
* 1. Send the trigger message: "Give me a travel agency poster" | ||
*/ | ||
test('102', async ({ page, browserName }) => { | ||
await loadWidget(page); | ||
// 1 | ||
await sendTextMessage(page, 'Give me a travel agency poster', 5000); | ||
await assertScreenshot(page, '102-1', browserName); | ||
}); | ||
|
||
/** | ||
* 103 | ||
* Workflow - Suggested replies with 'Back' enabled | ||
* Steps: | ||
* 1. Send the trigger message: "Suggested replies" | ||
* 2. Click "Text" | ||
* 3. Click "Back" | ||
* 4. Click "File" | ||
* 5. Click "Back" | ||
* 6. Click "Link to workflow: form message" | ||
*/ | ||
test('103', async ({ page, browserName }) => { | ||
await loadWidget(page); | ||
// 1 | ||
await sendTextMessage(page, 'Suggested replies', 2000); | ||
await assertScreenshot(page, '103-1', browserName); | ||
|
||
// 2 | ||
let options = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
await options.nth(0).click(); | ||
await page.waitForTimeout(1000); | ||
await assertScreenshot(page, '103-2', browserName); | ||
|
||
// 3 | ||
options = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
await options.nth(0).click(); | ||
await page.waitForTimeout(1000); | ||
await assertScreenshot(page, '103-3', browserName); | ||
|
||
// 4 | ||
options = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
await options.nth(1).click(); | ||
await page.waitForTimeout(4000); // Time takes long for file message to be rendered and then scrolled to bottom in CI browsers. | ||
await assertScreenshot(page, '103-4', browserName); | ||
|
||
// 5 | ||
options = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
await options.nth(0).click(); | ||
options = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
// Expecting three options. | ||
await options.nth(2).waitFor({ state: 'visible' }); | ||
await assertScreenshot(page, '103-5', browserName); | ||
|
||
// 6 | ||
options = page.locator(WidgetComponentIds.SUGGESTED_REPLIES_OPTIONS); | ||
await options.nth(2).click(); | ||
await page.waitForTimeout(1000); | ||
await assertScreenshot(page, '103-6', browserName); | ||
}); |
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,83 @@ | ||
import {defineConfig, devices} from '@playwright/test'; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// import dotenv from 'dotenv'; | ||
// import path from 'path'; | ||
// dotenv.config({ path: path.resolve(__dirname, '.env') }); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: './__visual_tests__', | ||
snapshotPathTemplate: '{testDir}/__snapshots__/{testFilePath}/{arg}{ext}', // Refer to: https://playwright.dev/docs/next/api/class-testproject#test-project-snapshot-path-template | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: 0, // process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: undefined, // process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: [ | ||
['junit', { outputFile: 'results.xml' }], | ||
['html'] | ||
], | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
// baseURL: 'http://127.0.0.1:3000', | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, // Note we cannot use ...devices['Desktop Chrome'] because the name varies between devices and in CircleCI environment. CI test will fail because of this. | ||
}, | ||
|
||
{ | ||
name: 'firefox', | ||
use: { ...devices['Desktop Firefox'] }, // Note we cannot use ...devices['Desktop Firefox'] because the name varies between devices and in CircleCI environment. CI test will fail because of this. | ||
}, | ||
|
||
// { | ||
// name: 'webkit', | ||
// use: { ...devices['Desktop Safari'] }, | ||
// }, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { ...devices['Pixel 5'] }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { ...devices['iPhone 12'] }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
webServer: { | ||
command: 'yarn dev', | ||
url: 'http://localhost:5173/chat-ai-widget/', | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}); |
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.