Skip to content

Commit 74011d2

Browse files
committed
added setup.ts and testContext so that auth can be shared across tests
1 parent c8ccbae commit 74011d2

File tree

5 files changed

+52
-14
lines changed

5 files changed

+52
-14
lines changed

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,31 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
import { By, WebviewView } from 'vscode-extension-tester'
6-
import { loginToAmazonQ } from './framework/loginHelper'
5+
import './utils/setup'
6+
import { WebviewView } from 'vscode-extension-tester'
77
import { closeAllTabs } from './framework/cleanupHelper'
8-
import { waitForElement } from './framework/generalHelper'
9-
import { waitForChatResponse } from './framework/chatHelper'
8+
import { testContext } from './utils/testContext'
9+
import { waitForChatResponse, writeToChat } from './framework/chatHelper'
1010

1111
describe('Amazon Q Chat Basic Functionality', function () {
1212
// this timeout is the general timeout for the entire test suite
1313
this.timeout(150000)
1414
let webviewView: WebviewView
1515

1616
before(async function () {
17-
const result = await loginToAmazonQ()
18-
webviewView = result.webviewView
17+
webviewView = testContext.webviewView!
1918
})
2019

2120
afterEach(async () => {
2221
await closeAllTabs(webviewView)
2322
})
2423

2524
it('Chat Prompt Test', async () => {
26-
const chatInput = await waitForElement(webviewView, By.css('.mynah-chat-prompt-input'))
27-
await chatInput.sendKeys('Hello, Amazon Q!')
28-
const sendButton = await waitForElement(webviewView, By.css('.mynah-chat-prompt-button'))
29-
await sendButton.click()
25+
await writeToChat('Hello, Amazon Q!', webviewView)
3026
const responseReceived = await waitForChatResponse(webviewView)
3127
if (!responseReceived) {
3228
throw new Error('Chat response not received within timeout')
3329
}
34-
3530
console.log('Chat response detected successfully')
3631
})
3732
})

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55
import { By, WebviewView } from 'vscode-extension-tester'
6+
import { waitForElement } from './generalHelper'
7+
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+
15+
export async function writeToChat(prompt: string, webview: WebviewView): Promise<boolean> {
16+
const chatInput = await waitForElement(webview, By.css('.mynah-chat-prompt-input'))
17+
await chatInput.sendKeys(prompt)
18+
const sendButton = await waitForElement(webview, By.css('.mynah-chat-prompt-button'))
19+
await sendButton.click()
20+
return true
21+
}
622

723
/* Waits for a chat response and outputs whether the response is "correct"
824

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
import { Workbench, By, WebviewView } from 'vscode-extension-tester'
66
import { waitForElement, findItemByText } from './generalHelper'
7-
7+
import { testContext } from '../utils/testContext'
88
/* Completes the entire Amazon Q login flow
99
1010
Currently, the function will
@@ -16,7 +16,7 @@ Currently, the function will
1616
TO-DO: Currently this loginToAmazonQ is not fully autonomous as we ran into a blocker when the browser window pops up
1717
Documentation: https://quip-amazon.com/PoJOAyt4ja8H/Authentication-for-UI-Tests-Documentation */
1818

19-
export async function loginToAmazonQ(): Promise<{ workbench: Workbench; webviewView: WebviewView }> {
19+
export async function loginToAmazonQ(): Promise<void> {
2020
const workbench = new Workbench()
2121
await workbench.executeCommand('Amazon Q: Open Chat')
2222

@@ -48,5 +48,6 @@ export async function loginToAmazonQ(): Promise<{ workbench: Workbench; webviewV
4848
webviewView = new WebviewView()
4949
await webviewView.switchToFrame()
5050

51-
return { workbench, webviewView }
51+
testContext.workbench = workbench
52+
testContext.webviewView = webviewView
5253
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import { loginToAmazonQ } from '../framework/loginHelper'
6+
7+
before(async function () {
8+
this.timeout(60000) // Increase timeout to 60 seconds
9+
console.log('\n\n*** MANUAL INTERVENTION REQUIRED ***')
10+
console.log('When prompted, you must manually click to open the browser and complete authentication')
11+
console.log('You have 60 seconds to complete this step\n\n')
12+
await loginToAmazonQ()
13+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import { Workbench, WebviewView } from 'vscode-extension-tester'
6+
7+
export interface TestContext {
8+
workbench?: Workbench
9+
webviewView?: WebviewView
10+
}
11+
12+
// arr to store shared context
13+
export const testContext: TestContext = {}

0 commit comments

Comments
 (0)