UNPKG

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