-
Notifications
You must be signed in to change notification settings - Fork 731
fix(amazonq): XPath Selector for pinContextHelpers and fixing PinContext ability to run in full test suite #7928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,25 +36,23 @@ export async function clickPinContextButton(webview: WebviewView): Promise<void> | |
| * @returns Promise<boolean> Returns the items as a WebElement List and the labels in a string array | ||
| */ | ||
| export async function getPinContextMenuItems(webview: WebviewView): Promise<{ items: WebElement[]; labels: string[] }> { | ||
| const menuList = await waitForElement(webview, By.css('.mynah-detailed-list-items-block')) | ||
| // TODO: Fix the need for a sleep function to be required at all. | ||
| await sleep(100) | ||
| const menuListItems = await menuList.findElements(By.css('.mynah-detailed-list-item.mynah-ui-clickable-item')) | ||
| const items = await webview.findElements( | ||
| By.xpath(`//div[contains(@class, 'mynah-detailed-list-item') and contains(@class, 'mynah-ui-clickable-item')]`) | ||
| ) | ||
|
|
||
| if (menuListItems.length === 0) { | ||
| if (items.length === 0) { | ||
| throw new Error('No pin context menu items found') | ||
| } | ||
|
|
||
| const labels: string[] = [] | ||
| for (const item of menuListItems) { | ||
| const textWrapper = await item.findElement(By.css('.mynah-detailed-list-item-text')) | ||
| const nameElement = await textWrapper.findElement(By.css('.mynah-detailed-list-item-name')) | ||
| for (const item of items) { | ||
| const nameElement = await item.findElement(By.css('.mynah-detailed-list-item-description')) | ||
| const labelText = await nameElement.getText() | ||
| labels.push(labelText) | ||
| console.log('Menu item found:', labelText) | ||
| } | ||
|
|
||
| return { items: menuListItems, labels } | ||
| return { items, labels } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -66,49 +64,38 @@ export async function getPinContextMenuItems(webview: WebviewView): Promise<{ it | |
| * NOTE: To find all possible text labels, you can call getPinContextMenuItems | ||
| */ | ||
| export async function clickPinContextMenuItem(webview: WebviewView, itemName: string): Promise<void> { | ||
| const menuList = await waitForElement(webview, By.css('.mynah-detailed-list-items-block')) | ||
| await sleep(100) | ||
| const menuListItems = await menuList.findElements(By.css('.mynah-detailed-list-item.mynah-ui-clickable-item')) | ||
| for (const item of menuListItems) { | ||
| const textWrapper = await item.findElement(By.css('.mynah-detailed-list-item-text')) | ||
| const nameElement = await textWrapper.findElement(By.css('.mynah-detailed-list-item-name')) | ||
| const labelText = await nameElement.getText() | ||
|
|
||
| if (labelText === itemName) { | ||
| console.log(`Clicking Pin Context menu item: ${itemName}`) | ||
| await item.click() | ||
| return | ||
| } | ||
| } | ||
|
|
||
| throw new Error(`Pin Context menu item not found: ${itemName}`) | ||
| const item = await waitForElement( | ||
| webview, | ||
| By.xpath( | ||
| `//div[contains(@class, 'mynah-detailed-list-item') and contains(@class, 'mynah-ui-clickable-item')]//div[contains(@class, 'mynah-detailed-list-item-name') and text()='${itemName}']` | ||
| ) | ||
| ) | ||
| console.log(`Clicking Pin Context menu item: ${itemName}`) | ||
| await item.click() | ||
| } | ||
| /** | ||
| * Lists all the possible Sub-menu items in the console. | ||
| * @param webview The WebviewView instance | ||
| * @returns Promise<boolean> Returns the items as a WebElement List and the labels in a string array | ||
| */ | ||
| export async function getSubMenuItems(webview: WebviewView): Promise<{ items: WebElement[]; labels: string[] }> { | ||
| const menuList = await waitForElement(webview, By.css('.mynah-detailed-list-items-block')) | ||
| await sleep(100) | ||
| const menuListItems = await menuList.findElements(By.css('.mynah-detailed-list-item.mynah-ui-clickable-item')) | ||
| const items = await webview.findElements( | ||
| By.xpath(`//div[contains(@class, 'mynah-detailed-list-item') and contains(@class, 'mynah-ui-clickable-item')]`) | ||
| ) | ||
|
|
||
| if (menuListItems.length === 0) { | ||
| if (items.length === 0) { | ||
| throw new Error('No sub-menu items found') | ||
| } | ||
|
|
||
| const labels: string[] = [] | ||
| for (const item of menuListItems) { | ||
| const textWrapper = await item.findElement( | ||
| By.css('.mynah-detailed-list-item-text.mynah-detailed-list-item-text-direction-row') | ||
| ) | ||
| const nameElement = await textWrapper.findElement(By.css('.mynah-detailed-list-item-name')) | ||
| for (const item of items) { | ||
| const nameElement = await item.findElement(By.css('.mynah-detailed-list-item-name')) | ||
| const labelText = await nameElement.getText() | ||
| labels.push(labelText) | ||
| console.log('Menu item found:', labelText) | ||
| } | ||
|
|
||
| return { items: menuListItems, labels } | ||
| return { items, labels } | ||
| } | ||
| /** | ||
| * Clicks a specific item in the Sub-Menu by its label text | ||
|
|
@@ -119,22 +106,13 @@ export async function getSubMenuItems(webview: WebviewView): Promise<{ items: We | |
| * NOTE: To find all possible text labels, you can call getPinContextMenuItems | ||
| */ | ||
| export async function clickSubMenuItem(webview: WebviewView, itemName: string): Promise<void> { | ||
| const menuList = await waitForElement(webview, By.css('.mynah-detailed-list-items-block')) | ||
| await sleep(100) | ||
| const menuListItems = await menuList.findElements(By.css('.mynah-detailed-list-item.mynah-ui-clickable-item')) | ||
| for (const item of menuListItems) { | ||
| const textWrapper = await item.findElement( | ||
| By.css('.mynah-detailed-list-item-text.mynah-detailed-list-item-text-direction-row') | ||
| await sleep(0) | ||
| const item = await waitForElement( | ||
| webview, | ||
| By.xpath( | ||
| `//div[contains(@class, 'mynah-detailed-list-item') and contains(@class, 'mynah-ui-clickable-item')]//div[contains(@class, 'mynah-detailed-list-item-name') and text()='${itemName}']` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these strings are gnarly, how does one find this? Are they querying the css based on these attributes?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think they are pretty complex, but I do think this is the best/reliable way to snipe the correct element. Yup, XPath is querying based on the css class attributes. I think in general we can use css selectors, but for this specific instance it may be best to use our XPath. You could find this by using the printElementHTML Function and dumping the entire overlay to figure out what you need if building/debugging a XPath selector.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow cool! Maybe in the future we can build/find a nicer interface on top of these queries? This looks good for now though, nice find!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I agree, I think building a helper function for XPaths could be useful, I think it has a lot of moving parameters but definitely doable. |
||
| ) | ||
| const nameElement = await textWrapper.findElement(By.css('.mynah-detailed-list-item-name')) | ||
| const labelText = await nameElement.getText() | ||
|
|
||
| if (labelText === itemName) { | ||
| console.log(`Clicking Pin Context menu item: ${itemName}`) | ||
| await item.click() | ||
| return | ||
| } | ||
| } | ||
|
|
||
| throw new Error(`Pin Context menu item not found: ${itemName}`) | ||
| ) | ||
| console.log(`Clicking Pin Context menu item: ${itemName}`) | ||
| await item.click() | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| */ | ||
| import '../utils/setup' | ||
| import { WebviewView, By } from 'vscode-extension-tester' | ||
| import { closeAllTabs, dismissOverlayIfPresent } from '../utils/cleanupUtils' | ||
| import { closeAllTabs } from '../utils/cleanupUtils' | ||
| import { testContext } from '../utils/testContext' | ||
| import { clickPinContextButton, clickPinContextMenuItem, clickSubMenuItem } from '../helpers/pinContextHelper' | ||
| import { waitForElement } from '../utils/generalUtils' | ||
|
|
@@ -19,13 +19,12 @@ describe('Amazon Q Pin Context Functionality', function () { | |
| }) | ||
|
|
||
| afterEach(async () => { | ||
| await dismissOverlayIfPresent(webviewView) | ||
| await closeAllTabs(webviewView) | ||
| }) | ||
| it('Allows User to Add File Context', async () => { | ||
| await clickPinContextButton(webviewView) | ||
| await clickPinContextMenuItem(webviewView, 'Files') | ||
| await clickPinContextMenuItem(webviewView, 'Active file') | ||
| await clickSubMenuItem(webviewView, 'Active file') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does the File test work properly now? or do we still have to skip it? |
||
| }) | ||
| it('Allows User to Pin Workspace Context', async () => { | ||
| await clickPinContextButton(webviewView) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is needed, but maybe it worth adding a comment about why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, good thought.