Skip to content

Commit ed3c220

Browse files
committed
tested the timeouts, implemented a general wait function
1 parent 35c656f commit ed3c220

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

packages/amazonq/test.log

Whitespace-only changes.

packages/amazonq/test/e2e/amazonq/VET.test.ts

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,21 @@ import { until } from 'selenium-webdriver'
77

88
describe('Amazon Q E2E UI Test', function () {
99
// need this timeout because Amazon Q takes awhile to load
10+
11+
// need this timeout
1012
this.timeout(150000)
1113
let webviewView: WebviewView
1214
let workbench: Workbench
13-
// NOTE: I tested all the timeouts and they are necessary for the webview to load properly
1415
before(async function () {
15-
this.timeout(120000)
1616
workbench = new Workbench()
1717
await workbench.executeCommand('Amazon Q: Open Chat')
1818

19+
// need this timeout
1920
await new Promise((resolve) => setTimeout(resolve, 5000))
2021
webviewView = new WebviewView()
2122
await webviewView.switchToFrame()
2223

23-
const driver = webviewView.getDriver()
24-
await driver.wait(until.elementsLocated(By.css('.selectable-item')), 30000)
25-
const selectableItems = await webviewView.findWebElements(By.css('.selectable-item'))
24+
const selectableItems = await waitForElement(webviewView, By.css('.selectable-item'), true)
2625
if (selectableItems.length === 0) {
2726
throw new Error('No selectable login options found')
2827
}
@@ -37,6 +36,7 @@ describe('Amazon Q E2E UI Test', function () {
3736
const UrlContinue = await webviewView.findWebElement(By.css('button.continue-button.topMargin'))
3837
await UrlContinue.click()
3938
console.log('Waiting for manual authentication...')
39+
// need this timeout
4040
await new Promise((resolve) => setTimeout(resolve, 12000))
4141
console.log('Manual authentication should be done')
4242
await webviewView.switchBack()
@@ -46,24 +46,18 @@ describe('Amazon Q E2E UI Test', function () {
4646
console.log('editorview successfully created')
4747
await editorView.closeAllEditors()
4848
console.log('Closed all editors')
49-
await new Promise((resolve) => setTimeout(resolve, 1500))
5049
webviewView = new WebviewView()
5150
console.log('Reopened webview view')
5251
await webviewView.switchToFrame()
53-
await new Promise((resolve) => setTimeout(resolve, 1200))
5452
})
5553

5654
after(async () => {
57-
// TO-DO: Close all the chat windows after the test is done so that when the test runs again it does not have memory
58-
// from the previous test
59-
6055
/*
6156
mynah-tabs-container is the css that contains all the mynah ui tabs
6257
inside that there are two spans that have key values
6358
inside those spans there is a div with the css mynah-tab-item-label
6459
and finally INSIDE THAT there is a button with the css mynah-tabs-close-button, we need to click that button and close all the tabs after the test is done
6560
66-
6761
Logic:
6862
Find all the tahs by looking for the close buttons and then close them one by one. To check if all the tabs are closed, we can check if the mynah-tabs-container is empty.
6963
*/
@@ -92,18 +86,13 @@ describe('Amazon Q E2E UI Test', function () {
9286
})
9387

9488
it('Chat Prompt Test', async () => {
95-
const driver = webviewView.getDriver()
96-
await driver.wait(until.elementsLocated(By.css('.mynah-chat-prompt-input')), 300000)
97-
// In order to test the chat prompt, we need to find the input field and send keys
98-
const chatInput = await webviewView.findWebElement(By.css('.mynah-chat-prompt-input'))
89+
const chatInput = await waitForElement(webviewView, By.css('.mynah-chat-prompt-input'))
9990
await chatInput.sendKeys('Hello, Amazon Q!')
100-
await driver.wait(until.elementsLocated(By.css('.mynah-chat-prompt-button')), 300000)
101-
// In order to submit the chat prompt, we need to find the send button and click it
102-
const sendButton = await webviewView.findWebElement(By.css('.mynah-chat-prompt-button'))
91+
const sendButton = await waitForElement(webviewView, By.css('.mynah-chat-prompt-button'))
10392
await sendButton.click()
10493

105-
await new Promise((resolve) => setTimeout(resolve, 12000))
106-
// Wait for response using conversation container check
94+
// await new Promise((resolve) => setTimeout(resolve, 12000))
95+
// wait for response using conversation container check
10796
const responseReceived = await waitForChatResponse(webviewView)
10897
if (!responseReceived) {
10998
throw new Error('Chat response not received within timeout')
@@ -112,6 +101,30 @@ describe('Amazon Q E2E UI Test', function () {
112101
console.log('Chat response detected successfully')
113102
})
114103

104+
// Helper to wait for ui elements to load, utilizes typescript function overloading to account for all possible edge cases
105+
async function waitForElement(
106+
webview: WebviewView,
107+
locator: By,
108+
multiple: true,
109+
timeout?: number
110+
): Promise<WebElement[]>
111+
async function waitForElement(
112+
webview: WebviewView,
113+
locator: By,
114+
multiple?: false,
115+
timeout?: number
116+
): Promise<WebElement>
117+
async function waitForElement(
118+
webview: WebviewView,
119+
locator: By,
120+
multiple = false,
121+
timeout = 15000
122+
): Promise<WebElement | WebElement[]> {
123+
const driver = webview.getDriver()
124+
await driver.wait(until.elementsLocated(locator), timeout)
125+
return multiple ? await webview.findWebElements(locator) : await webview.findWebElement(locator)
126+
}
127+
115128
// Helper to find item by text content
116129
async function findItemByText(items: WebElement[], text: string) {
117130
for (const item of items) {
@@ -130,9 +143,8 @@ describe('Amazon Q E2E UI Test', function () {
130143
Instead of looking for a specific message like how we look for other elements in the test,
131144
I can check how many elements there are in our specific conversation container. If there is 2 elements,
132145
we can assume that the chat response has been generated. The challenge is, we must grab the latest
133-
conversation container, as there can be multiple conversations in the webview.
134-
*/
135-
async function waitForChatResponse(webview: WebviewView, timeout = 30000): Promise<boolean> {
146+
conversation container, as there can be multiple conversations in the webview. */
147+
async function waitForChatResponse(webview: WebviewView, timeout = 15000): Promise<boolean> {
136148
const startTime = Date.now()
137149

138150
while (Date.now() - startTime < timeout) {

0 commit comments

Comments
 (0)