| 1 | import { By, WebElement, WebView } from "vscode-extension-tester"; |
| 2 | |
| 3 | export class SelectorUtils { |
| 4 | /** |
| 5 | * Finds a web element by its data-testid attribute within a WebView. |
| 6 | * @param view - The WebView to search within. |
| 7 | * @param testId - The data-testid value to search for. |
| 8 | * @returns A promise that resolves to the WebElement found. |
| 9 | */ |
| 10 | public static getElementByDataTestId( |
| 11 | view: WebView, |
| 12 | testId: string, |
| 13 | ): Promise<WebElement> { |
| 14 | return view.findWebElement(By.css(`[data-testid='${testId}']`)); |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Finds a web element by its aria-label attribute within a WebView. |
| 19 | * @param view - The WebView to search within. |
| 20 | * @param ariaLabel - The aria-label value to search for. |
| 21 | * @returns A promise that resolves to the WebElement found. |
| 22 | */ |
| 23 | public static getElementByAriaLabel( |
| 24 | view: WebView, |
| 25 | ariaLabel: string, |
| 26 | ): Promise<WebElement> { |
| 27 | return view.findWebElement(By.css(`[aria-label='${ariaLabel}']`)); |
| 28 | } |
| 29 | } |