@@ -69,49 +69,89 @@ function toProtractorModifierKeys(modifiers: ModifierKeys): string[] {
69
69
return result ;
70
70
}
71
71
72
- /** A `TestElement` implementation for Protractor. */
72
+ /**
73
+ * A `TestElement` implementation for Protractor.
74
+ * @deprecated
75
+ * @breaking -change 13.0.0
76
+ */
73
77
export class ProtractorElement implements TestElement {
74
78
constructor ( readonly element : ElementFinder ) { }
75
79
80
+ /** Blur the element. */
76
81
async blur ( ) : Promise < void > {
77
82
return browser . executeScript ( 'arguments[0].blur()' , this . element ) ;
78
83
}
79
84
85
+ /** Clear the element's input (for input and textarea elements only). */
80
86
async clear ( ) : Promise < void > {
81
87
return this . element . clear ( ) ;
82
88
}
83
89
90
+ /**
91
+ * Click the element at the default location for the current environment. If you need to guarantee
92
+ * the element is clicked at a specific location, consider using `click('center')` or
93
+ * `click(x, y)` instead.
94
+ */
95
+ click ( modifiers ?: ModifierKeys ) : Promise < void > ;
96
+ /** Click the element at the element's center. */
97
+ click ( location : 'center' , modifiers ?: ModifierKeys ) : Promise < void > ;
98
+ /**
99
+ * Click the element at the specified coordinates relative to the top-left of the element.
100
+ * @param relativeX Coordinate within the element, along the X-axis at which to click.
101
+ * @param relativeY Coordinate within the element, along the Y-axis at which to click.
102
+ * @param modifiers Modifier keys held while clicking
103
+ */
104
+ click ( relativeX : number , relativeY : number , modifiers ?: ModifierKeys ) : Promise < void > ;
84
105
async click ( ...args : [ ModifierKeys ?] | [ 'center' , ModifierKeys ?] |
85
106
[ number , number , ModifierKeys ?] ) : Promise < void > {
86
107
await this . _dispatchClickEventSequence ( args , Button . LEFT ) ;
87
108
}
88
109
110
+ /**
111
+ * Right clicks on the element at the specified coordinates relative to the top-left of it.
112
+ * @param relativeX Coordinate within the element, along the X-axis at which to click.
113
+ * @param relativeY Coordinate within the element, along the Y-axis at which to click.
114
+ * @param modifiers Modifier keys held while clicking
115
+ */
116
+ rightClick ( relativeX : number , relativeY : number , modifiers ?: ModifierKeys ) : Promise < void > ;
89
117
async rightClick ( ...args : [ ModifierKeys ?] | [ 'center' , ModifierKeys ?] |
90
118
[ number , number , ModifierKeys ?] ) : Promise < void > {
91
119
await this . _dispatchClickEventSequence ( args , Button . RIGHT ) ;
92
120
}
93
121
122
+ /** Focus the element. */
94
123
async focus ( ) : Promise < void > {
95
124
return browser . executeScript ( 'arguments[0].focus()' , this . element ) ;
96
125
}
97
126
127
+ /** Get the computed value of the given CSS property for the element. */
98
128
async getCssValue ( property : string ) : Promise < string > {
99
129
return this . element . getCssValue ( property ) ;
100
130
}
101
131
132
+ /** Hovers the mouse over the element. */
102
133
async hover ( ) : Promise < void > {
103
134
return browser . actions ( )
104
135
. mouseMove ( await this . element . getWebElement ( ) )
105
136
. perform ( ) ;
106
137
}
107
138
139
+ /** Moves the mouse away from the element. */
108
140
async mouseAway ( ) : Promise < void > {
109
141
return browser . actions ( )
110
142
. mouseMove ( await this . element . getWebElement ( ) , { x : - 1 , y : - 1 } )
111
143
. perform ( ) ;
112
144
}
113
145
146
+ /**
147
+ * Sends the given string to the input as a series of key presses. Also fires input events
148
+ * and attempts to add the string to the Element's value.
149
+ */
114
150
async sendKeys ( ...keys : ( string | TestKey ) [ ] ) : Promise < void > ;
151
+ /**
152
+ * Sends the given string to the input as a series of key presses. Also fires input events
153
+ * and attempts to add the string to the Element's value.
154
+ */
115
155
async sendKeys ( modifiers : ModifierKeys , ...keys : ( string | TestKey ) [ ] ) : Promise < void > ;
116
156
async sendKeys ( ...modifiersAndKeys : any [ ] ) : Promise < void > {
117
157
const first = modifiersAndKeys [ 0 ] ;
@@ -135,37 +175,47 @@ export class ProtractorElement implements TestElement {
135
175
return this . element . sendKeys ( ...keys ) ;
136
176
}
137
177
178
+ /**
179
+ * Gets the text from the element.
180
+ * @param options Options that affect what text is included.
181
+ */
138
182
async text ( options ?: TextOptions ) : Promise < string > {
139
183
if ( options ?. exclude ) {
140
184
return browser . executeScript ( _getTextWithExcludedElements , this . element , options . exclude ) ;
141
185
}
142
186
return this . element . getText ( ) ;
143
187
}
144
188
189
+ /** Gets the value for the given attribute from the element. */
145
190
async getAttribute ( name : string ) : Promise < string | null > {
146
191
return browser . executeScript (
147
192
`return arguments[0].getAttribute(arguments[1])` , this . element , name ) ;
148
193
}
149
194
195
+ /** Checks whether the element has the given class. */
150
196
async hasClass ( name : string ) : Promise < boolean > {
151
197
const classes = ( await this . getAttribute ( 'class' ) ) || '' ;
152
198
return new Set ( classes . split ( / \s + / ) . filter ( c => c ) ) . has ( name ) ;
153
199
}
154
200
201
+ /** Gets the dimensions of the element. */
155
202
async getDimensions ( ) : Promise < ElementDimensions > {
156
203
const { width, height} = await this . element . getSize ( ) ;
157
204
const { x : left , y : top } = await this . element . getLocation ( ) ;
158
205
return { width, height, left, top} ;
159
206
}
160
207
208
+ /** Gets the value of a property of an element. */
161
209
async getProperty ( name : string ) : Promise < any > {
162
210
return browser . executeScript ( `return arguments[0][arguments[1]]` , this . element , name ) ;
163
211
}
164
212
213
+ /** Sets the value of a property of an input. */
165
214
async setInputValue ( value : string ) : Promise < void > {
166
215
return browser . executeScript ( `arguments[0].value = arguments[1]` , this . element , value ) ;
167
216
}
168
217
218
+ /** Selects the options at the specified indexes inside of a native `select` element. */
169
219
async selectOptions ( ...optionIndexes : number [ ] ) : Promise < void > {
170
220
const options = await this . element . all ( by . css ( 'option' ) ) ;
171
221
const indexes = new Set ( optionIndexes ) ; // Convert to a set to remove duplicates.
@@ -187,17 +237,23 @@ export class ProtractorElement implements TestElement {
187
237
}
188
238
}
189
239
240
+ /** Checks whether this element matches the given selector. */
190
241
async matchesSelector ( selector : string ) : Promise < boolean > {
191
242
return browser . executeScript ( `
192
243
return (Element.prototype.matches ||
193
244
Element.prototype.msMatchesSelector).call(arguments[0], arguments[1])
194
245
` , this . element , selector ) ;
195
246
}
196
247
248
+ /** Checks whether the element is focused. */
197
249
async isFocused ( ) : Promise < boolean > {
198
250
return this . element . equals ( browser . driver . switchTo ( ) . activeElement ( ) ) ;
199
251
}
200
252
253
+ /**
254
+ * Dispatches an event with a particular name.
255
+ * @param name Name of the event to be dispatched.
256
+ */
201
257
async dispatchEvent ( name : string , data ?: Record < string , EventData > ) : Promise < void > {
202
258
return browser . executeScript ( _dispatchEvent , name , this . element , data ) ;
203
259
}
0 commit comments