Skip to content

Commit 693404d

Browse files
committed
fixed the PR based on the comments
1 parent d2bc9dd commit 693404d

File tree

7 files changed

+39
-52
lines changed

7 files changed

+39
-52
lines changed

packages/amazonq/test/e2e_new/amazonq/chat.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { WebviewView } from 'vscode-extension-tester'
77
import { closeAllTabs } from './framework/cleanupHelper'
88
import { testContext } from './utils/testContext'
99
import { waitForChatResponse, writeToChat } from './framework/chatHelper'
10+
import assert from 'assert'
1011

1112
describe('Amazon Q Chat Basic Functionality', function () {
1213
// this timeout is the general timeout for the entire test suite
@@ -18,7 +19,11 @@ describe('Amazon Q Chat Basic Functionality', function () {
1819
})
1920

2021
afterEach(async () => {
21-
await closeAllTabs(webviewView)
22+
try {
23+
await closeAllTabs(webviewView)
24+
} catch (e) {
25+
assert.fail(`Failed to clean up tabs: ${e}`)
26+
}
2227
})
2328

2429
it('Chat Prompt Test', async () => {

packages/amazonq/test/e2e_new/amazonq/framework/chatHelper.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
import { By, WebviewView } from 'vscode-extension-tester'
66
import { waitForElement } from './generalHelper'
77

8-
/* Writes a prompt to the chat input and waits for a response
9-
10-
Logic:
11-
Finds the chat input element using the .mynah-chat-prompt-input CSS selector,
12-
sends the provided prompt test, clicks the send button, and waits for a chat
13-
response. Returns true if successful, throws an error if the response times out */
14-
158
export async function writeToChat(prompt: string, webview: WebviewView): Promise<boolean> {
169
const chatInput = await waitForElement(webview, By.css('.mynah-chat-prompt-input'))
1710
await chatInput.sendKeys(prompt)
@@ -20,14 +13,6 @@ export async function writeToChat(prompt: string, webview: WebviewView): Promise
2013
return true
2114
}
2215

23-
/* Waits for a chat response and outputs whether the response is "correct"
24-
25-
Logic:
26-
The overall conversation container's css is .mynah-chat-items-conversation-container.
27-
Within that container we can check how many elements exist. If there is 2 elements,
28-
we can assume that the chat response has been generated. However, we must grab the
29-
latest conversation container, as there can be multiple conversations in the webview. */
30-
3116
export async function waitForChatResponse(webview: WebviewView, timeout = 15000): Promise<boolean> {
3217
const startTime = Date.now()
3318

packages/amazonq/test/e2e_new/amazonq/framework/cleanupHelper.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@
44
*/
55
import { By, WebviewView } from 'vscode-extension-tester'
66

7-
/* Finds all the tabs by looking for the close buttons and then closes them one by one.
8-
9-
Logic:
10-
There is a button with the css mynah-tabs-close-button, we need to click that button and
11-
close all the tabs after the test is done to avoid memory from a previous test. To double
12-
check if all the tabs are closed, we can check if the mynah-tabs-container is empty. */
13-
14-
export async function closeAllTabs(webview: WebviewView) {
7+
export async function closeAllTabs(webview: WebviewView): Promise<boolean> {
158
try {
169
const closeButtons = await webview.findWebElements(By.css('.mynah-tabs-close-button'))
1710

@@ -20,15 +13,19 @@ export async function closeAllTabs(webview: WebviewView) {
2013
await new Promise((resolve) => setTimeout(resolve, 500))
2114
}
2215

23-
// double check that all tabs are closed by checking if the mynah-tabs-container is empty
2416
const tabsContainer = await webview.findWebElements(By.css('.mynah-tabs-container'))
25-
if (
17+
const allClosed =
2618
tabsContainer.length === 0 ||
2719
(await tabsContainer[0].findElements(By.css('.mynah-tab-item-label'))).length === 0
28-
) {
20+
21+
if (allClosed) {
2922
console.log('All chat tabs successfully closed')
23+
return true
24+
} else {
25+
throw new Error('Failed to close all tabs')
3026
}
3127
} catch (error) {
32-
console.log('Error closing tabs:', error)
28+
console.error('Error closing tabs:', error)
29+
throw error
3330
}
3431
}

packages/amazonq/test/e2e_new/amazonq/framework/generalHelper.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@
55
import { By, WebviewView, WebElement } from 'vscode-extension-tester'
66
import { until } from 'selenium-webdriver'
77

8-
/* Waits for an element (or multiple elements) to appear based on the parameters
9-
10-
Logic:
11-
The function utilizes the Selenium wait driver. We can call that driver from our
12-
WebviewView but it can also be called on parts of the VSCode Editor that are not
13-
part of the WebviewView.
14-
15-
(TO-DO: create a more general function that can be called on any part of the VSCode
16-
Editor. Will do when a use case appears for it.*/
17-
8+
/* Note: If multiple is set to False, then it will return the first element it finds that matches the Locator*/
189
export async function waitForElement(
1910
webview: WebviewView,
2011
locator: By,
@@ -38,13 +29,6 @@ export async function waitForElement(
3829
return multiple ? await webview.findWebElements(locator) : await webview.findWebElement(locator)
3930
}
4031

41-
/* General function for finding WebElement by their text content
42-
43-
Logic:
44-
It searches through an array of WebElements and looks for an element with
45-
the ".tittle" CSS class within each item. Compares the text content and returns
46-
the first matching parent element, or throws an error if not found. */
47-
4832
export async function findItemByText(items: WebElement[], text: string) {
4933
for (const item of items) {
5034
const titleDivs = await item.findElements(By.css('.title'))

packages/amazonq/test/e2e_new/amazonq/framework/loginHelper.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Currently, the function will
1313
3. Inputs the Start URL
1414
4. IMPORTANT: you must click manually open yourself when the popup window asks to open the browser and complete the authentication in the browser**
1515
16-
TO-DO: Currently this loginToAmazonQ is not fully autonomous as we ran into a blocker when the browser window pops up
17-
Documentation: https://quip-amazon.com/PoJOAyt4ja8H/Authentication-for-UI-Tests-Documentation */
16+
TO-DO: Currently this loginToAmazonQ is not fully autonomous as we ran into a blocker when the browser window pops up */
1817

1918
export async function loginToAmazonQ(): Promise<void> {
2019
const workbench = new Workbench()

packages/amazonq/test/e2e_new/amazonq/utils/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { loginToAmazonQ } from '../framework/loginHelper'
66

77
before(async function () {
8-
this.timeout(60000) // Increase timeout to 60 seconds
8+
this.timeout(60000)
99
console.log('\n\n*** MANUAL INTERVENTION REQUIRED ***')
1010
console.log('When prompted, you must manually click to open the browser and complete authentication')
1111
console.log('You have 60 seconds to complete this step\n\n')

packages/amazonq/test/e2e_new/amazonq/utils/testContext.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,26 @@
55
import { Workbench, WebviewView } from 'vscode-extension-tester'
66

77
export interface TestContext {
8-
workbench?: Workbench
9-
webviewView?: WebviewView
8+
workbench: Workbench
9+
webviewView: WebviewView
1010
}
1111

12-
// arr to store shared context
13-
export const testContext: TestContext = {}
12+
export const testContext = new Proxy<TestContext>({} as TestContext, {
13+
get(target, prop) {
14+
if (prop in target && target[prop as keyof TestContext] !== undefined) {
15+
return target[prop as keyof TestContext]
16+
}
17+
throw new Error(
18+
`TestContext.${String(prop)} is undefined. Make sure setup.ts has properly initialized the test context.`
19+
)
20+
},
21+
set(target, prop, value) {
22+
target[prop as keyof TestContext] = value
23+
return true
24+
},
25+
})
26+
27+
export function initializeTestContext(workbench: Workbench, webviewView: WebviewView): void {
28+
testContext.workbench = workbench
29+
testContext.webviewView = webviewView
30+
}

0 commit comments

Comments
 (0)