UNPKG

5.91 kBTypeScriptView Raw
1import { Definition, NightwatchAPI, Awaitable } from "./index";
2
3export interface NightwatchExpectResult {
4 value: null;
5 returned: 1;
6}
7
8export interface ExpectLanguageChains<T> {
9 // The following are provided as chainable getters
10 // to improve the readability of your assertions.
11 // They do not provide testing capabilities and
12 // the order is not important.
13 to: T;
14 be: T;
15 been: T;
16 is: T;
17 that: T;
18 which: T;
19 and: T;
20 has: T;
21 have: T;
22 with: T;
23 at: T;
24 does: T;
25 of: T;
26 same: T;
27
28 /**
29 * Negates any of assertions following in the chain.
30 */
31 not: T;
32
33 /**
34 * Sets the `deep` flag, later to be used by the `equal`.
35 */
36 deep: T;
37}
38
39export interface ExpectEqual<T> {
40 (value: any): Awaitable<T, NightwatchExpectResult>;
41}
42
43export interface ExpectInclude<T> {
44 (value: string): Awaitable<T, NightwatchExpectResult>;
45}
46
47export interface ExpectMatch<T> {
48 (regexp: RegExp): Awaitable<T, NightwatchExpectResult>;
49}
50
51export interface ExpectStartWith<T> {
52 (value: string): Awaitable<T, NightwatchExpectResult>;
53}
54
55export interface ExpectEndWith<T> {
56 (value: string): Awaitable<T, NightwatchExpectResult>;
57}
58
59export interface ExpectAssertions<T> extends ExpectLanguageChains<T> {
60 equal: ExpectEqual<T>;
61 equals: ExpectEqual<T>;
62 eq: ExpectEqual<T>;
63
64 include: ExpectInclude<T>;
65 includes: ExpectInclude<T>;
66 contain: ExpectInclude<T>;
67 contains: ExpectInclude<T>;
68
69 match: ExpectMatch<T>;
70 matches: ExpectMatch<T>;
71
72 startWith: ExpectStartWith<T>;
73 startsWith: ExpectStartWith<T>;
74
75 endWith: ExpectEndWith<T>;
76 endsWith: ExpectEndWith<T>;
77
78 before: (ms: number) => Awaitable<T, NightwatchExpectResult>;
79 after: (ms: number) => Awaitable<T, NightwatchExpectResult>;
80
81 // Assertion methods returning NightwatchAPI
82 toEqual: (value: any) => NightwatchAPI;
83 toBe: (value: any) => NightwatchAPI;
84 toContain: (value: string) => NightwatchAPI;
85 toMatch: (regexp: RegExp) => NightwatchAPI;
86 toEndWith: (value: string) => NightwatchAPI;
87}
88
89export interface ExpectCookie extends ExpectAssertions<ExpectCookie> {}
90
91export interface ExpectElement extends ExpectAssertions<ExpectElement> {
92 /**
93 * Checks if the type (i.e. tag name) of a specified element is of an expected value.
94 */
95 a(type: string, message?: string): Awaitable<this, NightwatchExpectResult>;
96
97 /**
98 * Checks if the type (i.e. tag name) of a specified element is of an expected value.
99 */
100 an(type: string, message?: string): Awaitable<this, NightwatchExpectResult>;
101
102 /**
103 * Property that checks if an element is active in the DOM.
104 */
105 active: Awaitable<this, NightwatchExpectResult>;
106
107 /**
108 * Checks if a given attribute of an element exists and optionally if it has the expected value.
109 */
110 attribute(attribute: string, message?: string): Awaitable<this, NightwatchExpectResult>;
111
112 /**
113 * Checks a given css property of an element exists and optionally if it has the expected value.
114 */
115 css(property: string, message?: string): Awaitable<this, NightwatchExpectResult>;
116
117 /**
118 * Property that checks if an element is currently enabled.
119 */
120 enabled: Awaitable<this, NightwatchExpectResult>;
121
122 /**
123 * Property that checks if an element is present in the DOM.
124 */
125 present: Awaitable<this, NightwatchExpectResult>;
126
127 /**
128 * Checks if a given DOM property of an element has the expected value.
129 * For all the available DOM element properties, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element).
130 */
131 property(name: string, message?: string): Awaitable<this, NightwatchExpectResult>;
132
133 /**
134 * Property that checks if an OPTION element, or an INPUT element of type checkbox or radio button is currently selected.
135 */
136 selected: Awaitable<this, NightwatchExpectResult>;
137
138 /**
139 * Property that retrieves the text contained by an element. Can be chained to check if contains/equals/matches the specified text or regex.
140 */
141 text: Awaitable<this, NightwatchExpectResult>;
142
143 /**
144 * 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.
145 */
146 value: Awaitable<this, NightwatchExpectResult>;
147
148 /**
149 * Property that asserts the visibility of a specified element.
150 */
151 visible: Awaitable<this, NightwatchExpectResult>;
152
153 /**
154 * Checks if the specified DOM property of a given element is present and has the expected value.
155 * For all the available DOM element properties, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element).
156 */
157 domProperty(propertyName: string, message?: string): Awaitable<this, NightwatchExpectResult>;
158}
159
160export interface ExpectElements extends ExpectAssertions<ExpectElements> {
161 /**
162 * Checks if the number of elements specified by a selector is equal or not to a given value.
163 */
164 count: this;
165}
166
167export interface ExpectTitle extends ExpectAssertions<ExpectTitle> {}
168
169export interface ExpectUrl extends ExpectAssertions<ExpectUrl> {}
170
171export interface Expect {
172 /**
173 * Expect assertions operating on a single cookie after
174 * retrieving the entire cookie string, using .getCookies().
175 */
176 cookie(name: string, domain?: string): ExpectCookie;
177
178 /**
179 * Expect assertions operating on a single element, specified by its CSS/Xpath selector.
180 */
181 element(property: Definition): ExpectElement;
182
183 /**
184 * Expect assertions operating on a collection of elements, specified by a CSS/Xpath selector.
185 * So far only .count is available.
186 */
187 elements(property: Definition): ExpectElements;
188
189 /**
190 * Retrieves the page title value in order to be used for performing equal, match or contains assertions on it.
191 */
192 title(): ExpectTitle;
193
194 /**
195 * Retrieves the page url value in order to be used for performing equal, match or contains assertions on it.
196 */
197 url(): ExpectUrl;
198}