diff --git a/page-objects/src/components/editor/SettingsEditor.ts b/page-objects/src/components/editor/SettingsEditor.ts index 64d512a75..af485e06e 100644 --- a/page-objects/src/components/editor/SettingsEditor.ts +++ b/page-objects/src/components/editor/SettingsEditor.ts @@ -31,6 +31,46 @@ export class SettingsEditor extends Editor { await searchBox.sendKeys(Key.chord(SettingsEditor.ctlKey, 'a')); await searchBox.sendKeys(`${category}: ${title}`); + let setting!: Setting; + const items = await this._getSettingItems(); + + for (const item of items) { + try { + return await (await this.createSetting(item, title, category)).wait(); + } catch (err) { + } + } + return setting; + } + + /** + * Search for a setting with a precise ID. + * Returns an appropriate Setting object if it exists, + * undefined otherwise. + * + * @param id of the setting + * @returns Promise resolving to a Setting object if found, undefined otherwise + */ + async findSettingByID(id: string): Promise { + const searchBox = await this.findElement(SettingsEditor.locators.Editor.inputArea); + await searchBox.sendKeys(Key.chord(SettingsEditor.ctlKey, 'a')); + await searchBox.sendKeys(id); + + let setting!: Setting; + const items = await this._getSettingItems(); + + for (const item of items) { + try { + const category = (await (await item.findElement(SettingsEditor.locators.SettingsEditor.settingCategory)).getText()).replace(':', ''); + const title = await (await item.findElement(SettingsEditor.locators.SettingsEditor.settingLabel)).getText(); + return await (await this.createSetting(item, title, category)).wait(); + } catch (err) { + } + } + return setting; + } + + private async _getSettingItems(): Promise { const count = await this.findElement(SettingsEditor.locators.SettingsEditor.itemCount); let textCount = await count.getText(); @@ -44,18 +84,9 @@ export class SettingsEditor extends Editor { return true; }); - let setting!: Setting; - const items = await this.findElements(SettingsEditor.locators.SettingsEditor.itemRow); - - for (const item of items) { - try { - return (await this.createSetting(item, title, category)).wait(); - } catch (err) { - } - } - return setting; + return await this.findElements(SettingsEditor.locators.SettingsEditor.itemRow); } - + /** * Switch between settings perspectives * Works only if your vscode instance has both user and workspace settings available diff --git a/test/test-project/src/test/editor/settingsEditor-test.ts b/test/test-project/src/test/editor/settingsEditor-test.ts index 949b94a10..54519ac02 100644 --- a/test/test-project/src/test/editor/settingsEditor-test.ts +++ b/test/test-project/src/test/editor/settingsEditor-test.ts @@ -1,98 +1,104 @@ import { expect } from 'chai'; import { SettingsEditor, Workbench, EditorView, ComboSetting, TextSetting, CheckboxSetting } from 'vscode-extension-tester'; -describe('SettingsEditor', () => { +describe('Settings Editor', function () { let editor: SettingsEditor; - before(async function() { + before(async function () { this.timeout(10000); editor = await new Workbench().openSettings(); }); - after(async () => { + after(async function () { await new EditorView().closeAllEditors(); }); - it('findSetting works', async function() { + it('findSetting works', async function () { this.timeout(15000); const setting = await editor.findSetting('Title Bar Style', 'Window'); expect(setting).not.undefined; }); - it('findSetting works for nested configurations', async function() { + it('findSetting by ID works', async function () { + this.timeout(15000); + const setting = await editor.findSettingByID('testProject.general.helloWorld'); + expect(setting).not.undefined; + }); + + it('findSetting works for nested configurations', async function () { this.timeout(15000); const setting = await editor.findSetting('Hello World', 'Test Project', 'General'); expect(setting).not.undefined; }); - describe('combo setting', () => { + describe('combo setting', function () { let setting: ComboSetting; - before(async function() { + before(async function () { this.timeout(15000); setting = await editor.findSetting('Title Bar Style', 'Window') as ComboSetting; }); - it('getTitle works', async () => { + it('getTitle works', async function () { const title = await setting.getTitle(); expect(title).equals('Title Bar Style'); }); - it('getCategory works', async () => { + it('getCategory works', async function () { const cat = await setting.getCategory(); expect(cat).equals('Window:'); }); - it('getValue works', async () => { + it('getValue works', async function () { const value = await setting.getValue(); expect(value).equals('custom'); }); - it('getValues works', async () => { + it('getValues works', async function () { const values = await setting.getValues(); expect(values).contains.members(['native', 'custom']); }); - it('getDescription works', async () => { + it('getDescription works', async function () { const desc = await setting.getDescription(); expect(desc).not.empty; }); }); - describe('text setting', () => { + describe('text setting', function () { let setting: TextSetting; - before(async function() { + before(async function () { this.timeout(15000); setting = await editor.findSetting('Auto Save Delay', 'Files') as TextSetting; }); - it('getValue works', async () => { + it('getValue works', async function () { const value = await setting.getValue(); expect(+value).greaterThan(0); }); - it('setValue works', async () => { + it('setValue works', async function () { const newVal = '1001'; await setting.setValue(newVal); expect(await setting.getValue()).equals(newVal); }); }); - describe('checkbox setting', () => { + describe('checkbox setting', function () { let setting: CheckboxSetting; - before(async function() { + before(async function () { this.timeout(15000); setting = await editor.findSetting('Code Lens', 'Editor') as CheckboxSetting; }); - it('getValue works', async () => { + it('getValue works', async function () { const value = await setting.getValue(); expect(value).is.true; }); - it('setValue works', async () => { + it('setValue works', async function () { await setting.setValue(false); expect(await setting.getValue()).is.false; await setting.setValue(true);