| 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 getToolsTab(view: WebView) { |
| 51 | return SelectorUtils.getElementByDataTestId(view, "tab-tools"); |
| 52 | } |
| 53 | |
| 54 | public static getBackButton(view: WebView) { |
| 55 | return SelectorUtils.getElementByDataTestId(view, "tab-back"); |
| 56 | } |
| 57 | |
| 58 | public static getToolPolicyButton(view: WebView, toolName: string) { |
| 59 | return SelectorUtils.getElementByDataTestId( |
| 60 | view, |
| 61 | `tool-policy-item-${toolName}`, |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | public static getModelDropdownButton(view: WebView) { |
| 66 | return SelectorUtils.getElementByDataTestId(view, "model-select-button"); |
| 67 | } |
| 68 | |
| 69 | public static getModeDropdownButton(view: WebView) { |
| 70 | return SelectorUtils.getElementByDataTestId(view, "mode-select-button"); |
| 71 | } |
| 72 | |
| 73 | public static getFirstContextProviderDropdownItem(view: WebView) { |
| 74 | return SelectorUtils.getElementByDataTestId( |
| 75 | view, |
| 76 | "context-provider-dropdown-item", |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | public static getContextItemsPeek(view: WebView) { |
| 81 | return SelectorUtils.getElementByDataTestId(view, "context-items-peek"); |
| 82 | } |
| 83 | |
| 84 | public static getFirstContextItemsPeekItem(view: WebView) { |
| 85 | return SelectorUtils.getElementByDataTestId( |
| 86 | view, |
| 87 | "context-items-peek-item", |
| 88 | ); |
| 89 | } |
| 90 | |
| 91 | public static getRulesPeek(view: WebView) { |
| 92 | return SelectorUtils.getElementByDataTestId(view, "rules-peek"); |
| 93 | } |
| 94 | |
| 95 | public static getFirstRulesPeekItem(view: WebView) { |
| 96 | return SelectorUtils.getElementByDataTestId(view, "rules-peek-item"); |
| 97 | } |
| 98 | |
| 99 | public static getNthHistoryTableRow(view: WebView, index: number) { |
| 100 | return SelectorUtils.getElementByDataTestId(view, `history-row-${index}`); |
| 101 | } |
| 102 | |
| 103 | public static getNthMessageDeleteButton(view: WebView, index: number) { |
| 104 | return SelectorUtils.getElementByDataTestId(view, `delete-button-${index}`); |
| 105 | } |
| 106 | |
| 107 | public static getModelDropdownOption(view: WebView, option: string) { |
| 108 | return view.findWebElement( |
| 109 | By.xpath(`//*[@role="listbox"]//*[contains(text(), "${option}")]`), |
| 110 | ); |
| 111 | } |
| 112 | |
| 113 | public static getModeDropdownOption(view: WebView, option: string) { |
| 114 | return view.findWebElement( |
| 115 | By.xpath(`//*[@role="listbox"]//*[contains(text(), "${option}")]`), |
| 116 | ); |
| 117 | } |
| 118 | |
| 119 | public static getOnboardingTabButton(view: WebView, title: string) { |
| 120 | return SelectorUtils.getElementByDataTestId( |
| 121 | view, |
| 122 | `onboarding-tab-${title}`, |
| 123 | ); |
| 124 | } |
| 125 | |
| 126 | public static getBestChatApiKeyInput(view: WebView) { |
| 127 | return SelectorUtils.getElementByDataTestId( |
| 128 | view, |
| 129 | "best-chat-api-key-input", |
| 130 | ); |
| 131 | } |
| 132 | |
| 133 | public static getBestAutocompleteApiKeyInput(view: WebView) { |
| 134 | return SelectorUtils.getElementByDataTestId( |
| 135 | view, |
| 136 | "best-autocomplete-api-key-input", |
| 137 | ); |
| 138 | } |
| 139 | |
| 140 | public static getTutorialCard(view: WebView) { |
| 141 | return SelectorUtils.getElementByDataTestId(view, "tutorial-card"); |
| 142 | } |
| 143 | |
| 144 | public static getThreadMessageByText(view: WebView, text: string) { |
| 145 | return view.findWebElement( |
| 146 | By.xpath(`//*[@class="thread-message"]//*[contains(text(), "${text}")]`), |
| 147 | ); |
| 148 | } |
| 149 | |
| 150 | public static getHistoryNavButton(view: WebView) { |
| 151 | return SelectorUtils.getElementByAriaLabel(view, "View History"); |
| 152 | } |
| 153 | |
| 154 | public static getSettingsNavButton(view: WebView) { |
| 155 | return SelectorUtils.getElementByAriaLabel(view, "Open Settings"); |
| 156 | } |
| 157 | |
| 158 | public static getNewSessionNavButton(view: WebView) { |
| 159 | return SelectorUtils.getElementByAriaLabel(view, "New Session"); |
| 160 | } |
| 161 | |
| 162 | public static async getInputBoxCodeBlockAtIndex( |
| 163 | view: WebView, |
| 164 | index: number, |
| 165 | ) { |
| 166 | const firstInputField = await this.getMessageInputFieldAtIndex(view, index); |
| 167 | |
| 168 | const codeBlockElement = await firstInputField.findElement( |
| 169 | By.xpath(".//code"), |
| 170 | ); |
| 171 | |
| 172 | return codeBlockElement; |
| 173 | } |
| 174 | |
| 175 | public static getContinueExtensionBadge(view: WebView) { |
| 176 | return SelectorUtils.getElementByAriaLabel(view, "Continue"); |
| 177 | } |
| 178 | } |