forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quixote.d.ts
233 lines (165 loc) · 7.86 KB
/
quixote.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// Type definitions for quixote v0.7.0
// Project: http://quixote-css.com/
// Definitions by: Aleksandr Filatov <https://github.com/greybax>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
interface Quixote {
// Create a test iframe. This is a slow operation, so once you have a frame, it's best to use QFrame.reset() on it rather than creating a new frame for each test
createFrame(options: QuixoteFrameOptions, callback: (err: Error, loadedFrame: QFrame) => void): QFrame;
}
interface QFrame {
// Reset the frame back to the state it was in immediately after you called quixote.createFrame()
reset(): void;
// Remove the test frame entirely.
remove(): void;
// Retrieve an element matching a selector. Throws an exception unless exactly one matching element is found
get(selector: string, nickname?: string): QElement;
// Retrieve a list of elements matching a selector. If you want to ensure that exactly one element is retrieved, use frame.get() instead.
getAll(selector: string, nickname?: string): QElementList;
// Create an element and append it to the frame's body. Throws an exception unless exactly one element is created. (But that one element may contain children.)
add(html: string, nickname?: string): QElement;
// Provides access to descriptors for the frame's viewport (the part of the page that you can see in the frame, not including scrollbars)
viewport(): QElement;
// Provides access to descriptors for the frame's page (everything you can see or scroll to, not including scrollbars)
page(): QElement;
// Retrieves the frame's body element.
body(): QElement;
// Changes the size of the frame.
resize(width: number, height: number): void;
// Scroll the page so that top-left corner of the frame is as close as possible to an (x, y) coordinate.
scroll(x: number, y: number): void;
// Determine the (x, y) coordinate of the top-left corner of the frame. This uses pageXOffset and pageYOffset under the covers. (On IE 8, it uses scrollLeft and scrollTop.)
getRawScrollPosition(x: number, y: number): Object;
// Retrieve the underlying HTMLIFrameElement DOM element for the frame.
toDomElement(): HTMLIFrameElement;
}
interface QElement {
// Compare the element's descriptors to a set of expected values and throw an exception if they don't match
assert(expected: ElementDescriptor, message?: string): void;
// Compare the element's descriptors to a set of expected values.
diff(expected: ElementDescriptor): string;
// Determine how the browser is actually rendering an element's style. This uses getComputedStyle() under the covers. (On IE 8, it uses currentStyle)
getRawStyle(property: string): string;
// Determine where an element is displayed within the frame viewport, as computed by the browser
getRawPosition(): RawPositionObject;
// Retrieve the underlying HTMLElement DOM element for the frame.
toDomElement(): HTMLElement;
}
interface QElementList {
// Determine the number of elements in the list.
length(): number;
// Retrieve an element from the list. Positive and negative indices are allowed. Throws an exception if the index is out of bounds.
at(index: number, nickname?: string): QElement;
}
// Element positions and sizes are available on all QElement instances.
interface ElementDescriptor {
// The top edge of the element
top: PositionDescriptor;
// The right edge of the element
right: PositionDescriptor;
// The bottom edge of the element
bottom: PositionDescriptor;
// The left edge of the element
left: PositionDescriptor;
// Horizontal center: midway between the right and left edges.
center: PositionDescriptor;
// Vertical middle: midway between the top and bottom edges.
middle: PositionDescriptor;
// Width of the element.
width: SizeDescriptor;
// Height of the element.
height: SizeDescriptor;
}
// Viewport positions and sizes are available on QFrame.viewport()
interface ViewportDescriptor {
// The highest visible part of the page.
top: PositionDescriptor;
// The rightmost visible part of the page.
right: PositionDescriptor;
// The lowest visible part of the page.
bottom: PositionDescriptor;
// The leftmost visible part of the page.
left: PositionDescriptor;
// Horizontal center: midway between right and left
center: PositionDescriptor;
// Vertical middle: midway between top and bottom.
middle: PositionDescriptor;
// Width of the viewport.
width: SizeDescriptor;
// Height of the viewport.
height: SizeDescriptor;
}
// Page positions and sizes are available on QFrame.page().
interface PageDescriptor {
// The top of the page.
top: PositionDescriptor;
// The right side of the page.
right: PositionDescriptor;
// The bottom of the page.
bottom: PositionDescriptor;
// The left side of the page.
left: PositionDescriptor;
// Horizontal center: midway between right and left.
center: PositionDescriptor;
// Vertical middle: midway between top and bottom.
middle: PositionDescriptor;
// Width of the page.
width: SizeDescriptor;
// Height of the page.
height: SizeDescriptor;
}
// Position descriptors represent an X or Y coordinate. The top-left corner of the page is (0, 0) and the values increase downward and to the right.
interface PositionDescriptor {
// Create a new descriptor that is further down the page or to the right.
plus(amount: SizeDescriptor): PositionDescriptor;
// Create a new descriptor that is further down the page or to the right.
plus(amount: number): PositionDescriptor;
// Create a new descriptor that is further down the page or to the right.
minus(amount: SizeDescriptor): PositionDescriptor;
// Create a new descriptor that is further down the page or to the right.
minus(amount: number): PositionDescriptor;
}
// Size descriptors represent width or height.
interface SizeDescriptor {
// Create a descriptor that's bigger than this one.
plus(amount: SizeDescriptor): SizeDescriptor;
// Create a descriptor that's bigger than this one.
plus(amount: number): SizeDescriptor;
// Create a descriptor that's smaller than this one.
minus(amount: SizeDescriptor): SizeDescriptor;
// Create a descriptor that's smaller than this one.
minus(amount: number): SizeDescriptor;
// Create a new descriptor that's a multiple or fraction of the size of this one.
times(multiple: number): SizeDescriptor;
}
interface QuixoteFrameOptions {
// Width of the iframe. Defaults to a large value (see stability note below)
width?: number;
// Height of the iframe. Defaults to a large value (see stability note below)
height?: number;
// URL of an HTML document to load into the frame. Must be served from same domain as the enclosing test document, or you could get same-origin policy errors. Defaults to an empty document with <!DOCTYPE html> (to enable standards-mode rendering)
src?: string;
// URL of a CSS stylesheet to load into the frame. Defaults to loading nothing
stylesheet?: string;
}
interface RawPositionObject {
// top edge
top: number;
// right edge
right: number;
// bottom edge
bottom: number;
// left edge
left: number;
// width (right edge minus left edge)
width: number;
// height (bottom edge minus top edge)
height: number;
}
declare var quixote: Quixote;
declare module "quixote" {
class Quixote {
constructor();
createFrame(options: QuixoteFrameOptions, callback: (err: Error, loadedFrame: QFrame) => void): QFrame;
}
export = Quixote;
}