diff --git a/page-objects/src/components/editor/TextEditor.ts b/page-objects/src/components/editor/TextEditor.ts index 24b8a2b84..83a4f37d6 100644 --- a/page-objects/src/components/editor/TextEditor.ts +++ b/page-objects/src/components/editor/TextEditor.ts @@ -7,12 +7,13 @@ import { ElementWithContexMenu } from "../ElementWithContextMenu"; import { AbstractElement } from "../AbstractElement"; import { Breakpoint } from "./Breakpoint"; -export class BreakpointError extends Error {} +export class BreakpointError extends Error { } /** * Page object representing the active text editor */ export class TextEditor extends Editor { + breakPoints: number[] = []; /** * Find whether the active editor has unsaved changes @@ -112,7 +113,7 @@ export class TextEditor extends Editor { await new Promise(res => setTimeout(res, 500)); const text = clipboard.readSync(); await inputarea.sendKeys(Key.UP); - if(originalClipboard.length > 0) { + if (originalClipboard.length > 0) { clipboard.writeSync(originalClipboard); } return text; @@ -136,7 +137,7 @@ export class TextEditor extends Editor { const inputarea = await this.findElement(TextEditor.locators.Editor.inputArea); clipboard.writeSync(text); await inputarea.sendKeys(Key.chord(TextEditor.ctlKey, 'a'), Key.chord(TextEditor.ctlKey, 'v')); - if(originalClipboard.length > 0) { + if (originalClipboard.length > 0) { clipboard.writeSync(originalClipboard); } if (formatText) { @@ -203,7 +204,7 @@ export class TextEditor extends Editor { found++; lineNum = i + 1; if (found >= occurrence) { - break; + break; } } } @@ -221,12 +222,12 @@ export class TextEditor extends Editor { if (lineNum < 1) { throw new Error(`Text '${text}' not found`); } - + const line = await this.getTextAtLine(lineNum); const column = line.indexOf(text) + 1; await this.moveCursor(lineNum, column); - + let actions = this.getDriver().actions(); await actions.clear(); actions.keyDown(Key.SHIFT); @@ -250,7 +251,7 @@ export class TextEditor extends Editor { // workaround issue https://github.com/redhat-developer/vscode-extension-tester/issues/835 // do not fail if clipboard is empty } - if(process.platform !== 'darwin') { + if (process.platform !== 'darwin') { const selection = await this.getSelection(); if (!selection) { return ''; @@ -265,7 +266,7 @@ export class TextEditor extends Editor { } await new Promise(res => setTimeout(res, 500)); const text = clipboard.readSync(); - if(originalClipboard.length > 0) { + if (originalClipboard.length > 0) { clipboard.writeSync(originalClipboard); } return text; @@ -275,7 +276,7 @@ export class TextEditor extends Editor { * Get the selection block as a page object * @returns Selection page object */ - async getSelection(): Promise { + async getSelection(): Promise { const selection = await this.findElements(TextEditor.locators.TextEditor.selection); if (selection.length < 1) { return undefined; @@ -328,7 +329,7 @@ export class TextEditor extends Editor { if (column < 1) { throw new Error(`Column number ${column} does not exist`); } - if(process.platform === 'darwin') { + if (process.platform === 'darwin') { const input = await new Workbench().openCommandPrompt(); await input.setText(`:${line},${column}`); await input.confirm(); @@ -386,7 +387,7 @@ export class TextEditor extends Editor { async openContextMenu(): Promise { await this.getDriver().actions().contextClick(this).perform(); const shadowRootHost = await this.enclosingItem.findElements(By.className('shadow-root-host')); - + if (shadowRootHost.length > 0) { let shadowRoot; const webdriverCapabilities = await (this.getDriver() as ChromiumWebDriver).getCapabilities(); @@ -398,7 +399,7 @@ export class TextEditor extends Editor { shadowRoot = await this.getDriver().executeScript('return arguments[0].shadowRoot', shadowRootHost[0]) as WebElement; return new ContextMenu(shadowRoot).wait(); } - + } return await super.openContextMenu(); } @@ -412,7 +413,7 @@ export class TextEditor extends Editor { const coords: number[] = []; const statusBar = new StatusBar(); const coordinates = (await statusBar.getCurrentPosition()).match(/\d+/g); - for(const c of coordinates) { + for (const c of coordinates) { coords.push(+c); } return [coords[0], coords[1]]; @@ -427,21 +428,24 @@ export class TextEditor extends Editor { async toggleBreakpoint(line: number): Promise { const margin = await this.findElement(TextEditor.locators.TextEditor.marginArea); const lineNum = await margin.findElement(TextEditor.locators.TextEditor.lineNumber(line)); - await this.getDriver().actions().move({origin: lineNum}).perform(); + await this.getDriver().actions().move({ origin: lineNum }).perform(); const lineOverlay = await margin.findElement(TextEditor.locators.TextEditor.lineOverlay(line)); const breakpointContainer = TextEditor.versionInfo.version >= '1.80.0' ? await this.findElement(By.className('glyph-margin-widgets')) : lineOverlay; const breakPoint = await breakpointContainer.findElements(TextEditor.locators.TextEditor.breakpoint.generalSelector); if (breakPoint.length > 0) { - await breakPoint[0].click(); - await new Promise(res => setTimeout(res, 200)); - return false; + if (this.breakPoints.indexOf(line) != -1) { + await breakPoint[this.breakPoints.indexOf(line)].click(); + await new Promise(res => setTimeout(res, 200)); + this.breakPoints.splice(this.breakPoints.indexOf(line), 1); + return false; + } } - const noBreak = await breakpointContainer.findElements(TextEditor.locators.TextEditor.debugHint); if (noBreak.length > 0) { await noBreak[0].click(); await new Promise(res => setTimeout(res, 200)); + this.breakPoints.push(line); return true; } return false; @@ -455,7 +459,7 @@ export class TextEditor extends Editor { const breakpointLocators = Breakpoint.locators.TextEditor.breakpoint; const breakpointContainer = TextEditor.versionInfo.version >= '1.80.0' ? await this.findElement(By.className('glyph-margin-widgets')) : this; const breakpoints = await breakpointContainer.findElements(breakpointLocators.pauseSelector); - + if (breakpoints.length === 0) { return undefined; } @@ -466,7 +470,7 @@ export class TextEditor extends Editor { // get parent let lineElement: WebElement; - if(TextEditor.versionInfo.version >= '1.80.0') { + if (TextEditor.versionInfo.version >= '1.80.0') { const styleTopAttr = await breakpoints[0].getCssValue('top'); lineElement = await this.findElement(TextEditor.locators.TextEditor.marginArea).findElement(By.xpath(`.//div[contains(@style, "${styleTopAttr}")]`)) } else { @@ -498,8 +502,8 @@ export class TextEditor extends Editor { */ async getCodeLens(indexOrTitle: number | string): Promise { const lenses = await this.getCodeLenses(); - - if (typeof(indexOrTitle) === 'string') { + + if (typeof (indexOrTitle) === 'string') { for (const lens of lenses) { const title = await lens.getText(); const match = title.match(indexOrTitle); @@ -527,7 +531,7 @@ class Selection extends ElementWithContexMenu { const ed = this.getEnclosingElement() as TextEditor; await this.getDriver().actions().contextClick(this).perform(); const shadowRootHost = await ed.getEnclosingElement().findElements(By.className('shadow-root-host')); - + if (shadowRootHost.length > 0) { let shadowRoot; const webdriverCapabilities = await (this.getDriver() as ChromiumWebDriver).getCapabilities(); @@ -577,7 +581,7 @@ export class FindWidget extends AbstractElement { async toggleReplace(replace: boolean): Promise { const btn = await this.findElement(FindWidget.locators.FindWidget.toggleReplace); const klass = await btn.getAttribute('class'); - + if (replace && klass.includes('collapsed') || !replace && !klass.includes('collapsed')) { await btn.sendKeys(Key.SPACE); const repl = await this.getDriver().wait(until.elementLocated(FindWidget.locators.FindWidget.replacePart), 2000); @@ -622,7 +626,7 @@ export class FindWidget extends AbstractElement { * Get text from Replace input box * @returns value of replace input as string */ - async getReplaceText(): Promise { + async getReplaceText(): Promise { const replacePart = await this.findElement(FindWidget.locators.FindWidget.replacePart); return await this.getInputText(replacePart); } @@ -675,7 +679,7 @@ export class FindWidget extends AbstractElement { const text = await count.getText(); if (text.includes('No results')) { - return [0,0]; + return [0, 0]; } const numbers = text.split(' of '); return [+numbers[0], +numbers[1]]; @@ -713,7 +717,7 @@ export class FindWidget extends AbstractElement { await this.toggleControl('Preserve Case', 'replace', toggle); } - private async toggleControl(title: string, part: 'find'|'replace', toggle: boolean) { + private async toggleControl(title: string, part: 'find' | 'replace', toggle: boolean) { let element!: WebElement; if (part === 'find') { element = await this.findElement(FindWidget.locators.FindWidget.findPart); @@ -730,7 +734,7 @@ export class FindWidget extends AbstractElement { } } - private async clickButton(title: string, part: 'find'|'replace'|'close') { + private async clickButton(title: string, part: 'find' | 'replace' | 'close') { let element!: WebElement; if (part === 'find') { element = await this.findElement(FindWidget.locators.FindWidget.findPart); diff --git a/test/test-project/src/test/debug/debug-test.ts b/test/test-project/src/test/debug/debug-test.ts index 6cbbf985e..edb4d0a81 100644 --- a/test/test-project/src/test/debug/debug-test.ts +++ b/test/test-project/src/test/debug/debug-test.ts @@ -68,7 +68,12 @@ describe('Debugging', function () { await new Promise(res => setTimeout(res, 5000)); }); - it('set a breakpoint', async function () { + it('set first breakpoint', async function () { + const result = await editor.toggleBreakpoint(line + 1); + expect(result).to.be.true; + }); + + it('set second breakpoint', async function () { const result = await editor.toggleBreakpoint(line); expect(result).to.be.true; }); @@ -221,7 +226,12 @@ describe('Debugging', function () { await editor.getDriver().wait(until.elementIsNotVisible(debugBar)); }); - it('remove the breakpoint', async function () { + it('remove the second breakpoint', async function () { + const result = await editor.toggleBreakpoint(line + 1); + expect(result).to.be.false; + }); + + it('remove the fisrt breakpoint', async function () { const result = await editor.toggleBreakpoint(line); expect(result).to.be.false; });