playwright-fluent
Version:
Fluent API around playwright
309 lines (308 loc) • 13.4 kB
TypeScript
import { PlaywrightFluent } from '../fluent-api';
import { ClickOptions, HoverOptions, Point, SelectOptionInfo, SerializableDOMRect, VerboseOptions } from '../actions';
import { ElementHandle } from 'playwright';
export declare class SelectorFluent {
private chainingHistory;
private pwf;
private actionInfos;
private getActionFrom;
private executeActions;
/**
* Executes the search.
* The result may differ from one execution to another
* especially if targeted element is rendered lately because its data is based on some backend response.
*
* @returns {Promise<ElementHandle<Element>[]>} will return an empty array if no elements are found, will return all found elements otherwise.
* @memberof SelectorFluent
*/
getAllHandles(): Promise<ElementHandle<Element>[]>;
/**
* Iterate over each found selector
* The index is the 1-based index of the selector in the list of selectors
* @param {(selector: SelectorFluent, index: number) => Promise<void>} func
* @returns {Promise<void>}
* @memberof SelectorFluent
* @example
* const rows = p.selector('[role="row"]');
* await rows.forEach(async (row) => {
* const checkbox = row.find('input[type="checkbox"]');
* await p.hover(checkbox).check(checkbox);
* });
*/
forEach(func: (selector: SelectorFluent, index: number) => Promise<void>): Promise<void>;
/**
* Obsolete: please use the getHandle() method.
* Executes the search and returns the first found element.
* The result may differ from one execution to another
* especially if targeted element is rendered lately because its data is based on some backend response.
*
* @returns {Promise<ElementHandle<Element> | null>} will return null if no elements are found, will return first found element otherwise.
* @memberof SelectorFluent
* @obsolete
*/
getFirstHandleOrNull(): Promise<ElementHandle<Element> | null>;
/**
* Executes the search and returns the first found element.
* The result may differ from one execution to another
* especially if targeted element is rendered lately because its data is based on some backend response.
*
* @returns {Promise<ElementHandle<Element> | null>} will return null if no elements are found, will return first found element otherwise.
* @memberof SelectorFluent
*/
getHandle(): Promise<ElementHandle<Element> | null>;
/**
* Gets the number of found elements.
* The result may differ from one execution to another
* especially if targeted element is rendered lately because its data is based on some backend response.
*
* @returns {Promise<number>} will return 0 if no elements are found.
* @memberof SelectorFluent
*/
count(): Promise<number>;
/**
*
*/
constructor(selector: string, pwf: PlaywrightFluent, stringifiedState?: string);
toString(): string;
private createSelectorFrom;
find(selector: string): SelectorFluent;
/**
* Finds, from previous search, all elements whose innerText contains the specified text
*
* @param {string} text
* @returns {SelectorFluent}
* @memberof SelectorFluent
*/
withText(text: string): SelectorFluent;
/**
* Finds, from previous search, all elements whose innerText match exactly the specified text.
* Use that method when you need to find elements with empty content.
* @param {string} text
* @returns {SelectorFluent}
* @memberof SelectorFluent
*/
withExactText(text: string): SelectorFluent;
/**
* Finds, from previous search, all elements whose value contains the specified text
*
* @param {string} text
* @returns {SelectorFluent}
* @memberof SelectorFluent
*/
withValue(text: string): SelectorFluent;
/**
* Finds, from previous search, all elements whose placeholder contains the specified text
*
* @param {string} text
* @returns {SelectorFluent}
* @memberof SelectorFluent
*/
withPlaceholder(text: string): SelectorFluent;
parent(): SelectorFluent;
nextSibling(): SelectorFluent;
previousSibling(): SelectorFluent;
/**
* Takes the nth element found at the previous step
*
* @param {number} index : 1-based index
* @returns {SelectorFluent}
* @memberof SelectorFluent
* @example
* nth(1): take the first element found at previous step.
* nth(-1): take the last element found at previous step.
*/
nth(index: number): SelectorFluent;
/**
* Checks if selector exists.
* The result may differ from one execution to another
* especially if targeted element is rendered lately because its data is based on some backend response.
* So the disability status is the one known when executing this method.
*
* @returns {Promise<boolean>}
* @memberof SelectorFluent
*/
exists(): Promise<boolean>;
/**
* Checks if selector is not in the DOM.
* The result may differ from one execution to another
* especially if targeted element is rendered lately because its data is based on some backend response.
* So the existence status is the one known when executing this method.
*
* @returns {Promise<boolean>}
* @memberof SelectorFluent
*/
doesNotExist(): Promise<boolean>;
/**
* Checks if the selector is visible.
* If the selector targets multiple DOM elements, this check is done only on the first one found.
* The result may differ from one execution to another
* especially if targeted element is rendered lately because its data is based on some backend response.
* So the visibilty status is the one known when executing this method.
* @param {Partial<VerboseOptions>} [options=defaultVerboseOptions]
* @returns {Promise<boolean>}
* @memberof SelectorFluent
*/
isVisible(options?: Partial<VerboseOptions>): Promise<boolean>;
/**
* Checks that the selector is not visible.
* If the selector targets multiple DOM elements, this check is done only on the first one found.
* The result may differ from one execution to another
* especially if targeted element is rendered lately because its data is based on some backend response.
* So the visibilty status is the one known when executing this method.
* @param {Partial<VerboseOptions>} [options=defaultVerboseOptions]
* @returns {Promise<boolean>}
* @memberof SelectorFluent
*/
isNotVisible(options?: Partial<VerboseOptions>): Promise<boolean>;
/**
* Checks if the selector is enabled.
* If the selector targets multiple DOM elements, this check is done only on the first one found.
* The result may differ from one execution to another
* especially if targeted element is rendered lately because its data is based on some backend response.
* So the enability status is the one known when executing this method.
* @param {Partial<VerboseOptions>} [options=defaultVerboseOptions]
* @returns {Promise<boolean>}
* @memberof SelectorFluent
*/
isEnabled(options?: Partial<VerboseOptions>): Promise<boolean>;
/**
* Checks if the selector is disabled.
* If the selector targets multiple DOM elements, this check is done only on the first one found.
* The result may differ from one execution to another
* especially if targeted element is rendered lately because its data is based on some backend response.
* So the disability status is the one known when executing this method.
*
* @param {Partial<VerboseOptions>} [options=defaultVerboseOptions]
* @returns {Promise<boolean>}
* @memberof SelectorFluent
*/
isDisabled(options?: Partial<VerboseOptions>): Promise<boolean>;
/**
* Checks if the selector is read-only.
* If the selector targets multiple DOM elements, this check is done only on the first one found.
* The result may differ from one execution to another
* especially if targeted element is rendered lately because its data is based on some backend response.
* So the disability status is the one known when executing this method.
*
* @param {Partial<VerboseOptions>} [options=defaultVerboseOptions]
* @returns {Promise<boolean>}
* @memberof SelectorFluent
*/
isReadOnly(options?: Partial<VerboseOptions>): Promise<boolean>;
/**
* Checks if the selector is not read-only.
* If the selector targets multiple DOM elements, this check is done only on the first one found.
* The result may differ from one execution to another
* especially if targeted element is rendered lately because its data is based on some backend response.
* So the disability status is the one known when executing this method.
*
* @param {Partial<VerboseOptions>} [options=defaultVerboseOptions]
* @returns {Promise<boolean>}
* @memberof SelectorFluent
*/
isNotReadOnly(options?: Partial<VerboseOptions>): Promise<boolean>;
innerText(): Promise<string | undefined | null>;
value(): Promise<string | undefined | null>;
classList(): Promise<string[]>;
getAttribute(attributeName: string): Promise<string | null>;
/**
* Get the placeholder content
*
* @returns {(Promise<string | null>)}
* @memberof SelectorFluent
*/
placeholder(): Promise<string | null>;
/**
* Get the client rectangle of the selector
*
* @returns {(Promise<SerializableDOMRect | null>)}
* @memberof SelectorFluent
*/
clientRectangle(): Promise<SerializableDOMRect | null>;
/**
* Get the position of the center of selector's bounding box.
*
* @returns {(Promise<Point | null>)}
* @memberof SelectorFluent
*/
position(): Promise<Point | null>;
/**
* Get the position of the left centered point of the selector's bounding box.
*
* @returns {(Promise<Point | null>)}
* @memberof SelectorFluent
*/
leftPosition(): Promise<Point | null>;
/**
* Get the position of the right centered point of the selector's bounding box.
*
* @returns {(Promise<Point | null>)}
* @memberof SelectorFluent
*/
rightPosition(): Promise<Point | null>;
/**
* Checks that selector has the an attribute with an expected value
* If the selector targets multiple DOM elements, this check is done only on the first one found.
* The result may differ from one execution to another
* especially if targeted element is rendered lately because its data is based on some backend response.
*
* @param {string} attributeName
* @param {string} expectedAttributeValue
* @returns {Promise<boolean>}
* @memberof SelectorFluent
*/
hasAttributeWithValue(attributeName: string, expectedAttributeValue: string): Promise<boolean>;
/**
* Checks that selector has the specified class
* If the selector targets multiple DOM elements, this check is done only on the first one found.
* The result may differ from one execution to another
* especially if targeted element is rendered lately because its data is based on some backend response.
*
* @param {string} expectedClass
* @returns {Promise<boolean>}
* @memberof SelectorFluent
*/
hasClass(expectedClass: string): Promise<boolean>;
/**
* Checks that selector does not have the specified class
* If the selector targets multiple DOM elements, this check is done only on the first one found.
* The result may differ from one execution to another
* especially if targeted element is rendered lately because its data is based on some backend response.
*
* @param {string} expectedClass
* @returns {Promise<boolean>}
* @memberof SelectorFluent
*/
doesNotHaveClass(expectedClass: string): Promise<boolean>;
/**
* Checks that the selector is checked.
* If the selector targets multiple DOM elements, this check is done only on the first one found.
* The result may differ from one execution to another
* especially if targeted element is rendered lately because its data is based on some backend response.
* So the checked status is the one known when executing this method.
*
* @param {Partial<VerboseOptions>} [options=defaultVerboseOptions]
* @returns {Promise<boolean>}
* @memberof SelectorFluent
*/
isChecked(options?: Partial<VerboseOptions>): Promise<boolean>;
isUnchecked(options?: Partial<VerboseOptions>): Promise<boolean>;
options(): Promise<SelectOptionInfo[]>;
allSelectedOptions(): Promise<SelectOptionInfo[]>;
selectedOption(): Promise<SelectOptionInfo | undefined>;
/**
* hover over selector
* @param {Partial<HoverOptions>} [options=defaultHoverOptions]
* @returns {Promise<void>}
* @memberof SelectorFluent
*/
hover(options?: Partial<HoverOptions>): Promise<void>;
/**
* click on selector
*
* @param {Partial<ClickOptions>} [options=defaultClickOptions]
* @returns {Promise<void>}
* @memberof SelectorFluent
*/
click(options?: Partial<ClickOptions>): Promise<void>;
}