@freelancercom/blue-harvest
Version:
protractor helpers
157 lines (156 loc) • 6.25 kB
TypeScript
/**
* Generic actions for interacting with the Pantheon UI in integration tests.
* Every action will automatically wait for the relevant elements to be
* in view and capable of interaction, and will retry upon failure.
*
* Examples of usage:
* see('Sandwich Order Form');
* under('Cheese').see('Provelone');
* under('Cheese').not.see('American');
* click('Order Sandwich');
*/
import { WebElement } from 'protractor';
import { BrowserSideOptions } from './find';
import { FlexibleLocator, Position, PositionalLocator } from './locator_types';
/**
* An enum declaring how slow a test should be.
* Don't use this directly.
*/
export declare enum Slowness {
FAST = 0,
REGULAR = 1,
SLOW = 2,
AGONIZINGLY_SLOW = 3
}
/**
* Information necessary to determine how to find an element.
*/
export declare class ActionContext {
readonly locators: ReadonlyArray<PositionalLocator>;
readonly slow: Slowness;
readonly wantZero: boolean;
static default(): ActionContext;
private constructor();
addLocator(position: Position, locator: FlexibleLocator): ActionContext;
setSlow(newSlow: Slowness): ActionContext;
setNot(newNot: boolean): ActionContext;
}
/**
* A ChainedAction captures information on how to interact with the page
* under test. The class contain modifier methods, e.g. leftOf and below,
* which return a new ChainedAction with additional context. It also contains
* action methods, e.g. see and click, which perform the action and complete
* the chain.
*/
export declare class ChainedAction {
private readonly context;
constructor(context: ActionContext);
not: {
see: Function;
};
/**
* Specify that the element to be found must be rendered below AND in the same
* vertical space as the element found by this locator.
*/
under(locator: FlexibleLocator): ChainedAction;
/**
* Specify that the element to be found must be rendered below the element
* found by this locator.
*/
below(locator: FlexibleLocator): ChainedAction;
/**
* Specify that the element to be found must be rendered inside the element
* found by this locator.
*/
inside(locator: FlexibleLocator): ChainedAction;
/**
* Specify that the element to be found must rendered to the right of the
* element found by this locator.
*/
rightOf(locator: FlexibleLocator): ChainedAction;
/**
* Specify that the element to be found must be rendered to the left of the
* element found by the locator.
*/
leftOf(locator: FlexibleLocator): ChainedAction;
private notSee;
private description;
private pretty;
private timeout;
private getElement;
/**
* Returns a WebElement from the given locator and satisfying the
* current context, or null if no element was found.
* Only use this method if you need to use the returned WebElement, otherwise
* prefer `see`.
* Note that this method, unlike other actions, does not throw if the element
* is not found.
*/
find(locator: FlexibleLocator, options?: BrowserSideOptions): Promise<WebElement | null>;
/**
* Returns true if an element with the given locator and satisfying the
* current context exists. Throws an error if an element cannot be found.
*/
see(locator: FlexibleLocator, options?: BrowserSideOptions): Promise<boolean>;
/**
* Finds and clicks on the first element with the given locator and satisfying
* the current context. Throws an error if an element cannot be found.
*/
click(locator: FlexibleLocator): Promise<void>;
/**
* Do a long press on the first element with the given locator and satisfying
* the current context. Throws an error if the element cannot be found.
* This function is used in mobile testing with simulated mobile device.
*/
longPress(locator: FlexibleLocator): Promise<void>;
/**
* Taps on the first element with the given locator and satisfying
* the current context. Throws an error if the element cannot be found.
* This function is used in mobile testing with simulated mobile device.
*/
tap(locator: FlexibleLocator): Promise<void>;
/**
* Mouse over the first element with the given locator and satisfying the
* current context. Throws an error if an element cannot be found.
*/
mouseOver(locator: FlexibleLocator): Promise<void>;
/**
* Type the given filepath into the first input[type="file"] element
* satisfying the current context, allowing to upload files through standard
* HTML file inputs
*/
uploadFile(filepath: string): Promise<void>;
}
export declare const find: any;
export declare const see: (locator: FlexibleLocator, options?: BrowserSideOptions) => Promise<boolean>;
export declare const click: (locator: FlexibleLocator) => Promise<void>;
export declare const longPress: (locator: FlexibleLocator) => Promise<void>;
export declare const tap: (locator: FlexibleLocator) => Promise<void>;
export declare const mouseOver: (locator: FlexibleLocator) => Promise<void>;
export declare const uploadFile: (filepath: string) => Promise<void>;
export declare const not: {
see: (locator: FlexibleLocator, options?: BrowserSideOptions) => Promise<boolean>;
};
export declare const fast: ChainedAction;
export declare const slow: ChainedAction;
export declare const agonizinglySlow: ChainedAction;
export declare const under: (locator: FlexibleLocator) => ChainedAction;
export declare const leftOf: (locator: FlexibleLocator) => ChainedAction;
export declare const rightOf: (locator: FlexibleLocator) => ChainedAction;
export declare const below: (locator: FlexibleLocator) => ChainedAction;
export declare const inside: (locator: FlexibleLocator) => ChainedAction;
/**
* Types text into the browser (into the currently active element).
*
* Usage:
* below('Description').click(by.css('textarea'));
* type('some text');
*/
export declare function type(text: string): Promise<void>;
/**
* Navigate to a page in Pantheon.
* Usage:
* go('/compute/instances');
* go('/start?tutorial=quickstart');
*/
export declare function go(path: string): Promise<void>;