Skip to content

Commit

Permalink
Add multipple breakpoints to editor
Browse files Browse the repository at this point in the history
  • Loading branch information
unsortedhashsets committed Aug 11, 2023
1 parent 9453808 commit 19ba24f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 30 deletions.
60 changes: 32 additions & 28 deletions page-objects/src/components/editor/TextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -203,7 +204,7 @@ export class TextEditor extends Editor {
found++;
lineNum = i + 1;
if (found >= occurrence) {
break;
break;
}
}
}
Expand All @@ -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);
Expand All @@ -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 '';
Expand All @@ -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;
Expand All @@ -275,7 +276,7 @@ export class TextEditor extends Editor {
* Get the selection block as a page object
* @returns Selection page object
*/
async getSelection(): Promise<Selection|undefined> {
async getSelection(): Promise<Selection | undefined> {
const selection = await this.findElements(TextEditor.locators.TextEditor.selection);
if (selection.length < 1) {
return undefined;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -386,7 +387,7 @@ export class TextEditor extends Editor {
async openContextMenu(): Promise<ContextMenu> {
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();
Expand All @@ -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();
}
Expand All @@ -412,7 +413,7 @@ export class TextEditor extends Editor {
const coords: number[] = [];
const statusBar = new StatusBar();
const coordinates = <RegExpMatchArray>(await statusBar.getCurrentPosition()).match(/\d+/g);
for(const c of coordinates) {
for (const c of coordinates) {
coords.push(+c);
}
return [coords[0], coords[1]];
Expand All @@ -427,21 +428,24 @@ export class TextEditor extends Editor {
async toggleBreakpoint(line: number): Promise<boolean> {
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;
Expand All @@ -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;
}
Expand All @@ -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 {
Expand Down Expand Up @@ -498,8 +502,8 @@ export class TextEditor extends Editor {
*/
async getCodeLens(indexOrTitle: number | string): Promise<CodeLens | undefined> {
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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -577,7 +581,7 @@ export class FindWidget extends AbstractElement {
async toggleReplace(replace: boolean): Promise<void> {
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);
Expand Down Expand Up @@ -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<string> {
async getReplaceText(): Promise<string> {
const replacePart = await this.findElement(FindWidget.locators.FindWidget.replacePart);
return await this.getInputText(replacePart);
}
Expand Down Expand Up @@ -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]];
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
14 changes: 12 additions & 2 deletions test/test-project/src/test/debug/debug-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down Expand Up @@ -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;
});
Expand Down

0 comments on commit 19ba24f

Please sign in to comment.