import "chai"; import { By, WebElement } from "selenium-webdriver"; import { Awaitable, Definition, Element, ELEMENT_KEY, NightwatchAPI } from "./index"; export interface NightwatchExpectResult { value: null; returned: 1; } export interface ExpectLanguageChains { // The following are provided as chainable getters // to improve the readability of your assertions. // They do not provide testing capabilities and // the order is not important. to: T; be: T; been: T; is: T; that: T; which: T; and: T; has: T; have: T; with: T; at: T; does: T; of: T; same: T; /** * Negates any of assertions following in the chain. */ not: T; /** * Sets the `deep` flag, later to be used by the `equal`. */ deep: T; } export interface ExpectEqual { (value: any): Awaitable; } export interface ExpectInclude { (value: string): Awaitable; } export interface ExpectMatch { (regexp: RegExp): Awaitable; } export interface ExpectStartWith { (value: string): Awaitable; } export interface ExpectEndWith { (value: string): Awaitable; } export interface ExpectAssertions extends ExpectLanguageChains { equal: ExpectEqual; equals: ExpectEqual; eq: ExpectEqual; include: ExpectInclude; includes: ExpectInclude; contain: ExpectInclude; contains: ExpectInclude; match: ExpectMatch; matches: ExpectMatch; startWith: ExpectStartWith; startsWith: ExpectStartWith; endWith: ExpectEndWith; endsWith: ExpectEndWith; before: (ms: number) => Awaitable; after: (ms: number) => Awaitable; // Assertion methods returning NightwatchAPI toEqual: (value: any) => NightwatchAPI; toBe: (value: any) => NightwatchAPI; toContain: (value: string) => NightwatchAPI; toMatch: (regexp: RegExp) => NightwatchAPI; toEndWith: (value: string) => NightwatchAPI; } export interface ExpectCookie extends ExpectAssertions {} export interface ExpectElement extends ExpectAssertions { /** * Checks if the type (i.e. tag name) of a specified element is of an expected value. */ a(type: string, message?: string): Awaitable; /** * Checks if the type (i.e. tag name) of a specified element is of an expected value. */ an(type: string, message?: string): Awaitable; /** * Property that checks if an element is active in the DOM. */ active: Awaitable; /** * Checks if a given attribute of an element exists and optionally if it has the expected value. */ attribute(attribute: string, message?: string): Awaitable; /** * Checks a given css property of an element exists and optionally if it has the expected value. */ css(property: string, message?: string): Awaitable; /** * Property that checks if an element is currently enabled. */ enabled: Awaitable; /** * Property that checks if an element is present in the DOM. */ present: Awaitable; /** * Checks if a given DOM property of an element has the expected value. * For all the available DOM element properties, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element). */ property(name: string, message?: string): Awaitable; /** * Property that checks if an OPTION element, or an INPUT element of type checkbox or radio button is currently selected. */ selected: Awaitable; /** * Property that retrieves the text contained by an element. Can be chained to check if contains/equals/matches the specified text or regex. */ text: Awaitable; /** * Property that retrieves the value (i.e. the value attributed) of an element. Can be chained to check if contains/equals/matches the specified text or regex. */ value: Awaitable; /** * Property that asserts the visibility of a specified element. */ visible: Awaitable; /** * Checks if the specified DOM property of a given element is present and has the expected value. * For all the available DOM element properties, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element). */ domProperty(propertyName: string, message?: string): Awaitable; } export interface ExpectSection extends ExpectAssertions, ExpectElement {} export interface ExpectElements extends ExpectAssertions { /** * Checks if the number of elements specified by a selector is equal or not to a given value. */ count: this; } export interface ExpectTitle extends ExpectAssertions {} export interface ExpectUrl extends ExpectAssertions {} export interface Expect { (val: Element | WebElement | By | { [ELEMENT_KEY]: string }): ExpectElement; (val: any): Chai.Assertion; /** * Expect assertions operating on a single cookie after * retrieving the entire cookie string, using .getCookies(). */ cookie(name: string, domain?: string): ExpectCookie; /** * Expect assertions operating on a single element, specified by its CSS/Xpath selector. */ element(property: Definition | WebElement): ExpectElement; /** * Expect assertions operating on a single component. */ component(property: Definition | WebElement): ExpectElement; /** * Expect assertions operating on a page-object section, specified by '`@section_name`'. */ section(property: Definition): ExpectSection; /** * Expect assertions operating on a collection of elements, specified by a CSS/Xpath selector. * So far only .count is available. */ elements(property: Definition): ExpectElements; /** * Retrieves the page title value in order to be used for performing equal, match or contains assertions on it. */ title(): ExpectTitle; /** * Retrieves the page url value in order to be used for performing equal, match or contains assertions on it. */ url(): ExpectUrl; }