Skip to content
This repository was archived by the owner on Jul 2, 2026. It is now read-only.

Commit e15565b

Browse files
committed
fix: adding support for vscode-version and fallback selector
1 parent 8dfea18 commit e15565b

2 files changed

Lines changed: 81 additions & 6 deletions

File tree

src/system-operations/settings.ts

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
import { By, Setting, SettingsEditor } from 'vscode-extension-tester';
8+
import { By, Setting, SettingsEditor, WebElement } from 'vscode-extension-tester';
99
import { executeQuickPick } from '../ui-interaction/commandPrompt';
1010
import { Duration, findElementByText, log, pause } from '../core/miscellaneous';
1111
import { getBrowser } from '../ui-interaction/workbench';
@@ -145,16 +145,80 @@ export async function isBooleanSettingEnabled(
145145
}
146146

147147
/**
148-
* Sets the value of a specific setting in the settings editor.
149-
*
148+
* Sets the value of a specified setting in VSCode.
150149
* @param id - The unique identifier of the setting to be updated.
151150
* @param value - The new value to set for the specified setting.
152151
* @param isWorkspace - True if the setting is a workspace setting; false if it's a user setting.
153152
* @returns A promise that resolves when the setting value has been updated.
154153
*/
155154
export const setSettingValue = async (id: string, value: string | boolean, isWorkspace: boolean): Promise<void> => {
156155
await (isWorkspace ? inWorkspaceSettings() : inUserSettings());
157-
const settingsEditor = new SettingsEditor();
158-
const logLevelSetting = await settingsEditor.findSettingByID(id);
159-
await logLevelSetting?.setValue(value);
156+
try {
157+
// Try the original implementation using RedHat page objects
158+
const settingsEditor = new SettingsEditor();
159+
const logLevelSetting = await settingsEditor.findSettingByID(id);
160+
await logLevelSetting?.setValue(value);
161+
} catch (error) {
162+
// Fallback for VS Code 1.90.0+ where .native-edit-context selector doesn't exist
163+
log(`Primary findSettingByID failed, using fallback implementation for VS Code 1.90.0+: ${error}`);
164+
165+
try {
166+
const browser = getBrowser();
167+
168+
// Alternative selectors for the search input in newer VS Code versions
169+
const searchSelectors = [
170+
'.inputarea.monaco-mouse-cursor-text',
171+
'input[placeholder*="Search settings"]',
172+
];
173+
174+
let searchInput: WebElement | undefined;
175+
for (const selector of searchSelectors) {
176+
try {
177+
searchInput = await browser.findElement(By.css(selector));
178+
break;
179+
} catch {
180+
// Try next selector
181+
}
182+
}
183+
184+
if (!searchInput) {
185+
throw new Error('Could not find settings search input with any known selector');
186+
}
187+
188+
// Clear and search for the setting
189+
await searchInput.clear();
190+
await searchInput.sendKeys(id);
191+
await pause(Duration.seconds(1));
192+
193+
// Find the setting by its title (last part of the ID)
194+
const title = id.split('.').pop();
195+
const settingElement = await findElementByText('div', 'textContent', title);
196+
197+
if (!settingElement) {
198+
throw new Error(`Could not find setting element for: ${title}`);
199+
}
200+
201+
// Find the input/control within the setting element and set the value
202+
const parent = await settingElement.findElement(By.xpath('..'));
203+
const settingContainer = await parent.findElement(By.xpath('..'));
204+
205+
if (typeof value === 'boolean') {
206+
const checkbox = await settingContainer.findElement(By.css('input[type="checkbox"]'));
207+
const isChecked = await checkbox.isSelected();
208+
if (isChecked !== value) {
209+
await checkbox.click();
210+
}
211+
} else {
212+
const textInput = await settingContainer.findElement(By.css('input[type="text"], textarea'));
213+
await textInput.clear();
214+
await textInput.sendKeys(value.toString());
215+
}
216+
217+
log(`Successfully set setting ${id} to ${value} using fallback implementation`);
218+
219+
} catch (fallbackError) {
220+
log(`Both primary and fallback implementations failed: ${fallbackError}`);
221+
throw new Error(`Failed to set setting ${id}: ${fallbackError}`);
222+
}
223+
}
160224
};

src/test-setup-and-runner.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,9 +823,16 @@ const argv = yargs(hideBin(process.argv))
823823
description: 'Path to workspace directory',
824824
demandOption: false
825825
})
826+
.option('vscode-version', {
827+
alias: 'v',
828+
type: 'string',
829+
description: 'VS Code version to use (e.g., latest, stable, 1.85.0)',
830+
demandOption: false
831+
})
826832
.help().argv as {
827833
spec: string | string[] | undefined;
828834
workspacePath?: string;
835+
vscodeVersion?: string;
829836
};
830837

831838
// Create test config from command line arguments
@@ -836,6 +843,10 @@ if (argv.workspacePath) {
836843
testConfig.extensionsPath = path.join(argv.workspacePath, 'extensions');
837844
}
838845

846+
if (argv.vscodeVersion) {
847+
testConfig.codeVersion = argv.vscodeVersion;
848+
}
849+
839850
if (argv.spec) {
840851
log(`Spec passed in: ${argv.spec}`);
841852
}

0 commit comments

Comments
 (0)