UNPKG

@redhat-developer/page-objects

Version:

Page Object API implementation for a VS Code editor used by ExTester framework.

353 lines (352 loc) 12.8 kB
/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License", destination); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { ContentAssist, ContextMenu, InputBox } from '../..'; import { WebElement } from 'selenium-webdriver'; import { Editor } from './Editor'; import { ElementWithContextMenu } from '../ElementWithContextMenu'; import { AbstractElement } from '../AbstractElement'; import { Breakpoint } from './Breakpoint'; export declare class BreakpointError extends Error { } /** * Page object representing the active text editor */ export declare class TextEditor extends Editor { breakPoints: number[]; /** * Find whether the active editor has unsaved changes * @returns Promise resolving to true/false */ isDirty(): Promise<boolean>; /** * Saves the active editor * @returns Promise resolving when ctrl+s is invoked */ save(): Promise<void>; /** * Open the Save as prompt * * @returns InputBox serving as a simple file dialog */ saveAs(): Promise<InputBox>; /** * Retrieve the Uri of the file opened in the active editor * @returns Promise resolving to editor's underlying Uri */ getFileUri(): Promise<string>; /** * Retrieve the path to the file opened in the active editor * @returns Promise resolving to editor's underlying file path */ getFilePath(): Promise<string>; /** * Open/Close the content assistant at the current position in the editor by sending the default * keyboard shortcut signal * @param open true to open, false to close * @returns Promise resolving to ContentAssist object when opening, void otherwise */ toggleContentAssist(open: boolean): Promise<ContentAssist | void>; /** * Get all text from the editor * @returns Promise resolving to editor text */ getText(): Promise<string>; /** * Replace the contents of the editor with a given text * @param text text to type into the editor * @param formatText format the new text, default false * @returns Promise resolving once the new text is copied over */ setText(text: string, formatText?: boolean): Promise<void>; /** * Deletes all text within the editor * @returns Promise resolving once the text is deleted */ clearText(): Promise<void>; /** * Get text from a given line * @param line number of the line to retrieve * @returns Promise resolving to text at the given line number */ getTextAtLine(line: number): Promise<string>; /** * Replace the contents of a line with a given text * @param line number of the line to edit * @param text text to set at the line * @returns Promise resolving when the text is typed in */ setTextAtLine(line: number, text: string): Promise<void>; /** * Get line number that contains the given text. Not suitable for multi line inputs. * * @param text text to search for * @param occurrence select which occurrence of the search text to look for in case there are multiple in the document, defaults to 1 (the first instance) * * @returns Number of the line that contains the start of the given text. -1 if no such text is found. * If occurrence number is specified, searches until it finds as many instances of the given text. * Returns the line number that holds the last occurrence found this way. */ getLineOfText(text: string, occurrence?: number): Promise<number>; /** * Find and select a given text. Not usable for multi line selection. * * @param text text to select * @param occurrence specify which occurrence of text to select if multiple are present in the document */ selectText(text: string, occurrence?: number): Promise<void>; /** * Get the text that is currently selected as string */ getSelectedText(): Promise<string>; /** * Get the selection block as a page object * @returns Selection page object */ getSelection(): Promise<Selection | undefined>; openFindWidget(): Promise<FindWidget>; /** * Add the given text to the given coordinates * @param line number of the line to type into * @param column number of the column to start typing at * @param text text to add * @returns Promise resolving when the text is typed in */ typeTextAt(line: number, column: number, text: string): Promise<void>; /** * Type given text at the current coordinates * @param text text to type * @returns promise resolving when the text is typed in */ typeText(text: string): Promise<void>; /** * Set cursor to given position using command prompt :Ln,Col * @param line line number to set to * @param column column number to set to * @returns Promise resolving when the cursor has reached the given coordinates */ setCursor(line: number, column: number, timeout?: number): Promise<void>; /** * Get indentation from the status bar for the currently opened text editor * @returns \{ string, number \} object which contains label and value of indentation */ getIndentation(): Promise<{ label: string; value: number; }>; /** * Move the cursor to the given coordinates * @param line line number to move to * @param column column number to move to * @returns Promise resolving when the cursor has reached the given coordinates */ moveCursor(line: number, column: number, timeout?: number): Promise<void>; /** * (private) Move the cursor to the given line coordinate * @param inputArea WebElement of an editor input area * @param line line number to move to * @returns Promise resolving when the cursor has reached the given line coordinate */ private moveCursorToLine; /** * (private) Move the cursor to the given column coordinate * @param inputArea WebElement of an editor input area * @param column column number to move to * @returns Promise resolving when the cursor has reached the given column coordinate */ private moveCursorToColumn; /** * (private) Check if the cursor is already on requested line * @param line line number to check against current cursor position * @returns true / false */ private isLine; /** * (private) Check if the cursor is already on requested column * @param column column number to check against current cursor position * @returns true / false */ private isColumn; /** * (private) Dynamic waiting for cursor position movements * @param line line number to wait * @param column column number to wait * @param timeout default timeout */ private waitForCursorPositionAt; /** * (private) Dynamic waiting for cursor position movements at line * @param line line number to wait * @param timeout */ private waitForCursorPositionAtLine; /** * (private) Dynamic waiting for cursor position movements at column * @param column column number to wait * @param timeout */ private waitForCursorPositionAtColumn; /** * Get number of lines in the editor * @returns Promise resolving to number of lines */ getNumberOfLines(): Promise<number>; /** * Use the built-in 'Format Document' option to format the text * @returns Promise resolving when the Format Document command is invoked */ formatDocument(): Promise<void>; openContextMenu(): Promise<ContextMenu>; /** * Get the cursor's coordinates as an array of two numbers: `[line, column]` * * **Caution** line & column coordinates do not start at `0` but at `1`! */ getCoordinates(): Promise<[number, number]>; /** * Toggle breakpoint on a given line * * @param line target line number * @returns promise resolving to True when a breakpoint was added, False when removed */ toggleBreakpoint(line: number): Promise<boolean>; /** * Get paused breakpoint if available. Otherwise, return undefined. * @returns promise which resolves to either Breakpoint page object or undefined */ getPausedBreakpoint(): Promise<Breakpoint | undefined>; /** * Get paused breakpoint on line if available. Otherwise, return undefined. * @param line number of the line to retrieve * @returns promise which resolves to either Breakpoint page object or undefined */ getBreakpoint(line: number): Promise<Breakpoint | undefined>; /** * Get all breakpoints. * @returns List of Breakpoints. */ getBreakpoints(): Promise<Breakpoint[]>; /** * Get all code lenses within the editor * @returns list of CodeLens page objects */ getCodeLenses(): Promise<CodeLens[]>; /** * Get a code lens based on title, or zero based index * * @param indexOrTitle zero based index (counting from the top of the editor), or partial title of the code lens * @returns CodeLens object if such a code lens exists, undefined otherwise */ getCodeLens(indexOrTitle: number | string): Promise<CodeLens | undefined>; } /** * Text selection block */ declare class Selection extends ElementWithContextMenu { constructor(el: WebElement, editor: TextEditor); openContextMenu(): Promise<ContextMenu>; } /** * Page object for Code Lens inside a text editor */ export declare class CodeLens extends AbstractElement { /** * Get tooltip of the code lens * @returns tooltip as string */ getTooltip(): Promise<string>; } /** * Text Editor's Find Widget */ export declare class FindWidget extends AbstractElement { constructor(element: WebElement, editor: TextEditor); /** * Toggle between find and replace mode * @param replace true for replace, false for find */ toggleReplace(replace: boolean): Promise<void>; /** * Set text in the search box * @param text text to fill in */ setSearchText(text: string): Promise<void>; /** * Get text from Find input box * @returns value of find input as string */ getSearchText(): Promise<string>; /** * Set text in the replace box. Will toggle replace mode on if called in find mode. * @param text text to fill in */ setReplaceText(text: string): Promise<void>; /** * Get text from Replace input box * @returns value of replace input as string */ getReplaceText(): Promise<string>; /** * Click 'Next match' */ nextMatch(): Promise<void>; /** * Click 'Previous match' */ previousMatch(): Promise<void>; /** * Click 'Replace'. Only works in replace mode. */ replace(): Promise<void>; /** * Click 'Replace All'. Only works in replace mode. */ replaceAll(): Promise<void>; /** * Close the widget. */ close(): Promise<void>; /** * Get the number of results as an ordered pair of numbers * @returns pair in form of [current result index, total number of results] */ getResultCount(): Promise<[number, number]>; /** * Toggle the search to match case * @param toggle true to turn on, false to turn off */ toggleMatchCase(toggle: boolean): Promise<void>; /** * Toggle the search to match whole words * @param toggle true to turn on, false to turn off */ toggleMatchWholeWord(toggle: boolean): Promise<void>; /** * Toggle the search to use regular expressions * @param toggle true to turn on, false to turn off */ toggleUseRegularExpression(toggle: boolean): Promise<void>; /** * Toggle the replace to preserve case * @param toggle true to turn on, false to turn off */ togglePreserveCase(toggle: boolean): Promise<void>; private toggleControl; private clickButton; private setText; private getInputText; } export {};