1- import { Workbench , By , WebviewView , WebElement } from 'vscode-extension-tester'
2- import { until } from 'selenium-webdriver'
1+ /*!
2+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+ * SPDX-License-Identifier: Apache-2.0
4+ */
35
4- describe ( 'Amazon Q E2E UI Test' , function ( ) {
6+ import { Workbench , By , EditorView , WebviewView , WebElement } from 'vscode-extension-tester'
7+
8+ describe ( 'Amazon Q Login Flow' , function ( ) {
59 // need this timeout because Amazon Q takes awhile to load
6- this . timeout ( 150000 )
10+ this . timeout ( 30000 )
711 let webviewView : WebviewView
8- let workbench : Workbench
12+
913 // NOTE: I tested all the timeouts and they are necessary for the webview to load properly
1014 before ( async function ( ) {
11- this . timeout ( 120000 )
12- workbench = new Workbench ( )
15+ const workbench = new Workbench ( )
1316 await workbench . executeCommand ( 'Amazon Q: Open Chat' )
1417
15- await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) )
18+ await new Promise ( ( resolve ) => setTimeout ( resolve , 15000 ) )
1619 webviewView = new WebviewView ( )
1720 await webviewView . switchToFrame ( )
21+ } )
1822
19- const driver = webviewView . getDriver ( )
20- await driver . wait ( until . elementsLocated ( By . css ( '.selectable-item' ) ) , 30000 )
23+ after ( async ( ) => {
24+ await webviewView . switchBack ( )
25+ try {
26+ await new EditorView ( ) . closeAllEditors ( )
27+ } catch { }
28+ } )
29+
30+ it ( 'Should click through the Amazon Q login screen' , async ( ) => {
31+ // Select company account option
2132 const selectableItems = await webviewView . findWebElements ( By . css ( '.selectable-item' ) )
33+ console . log ( typeof selectableItems )
2234 if ( selectableItems . length === 0 ) {
2335 throw new Error ( 'No selectable login options found' )
2436 }
2537
38+ // Find and click company account
2639 const companyItem = await findItemByText ( selectableItems , 'Company account' )
2740 await companyItem . click ( )
41+ await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) )
42+
43+ // Click first continue button
2844 const signInContinue = await webviewView . findWebElement ( By . css ( '#connection-selection-continue-button' ) )
2945 await signInContinue . click ( )
46+ await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) )
47+
48+ // Enter start URL
3049 const startUrlInput = await webviewView . findWebElement ( By . id ( 'startUrl' ) )
3150 await startUrlInput . clear ( )
3251 await startUrlInput . sendKeys ( 'https://amzn.awsapps.com/start' )
52+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) )
53+
54+ // Click second continue button
3355 const UrlContinue = await webviewView . findWebElement ( By . css ( 'button.continue-button.topMargin' ) )
3456 await UrlContinue . click ( )
35- console . log ( 'Waiting for manual authentication...' )
36- await new Promise ( ( resolve ) => setTimeout ( resolve , 12000 ) )
37- console . log ( 'Manual authentication should be done' )
38- await webviewView . switchBack ( )
39-
40- // AFTER AUTHENTICATION WE MUST RELOAD THE WEBVIEW BECAUSE MULTIPLE WEVIEWS CANNOT BE READ AT THE SAME TIME
41- const editorView = workbench . getEditorView ( )
42- console . log ( 'editorview successfully created' )
43- await editorView . closeAllEditors ( )
44- console . log ( 'Closed all editors' )
45- await new Promise ( ( resolve ) => setTimeout ( resolve , 1500 ) )
46- webviewView = new WebviewView ( )
47- console . log ( 'Reopened webview view' )
48- await webviewView . switchToFrame ( )
49- await new Promise ( ( resolve ) => setTimeout ( resolve , 1200 ) )
50- } )
51-
52- after ( async ( ) => {
53- // TO-DO: Close all the chat windows after the test is done so that when the test runs again it does not have memory
54- // from the previous test
55- await webviewView . switchBack ( )
56- } )
57-
58- it ( 'Chat Prompt Test' , async ( ) => {
59- // Debug consoles to look at the html of the current webview
60- // const chatTitle = await webviewView.getDriver().getTitle()
61- // const chatHtml = (await webviewView.getDriver().executeScript('return document.body.innerHTML')) as string
62- // console.log('Chat Title:', chatTitle)
63- // console.log('Chat HTML:', chatHtml.replace(/></g, '>\n<'))
64- const driver = webviewView . getDriver ( )
65- await driver . wait ( until . elementsLocated ( By . css ( '.mynah-chat-prompt-input' ) ) , 300000 )
66- // In order to test the chat prompt, we need to find the input field and send keys
67- const chatInput = await webviewView . findWebElement ( By . css ( '.mynah-chat-prompt-input' ) )
68- await chatInput . sendKeys ( 'Hello, Amazon Q!' )
69- await driver . wait ( until . elementsLocated ( By . css ( '.mynah-chat-prompt-button' ) ) , 300000 )
70- // In order to submit the chat prompt, we need to find the send button and click it
71- const sendButton = await webviewView . findWebElement ( By . css ( '.mynah-chat-prompt-button' ) )
72- await sendButton . click ( )
73-
74- // TO-DO: Find out a way to check if the chat response is the expected response
75- await new Promise ( ( resolve ) => setTimeout ( resolve , 12000 ) )
76- // Wait for response using conversation container check
77- const responseReceived = await waitForChatResponse ( webviewView )
78- if ( ! responseReceived ) {
79- throw new Error ( 'Chat response not received within timeout' )
80- }
81-
82- console . log ( 'Chat response detected successfully' )
57+ await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) )
8358 } )
8459
8560 // Helper to find item by text content
@@ -95,33 +70,4 @@ describe('Amazon Q E2E UI Test', function () {
9570 }
9671 throw new Error ( `Item with text "${ text } " not found` )
9772 }
98-
99- /* My Idea: Basically the conversation container's css is .mynah-chat-items-conversation-container
100- Instead of looking for a specific message like how we look for other elements in the test,
101- I can check how many elements there are in our specific conversation container. If there is 2 elements,
102- we can assume that the chat response has been generated. The challenge is, we must grab the latest
103- conversation container, as there can be multiple conversations in the webview.
104- */
105- async function waitForChatResponse ( webview : WebviewView , timeout = 30000 ) : Promise < boolean > {
106- const startTime = Date . now ( )
107-
108- while ( Date . now ( ) - startTime < timeout ) {
109- const conversationContainers = await webview . findWebElements (
110- By . css ( '.mynah-chat-items-conversation-container' )
111- )
112-
113- if ( conversationContainers . length > 0 ) {
114- const latestContainer = conversationContainers [ conversationContainers . length - 1 ]
115-
116- const chatItems = await latestContainer . findElements ( By . css ( '*' ) )
117-
118- if ( chatItems . length >= 2 ) {
119- return true
120- }
121- }
122- await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) )
123- }
124-
125- return false
126- }
12773} )
0 commit comments