| 1 | import { By, WebDriver, WebView } from "vscode-extension-tester"; |
| 2 | |
| 3 | import { SelectorUtils } from "./SelectorUtils"; |
| 4 | |
| 5 | export class GUISelectors { |
| 6 | public static getDescription(view: WebView) { |
| 7 | return view.findWebElement(By.xpath("//*[contains(text(), 'quickly')]")); |
| 8 | } |
| 9 | |
| 10 | public static getMessageInputFields(view: WebView) { |
| 11 | return view.findWebElements(By.className("tiptap")); |
| 12 | } |
| 13 | |
| 14 | public static async getMessageInputFieldAtIndex( |
| 15 | view: WebView, |
| 16 | index: number, |
| 17 | ) { |
| 18 | const elements = await this.getMessageInputFields(view); |
| 19 | return elements[index]; |
| 20 | } |
| 21 | |
| 22 | public static getAllIframes(driver: WebDriver) { |
| 23 | return driver.findElements(By.css("iframe")); |
| 24 | } |
| 25 | |
| 26 | public static getReactIframe(driver: WebDriver) { |
| 27 | return driver.findElement(By.css("iframe")); |
| 28 | } |
| 29 | |
| 30 | public static getSubmitInputButton(view: WebView) { |
| 31 | return SelectorUtils.getElementByDataTestId(view, "submit-input-button"); |
| 32 | } |
| 33 | |
| 34 | public static getAcceptToolCallButton(view: WebView) { |
| 35 | return view.findWebElement( |
| 36 | By.css("[data-testid*='accept-tool-call-button']"), |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | public static getRejectToolCallButton(view: WebView) { |
| 41 | return view.findWebElement( |
| 42 | By.css("[data-testid*='reject-tool-call-button']"), |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | public static getToolCallStatusMessage(view: WebView) { |
| 47 | return SelectorUtils.getElementByDataTestId(view, "tool-call-title"); |
| 48 | } |
| 49 | |
| 50 | public static getToolButton(view: WebView) { |
| 51 | return SelectorUtils.getElementByDataTestId( |
| 52 | view, |
| 53 | `block-settings-toolbar-icon-tools`, |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | public static getToolPolicyButton(view: WebView, toolName: string) { |
| 58 | return SelectorUtils.getElementByDataTestId( |
| 59 | view, |
| 60 | `tool-policy-item-${toolName}`, |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | public static getModelDropdownButton(view: WebView) { |
| 65 | return SelectorUtils.getElementByDataTestId(view, "model-select-button"); |
| 66 | } |
| 67 | |
| 68 | public static getModeDropdownButton(view: WebView) { |
| 69 | return SelectorUtils.getElementByDataTestId(view, "mode-select-button"); |
| 70 | } |
| 71 | |
| 72 | public static getFirstContextProviderDropdownItem(view: WebView) { |
| 73 | return SelectorUtils.getElementByDataTestId( |
| 74 | view, |
| 75 | "context-provider-dropdown-item", |
| 76 | ); |
| 77 | } |
| 78 | |
| 79 | public static getContextItemsPeek(view: WebView) { |
| 80 | return SelectorUtils.getElementByDataTestId(view, "context-items-peek"); |
| 81 | } |
| 82 | |
| 83 | public static getFirstContextItemsPeekItem(view: WebView) { |
| 84 | return SelectorUtils.getElementByDataTestId( |
| 85 | view, |
| 86 | "context-items-peek-item", |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | public static getRulesPeek(view: WebView) { |
| 91 | return SelectorUtils.getElementByDataTestId(view, "rules-peek"); |
| 92 | } |
| 93 | |
| 94 | public static getFirstRulesPeekItem(view: WebView) { |
| 95 | return SelectorUtils.getElementByDataTestId(view, "rules-peek-item"); |
| 96 | } |
| 97 | |
| 98 | public static getNthHistoryTableRow(view: WebView, index: number) { |
| 99 | return SelectorUtils.getElementByDataTestId(view, `history-row-${index}`); |
| 100 | } |
| 101 | |
| 102 | public static getNthMessageDeleteButton(view: WebView, index: number) { |
| 103 | return SelectorUtils.getElementByDataTestId(view, `delete-button-${index}`); |
| 104 | } |
| 105 | |
| 106 | public static getModelDropdownOption(view: WebView, option: string) { |
| 107 | return view.findWebElement( |
| 108 | By.xpath(`//*[@role="listbox"]//*[contains(text(), "${option}")]`), |
| 109 | ); |
| 110 | } |
| 111 | |
| 112 | public static getModeDropdownOption(view: WebView, option: string) { |
| 113 | return view.findWebElement( |
| 114 | By.xpath(`//*[@role="listbox"]//*[contains(text(), "${option}")]`), |
| 115 | ); |
| 116 | } |
| 117 | |
| 118 | public static getOnboardingTabButton(view: WebView, title: string) { |
| 119 | return SelectorUtils.getElementByDataTestId( |
| 120 | view, |
| 121 | `onboarding-tab-${title}`, |
| 122 | ); |
| 123 | } |
| 124 | |
| 125 | public static getBestChatApiKeyInput(view: WebView) { |
| 126 | return SelectorUtils.getElementByDataTestId( |
| 127 | view, |
| 128 | "best-chat-api-key-input", |
| 129 | ); |
| 130 | } |
| 131 | |
| 132 | public static getBestAutocompleteApiKeyInput(view: WebView) { |
| 133 | return SelectorUtils.getElementByDataTestId( |
| 134 | view, |
| 135 | "best-autocomplete-api-key-input", |
| 136 | ); |
| 137 | } |
| 138 | |
| 139 | public static getTutorialCard(view: WebView) { |
| 140 | return SelectorUtils.getElementByDataTestId(view, "tutorial-card"); |
| 141 | } |
| 142 | |
| 143 | public static getThreadMessageByText(view: WebView, text: string) { |
| 144 | return view.findWebElement( |
| 145 | By.xpath(`//*[@class="thread-message"]//*[contains(text(), "${text}")]`), |
| 146 | ); |
| 147 | } |
| 148 | |
| 149 | public static getHistoryNavButton(view: WebView) { |
| 150 | return SelectorUtils.getElementByAriaLabel(view, "View History"); |
| 151 | } |
| 152 | |
| 153 | public static getNewSessionNavButton(view: WebView) { |
| 154 | return SelectorUtils.getElementByAriaLabel(view, "New Session"); |
| 155 | } |
| 156 | |
| 157 | public static async getInputBoxCodeBlockAtIndex( |
| 158 | view: WebView, |
| 159 | index: number, |
| 160 | ) { |
| 161 | const firstInputField = await this.getMessageInputFieldAtIndex(view, index); |
| 162 | |
| 163 | const codeBlockElement = await firstInputField.findElement( |
| 164 | By.xpath(".//code"), |
| 165 | ); |
| 166 | |
| 167 | return codeBlockElement; |
| 168 | } |
| 169 | |
| 170 | public static getContinueExtensionBadge(view: WebView) { |
| 171 | return SelectorUtils.getElementByAriaLabel(view, "Continue"); |
| 172 | } |
| 173 | } |