/** * Happens when you call a test from node directly (node myFile.js) instead of through the Testim CLI (testim run myFile.js) */ class StubError extends Error { constructor(name: string) { super(`Error calling ${name} stub. Codim needs to run through the Testim CLI`); } } /** * Represents the Testim Dev Kit step locator. * @see https://help.testim.io/docs/working-with-locators */ class TDKStepLocator { public elementLocator?: any; public selector?: string; public nthChildIndex?: number; public id?: string; public name?: string; public innerLocator?: TDKStepLocator; public parentLocator?: TDKStepLocator; public find(selector: any): TDKStepLocator { throw new StubError('TDKStepLocator.find'); } public nthChild(index: number): TDKStepLocator { throw new StubError('TDKStepLocator.nthChild'); } public childWithText(text: string): TDKStepLocator { throw new StubError('TDKStepLocator.childWithText'); } /** * Sets the locator confidence threshold * @param threshold the locator conidence score */ withConfidence(threshold: number): TDKStepLocator { throw new StubError('TDKStepLocator.withThreshold'); } } /** * Represents the options passed to a click. * @see https://help.testim.io/docs/click */ interface ClickOptions { button?: 'left' | 'right'; offset?: { x: number; y: number } } /** * Represents the return value from a getCookie or setCookie call. * @see https://help.testim.io/docs/get-cookie */ class CookieData { name?: string; value?: string; domain?: string; expires?: number; httpOnly? = true; secure? = false; path?: string; } /** * Represents an x/y point - passed to Drag and Drop */ interface Point { x: number; y: number; } /** * A CSS selector used to select an element. This is usually a string like `'.foo'` and the syntax is whatever * the browser and JSDOM's `document.querySelector` understand. * @see https://www.w3.org/TR/selectors-3/#selectors */ type Selector = string; /** * All Testim methods that work on an element work on either a Selector or TDKStepLocator */ type SelectParam = Selector | TDKStepLocator; /** * The options passed to a scrollToElement command * @see https://help.testim.io/docs/scroll-to-element */ interface ScrollOptions { scrollTarget?: SelectParam; } /** The options passed to a hover command * @see https://help.testim.io/docs/hover */ interface HoverOptions { offset?: { x: number; y: number }; } /** The options passed to a waitForCode command * @see https://help.testim.io/docs/wait-for-code */ interface WaitForCodeOptions { pollInterval: number; } /** The options passed to a resize command * @see https://help.testim.io/docs/resize */ interface ResizeOptions { width: number; height: number; } /** the options passed to a waitForElement command * @see https://help.testim.io/docs/wait-for-element */ interface WaitForElementOptions { checkVisibility?: boolean; } /** the options passed to a waitForText command * @see https://help.testim.io/docs/wait-for-text */ interface WaitForTextOptions { checkVisibility?: boolean; } interface Headers { [key: string]: string } type RequestMethods = 'GET' | 'POST' | 'PUT' | 'PATH' | 'DELETE' | 'COPY' | 'HEAD' | 'OPTIONS'; interface ApiCallOptions { method?: RequestMethods; headers?: Headers; body?: string; sendViaWebApp?: boolean; omitCookies?: boolean; } export enum GeneratedValueTypes { LettersOnly = 'Letters Only', NumbersOnly = 'Numbers Only', Mixed = 'Mixed' } /** * Clicks the given element on the screen, clicks on the element in its center by default. * @see https://help.testim.io/docs/click */ export async function click(selector: SelectParam, options: ClickOptions = {}): Promise { throw new StubError('click'); } /** * Clicks the given element on the screen, clicks on the element in its center by default. * @see https://help.testim.io/docs/dblclick */ export async function dblclick(selector: SelectParam, options: ClickOptions = {}): Promise { throw new StubError('dblclick'); } /** * Sleeps a specified duration. Basically the same as * const sleep = require('util').promisify(setTimeout); * Except that it adds a sleep step to the UI * @param ms milliseconds to sleep */ export async function sleep(ms: number): Promise { throw new StubError('sleep'); } /** * Api call */ export async function apiCall(url: string, options?: ApiCallOptions): Promise<{ statusCode: number; statusText: string; requestDuration: number; responseBody: any; responseHeaders: any }> { throw new StubError('apiCall'); } /** * Get latest download item work only in Chrome extension mode */ export async function downloadFile(): Promise<{ fileName: string; fileType: string; sizeInBytes: number; fileBlob: any }> { throw new StubError('downloadFile'); } /** * Generate random value letters/numbers/mixed */ export async function generateRandomValue(generatedLength = 12, valueType = GeneratedValueTypes.Mixed, prefixValue = ''): Promise { throw new StubError('generateRandomValue'); } /** * Generate Testim random email - PRO feature */ export async function generateTestimEmail(): Promise { throw new StubError('generateTestimEmail'); } /** * Get email messages from Testim email inbox - PRO feature */ export async function getTestimInbox(emailAddress: string): Promise { throw new StubError('getTestimInbox'); } /** * Get document element outer html */ export async function html(): Promise { throw new StubError('html'); } /** * This method used to simulate upload file on */ export async function inputFile(selector: SelectParam, inputFileUrls: string | string[]): Promise { throw new StubError('inputFile'); } /** * This method used to simulate drop file on drop zone */ export async function dropFile(selector: SelectParam, inputFileUrls: string | string[]): Promise { throw new StubError('dropFile'); } /** * Refresh current page */ export async function refresh(): Promise { throw new StubError('refresh'); } /** * Get current page title */ export async function title(): Promise { throw new StubError('title'); } /** * Get current page url */ export async function url(): Promise { throw new StubError('url'); } /** * This method is used to extract an element's text content. * @see https://help.testim.io/docs/text */ export async function text(selector: SelectParam): Promise { throw new StubError('text'); } /** * Scroll to a given element on the screen. * @see https://help.testim.io/docs/scroll-to-element */ export async function scrollToElement(selector: SelectParam, options: ScrollOptions = {}): Promise { throw new StubError('scrollToElement'); } /** * This method is used to set an element's text content. If the element already has text content it overrides it. * @see https://help.testim.io/docs/type */ export async function type(selector: SelectParam, textValue: string): Promise { throw new StubError('type'); } /** * This method is used to run custom JavaScript in the browser application page. This is useful as an escape hatch and in order to implement interactions that are not available out of the box with Testim or in order to interact with the page JavaScript. * @see https://help.testim.io/docs/evaluate */ export async function evaluate(fn: (...any: U) => R | Promise, ...parameters: U): Promise { throw new StubError('evaluate'); } /** * This method is used to execute an arbitrary command that runs in Node.js from within the test * @see https://help.testim.io/docs/cli-action */ export async function cliAction(fn: (...any: U) => R | Promise, ...parameters: U): Promise { throw new StubError('cliAction'); } /** * The go command navigates to a given web page in the controlled browser. * @see https://help.testim.io/docs/go */ export async function go(url: string): Promise { throw new StubError('go'); } /** * Sets a cookie on a given page. * @see https://help.testim.io/docs/set-cookie */ export async function setCookie(cookieData: CookieData): Promise { throw new StubError('setCookie'); } /** * Gets a cookie by a specific name. * @see https://help.testim.io/docs/get-cookie */ export async function getCookie(name: string): Promise { throw new StubError('getCookie'); } /** * Hovers over the given element on the screen, on the element center by default. * @see https://help.testim.io/docs/hover */ export async function hover(selector: SelectParam, options: HoverOptions): Promise { throw new StubError('hover'); } /** * This method checks that an element matching the given selector exists on the page * @see https://help.testim.io/docs/exists */ export async function exists(selector: SelectParam): Promise { throw new StubError('exists'); } /** * This method is used to check if a checkbox element is checked or not. * @see https://help.testim.io/docs/checkbox */ export async function checkbox(selector: SelectParam): Promise { throw new StubError('checkbox'); } /** * This method is used to check if a radio element is checked or not. * @see https://help.testim.io/docs/radio */ export async function radio(selector: SelectParam): Promise { throw new StubError('radio'); } /** * This method selects a given