@@ -69,49 +69,89 @@ function toProtractorModifierKeys(modifiers: ModifierKeys): string[] {
6969 return result ;
7070}
7171
72- /** A `TestElement` implementation for Protractor. */
72+ /**
73+ * A `TestElement` implementation for Protractor.
74+ * @deprecated
75+ * @breaking -change 13.0.0
76+ */
7377export class ProtractorElement implements TestElement {
7478 constructor ( readonly element : ElementFinder ) { }
7579
80+ /** Blur the element. */
7681 async blur ( ) : Promise < void > {
7782 return browser . executeScript ( 'arguments[0].blur()' , this . element ) ;
7883 }
7984
85+ /** Clear the element's input (for input and textarea elements only). */
8086 async clear ( ) : Promise < void > {
8187 return this . element . clear ( ) ;
8288 }
8389
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 > ;
84105 async click ( ...args : [ ModifierKeys ?] | [ 'center' , ModifierKeys ?] |
85106 [ number , number , ModifierKeys ?] ) : Promise < void > {
86107 await this . _dispatchClickEventSequence ( args , Button . LEFT ) ;
87108 }
88109
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 > ;
89117 async rightClick ( ...args : [ ModifierKeys ?] | [ 'center' , ModifierKeys ?] |
90118 [ number , number , ModifierKeys ?] ) : Promise < void > {
91119 await this . _dispatchClickEventSequence ( args , Button . RIGHT ) ;
92120 }
93121
122+ /** Focus the element. */
94123 async focus ( ) : Promise < void > {
95124 return browser . executeScript ( 'arguments[0].focus()' , this . element ) ;
96125 }
97126
127+ /** Get the computed value of the given CSS property for the element. */
98128 async getCssValue ( property : string ) : Promise < string > {
99129 return this . element . getCssValue ( property ) ;
100130 }
101131
132+ /** Hovers the mouse over the element. */
102133 async hover ( ) : Promise < void > {
103134 return browser . actions ( )
104135 . mouseMove ( await this . element . getWebElement ( ) )
105136 . perform ( ) ;
106137 }
107138
139+ /** Moves the mouse away from the element. */
108140 async mouseAway ( ) : Promise < void > {
109141 return browser . actions ( )
110142 . mouseMove ( await this . element . getWebElement ( ) , { x : - 1 , y : - 1 } )
111143 . perform ( ) ;
112144 }
113145
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+ */
114150 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+ */
115155 async sendKeys ( modifiers : ModifierKeys , ...keys : ( string | TestKey ) [ ] ) : Promise < void > ;
116156 async sendKeys ( ...modifiersAndKeys : any [ ] ) : Promise < void > {
117157 const first = modifiersAndKeys [ 0 ] ;
@@ -135,37 +175,47 @@ export class ProtractorElement implements TestElement {
135175 return this . element . sendKeys ( ...keys ) ;
136176 }
137177
178+ /**
179+ * Gets the text from the element.
180+ * @param options Options that affect what text is included.
181+ */
138182 async text ( options ?: TextOptions ) : Promise < string > {
139183 if ( options ?. exclude ) {
140184 return browser . executeScript ( _getTextWithExcludedElements , this . element , options . exclude ) ;
141185 }
142186 return this . element . getText ( ) ;
143187 }
144188
189+ /** Gets the value for the given attribute from the element. */
145190 async getAttribute ( name : string ) : Promise < string | null > {
146191 return browser . executeScript (
147192 `return arguments[0].getAttribute(arguments[1])` , this . element , name ) ;
148193 }
149194
195+ /** Checks whether the element has the given class. */
150196 async hasClass ( name : string ) : Promise < boolean > {
151197 const classes = ( await this . getAttribute ( 'class' ) ) || '' ;
152198 return new Set ( classes . split ( / \s + / ) . filter ( c => c ) ) . has ( name ) ;
153199 }
154200
201+ /** Gets the dimensions of the element. */
155202 async getDimensions ( ) : Promise < ElementDimensions > {
156203 const { width, height} = await this . element . getSize ( ) ;
157204 const { x : left , y : top } = await this . element . getLocation ( ) ;
158205 return { width, height, left, top} ;
159206 }
160207
208+ /** Gets the value of a property of an element. */
161209 async getProperty ( name : string ) : Promise < any > {
162210 return browser . executeScript ( `return arguments[0][arguments[1]]` , this . element , name ) ;
163211 }
164212
213+ /** Sets the value of a property of an input. */
165214 async setInputValue ( value : string ) : Promise < void > {
166215 return browser . executeScript ( `arguments[0].value = arguments[1]` , this . element , value ) ;
167216 }
168217
218+ /** Selects the options at the specified indexes inside of a native `select` element. */
169219 async selectOptions ( ...optionIndexes : number [ ] ) : Promise < void > {
170220 const options = await this . element . all ( by . css ( 'option' ) ) ;
171221 const indexes = new Set ( optionIndexes ) ; // Convert to a set to remove duplicates.
@@ -187,17 +237,23 @@ export class ProtractorElement implements TestElement {
187237 }
188238 }
189239
240+ /** Checks whether this element matches the given selector. */
190241 async matchesSelector ( selector : string ) : Promise < boolean > {
191242 return browser . executeScript ( `
192243 return (Element.prototype.matches ||
193244 Element.prototype.msMatchesSelector).call(arguments[0], arguments[1])
194245 ` , this . element , selector ) ;
195246 }
196247
248+ /** Checks whether the element is focused. */
197249 async isFocused ( ) : Promise < boolean > {
198250 return this . element . equals ( browser . driver . switchTo ( ) . activeElement ( ) ) ;
199251 }
200252
253+ /**
254+ * Dispatches an event with a particular name.
255+ * @param name Name of the event to be dispatched.
256+ */
201257 async dispatchEvent ( name : string , data ?: Record < string , EventData > ) : Promise < void > {
202258 return browser . executeScript ( _dispatchEvent , name , this . element , data ) ;
203259 }
0 commit comments