@@ -783,131 +783,130 @@ class Actions {
783783 * @param {number } duration duration ratio be the ratio of time delta and duration
784784 * @returns {!Action } An action to scroll with this device.
785785 */
786- * /
787- scroll ( x , y , targetDeltaX , targetDeltaY , origin , duration ) {
788- return this . insert ( this . wheel_ , this . wheel_ . scroll ( x , y , targetDeltaX , targetDeltaY , origin , duration ) )
789- }
790-
791- /**
792- * Inserts an action for moving the mouse `x` and `y` pixels relative to the
793- * specified `origin`. The `origin` may be defined as the mouse's
794- * {@linkplain ./input.Origin.POINTER current position}, the
795- * {@linkplain ./input.Origin.VIEWPORT viewport}, or the center of a specific
796- * {@linkplain ./webdriver.WebElement WebElement}.
797- *
798- * You may adjust how long the remote end should take, in milliseconds, to
799- * perform the move using the `duration` parameter (defaults to 100 ms).
800- * The number of incremental move events generated over this duration is an
801- * implementation detail for the remote end.
802- *
803- * @param {{
804- * x: (number|undefined),
805- * y: (number|undefined),
806- * duration: (number|undefined),
807- * origin: (!Origin|!./webdriver.WebElement|undefined),
808- * }= } options The move options. Defaults to moving the mouse to the top-left
809- * corner of the viewport over 100ms.
810- * @return {!Actions } a self reference.
811- */
812- move ( { x = 0 , y = 0 , duration = 100 , origin = Origin . VIEWPORT } = { } ) {
813- return this . insert (
814- this . mouse_ ,
815- this . mouse_ . move ( { x, y, duration, origin } )
816- )
817- }
786+ scroll ( x , y , targetDeltaX , targetDeltaY , origin , duration ) {
787+ return this . insert ( this . wheel_ , this . wheel_ . scroll ( x , y , targetDeltaX , targetDeltaY , origin , duration ) )
788+ }
818789
819- /**
820- * Short-hand for performing a simple left-click (down/up) with the mouse.
821- *
822- * @param {./webdriver.WebElement= } element If specified, the mouse will
823- * first be moved to the center of the element before performing the
824- * click.
825- * @return {!Actions } a self reference.
826- */
827- click ( element ) {
828- if ( element ) {
829- this . move ( { origin : element } )
790+ /**
791+ * Inserts an action for moving the mouse `x` and `y` pixels relative to the
792+ * specified `origin`. The `origin` may be defined as the mouse's
793+ * {@linkplain ./input.Origin.POINTER current position}, the
794+ * {@linkplain ./input.Origin.VIEWPORT viewport}, or the center of a specific
795+ * {@linkplain ./webdriver.WebElement WebElement}.
796+ *
797+ * You may adjust how long the remote end should take, in milliseconds, to
798+ * perform the move using the `duration` parameter (defaults to 100 ms).
799+ * The number of incremental move events generated over this duration is an
800+ * implementation detail for the remote end.
801+ *
802+ * @param {{
803+ * x: (number|undefined),
804+ * y: (number|undefined),
805+ * duration: (number|undefined),
806+ * origin: (!Origin|!./webdriver.WebElement|undefined),
807+ * }= } options The move options. Defaults to moving the mouse to the top-left
808+ * corner of the viewport over 100ms.
809+ * @return {!Actions } a self reference.
810+ */
811+ move ( { x = 0 , y = 0 , duration = 100 , origin = Origin . VIEWPORT } = { } ) {
812+ return this . insert (
813+ this . mouse_ ,
814+ this . mouse_ . move ( { x, y, duration, origin } )
815+ )
830816 }
831- return this . press ( ) . release ( )
832- }
833817
834- /**
835- * Short-hand for performing a simple right-click (down/up) with the mouse.
836- *
837- * @param {./webdriver.WebElement= } element If specified, the mouse will
838- * first be moved to the center of the element before performing the
839- * click.
840- * @return {!Actions } a self reference.
841- */
842- contextClick ( element ) {
843- if ( element ) {
844- this . move ( { origin : element } )
818+ /**
819+ * Short-hand for performing a simple left-click (down/up) with the mouse.
820+ *
821+ * @param {./webdriver.WebElement= } element If specified, the mouse will
822+ * first be moved to the center of the element before performing the
823+ * click.
824+ * @return {!Actions } a self reference.
825+ */
826+ click ( element ) {
827+ if ( element ) {
828+ this . move ( { origin : element } )
829+ }
830+ return this . press ( ) . release ( )
845831 }
846- return this . press ( Button . RIGHT ) . release ( Button . RIGHT )
847- }
848832
849- /**
850- * Short-hand for performing a double left-click with the mouse.
851- *
852- * @param {./webdriver.WebElement= } element If specified, the mouse will
853- * first be moved to the center of the element before performing the
854- * click.
855- * @return {!Actions } a self reference.
856- */
857- doubleClick ( element ) {
858- return this . click ( element ) . press ( ) . release ( )
859- }
833+ /**
834+ * Short-hand for performing a simple right-click (down/up) with the mouse.
835+ *
836+ * @param {./webdriver.WebElement= } element If specified, the mouse will
837+ * first be moved to the center of the element before performing the
838+ * click.
839+ * @return {!Actions } a self reference.
840+ */
841+ contextClick ( element ) {
842+ if ( element ) {
843+ this . move ( { origin : element } )
844+ }
845+ return this . press ( Button . RIGHT ) . release ( Button . RIGHT )
846+ }
860847
861- /**
862- * Configures a drag-and-drop action consisting of the following steps:
863- *
864- * 1. Move to the center of the `from` element (element to be dragged).
865- * 2. Press the left mouse button.
866- * 3. If the `to` target is a {@linkplain ./webdriver.WebElement WebElement},
867- * move the mouse to its center. Otherwise, move the mouse by the
868- * specified offset.
869- * 4. Release the left mouse button.
870- *
871- * @param {!./webdriver.WebElement } from The element to press the left mouse
872- * button on to start the drag.
873- * @param {(!./webdriver.WebElement|{x: number, y: number}) } to Either another
874- * element to drag to (will drag to the center of the element), or an
875- * object specifying the offset to drag by, in pixels.
876- * @return {!Actions } a self reference.
877- */
878- dragAndDrop ( from , to ) {
879- // Do not require up top to avoid a cycle that breaks static analysis.
880- const { WebElement } = require ( './webdriver' )
881- if (
882- ! ( to instanceof WebElement ) &&
883- ( ! to || typeof to . x !== 'number' || typeof to . y !== 'number' )
884- ) {
885- throw new InvalidArgumentError (
886- 'Invalid drag target; must specify a WebElement or {x, y} offset'
887- )
848+ /**
849+ * Short-hand for performing a double left-click with the mouse.
850+ *
851+ * @param {./webdriver.WebElement= } element If specified, the mouse will
852+ * first be moved to the center of the element before performing the
853+ * click.
854+ * @return {!Actions } a self reference.
855+ */
856+ doubleClick ( element ) {
857+ return this . click ( element ) . press ( ) . release ( )
888858 }
889859
890- this . move ( { origin : from } ) . press ( )
891- if ( to instanceof WebElement ) {
892- this . move ( { origin : to } )
893- } else {
894- this . move ( { x : to . x , y : to . y , origin : Origin . POINTER } )
860+ /**
861+ * Configures a drag-and-drop action consisting of the following steps:
862+ *
863+ * 1. Move to the center of the `from` element (element to be dragged).
864+ * 2. Press the left mouse button.
865+ * 3. If the `to` target is a {@linkplain ./webdriver.WebElement WebElement},
866+ * move the mouse to its center. Otherwise, move the mouse by the
867+ * specified offset.
868+ * 4. Release the left mouse button.
869+ *
870+ * @param {!./webdriver.WebElement } from The element to press the left mouse
871+ * button on to start the drag.
872+ * @param {(!./webdriver.WebElement|{x: number, y: number}) } to Either another
873+ * element to drag to (will drag to the center of the element), or an
874+ * object specifying the offset to drag by, in pixels.
875+ * @return {!Actions } a self reference.
876+ */
877+ dragAndDrop ( from , to ) {
878+ // Do not require up top to avoid a cycle that breaks static analysis.
879+ const { WebElement } = require ( './webdriver' )
880+ if (
881+ ! ( to instanceof WebElement ) &&
882+ ( ! to || typeof to . x !== 'number' || typeof to . y !== 'number' )
883+ ) {
884+ throw new InvalidArgumentError (
885+ 'Invalid drag target; must specify a WebElement or {x, y} offset'
886+ )
887+ }
888+
889+ this . move ( { origin : from } ) . press ( )
890+ if ( to instanceof WebElement ) {
891+ this . move ( { origin : to } )
892+ } else {
893+ this . move ( { x : to . x , y : to . y , origin : Origin . POINTER } )
894+ }
895+ return this . release ( )
895896 }
896- return this . release ( )
897- }
898897
899- /**
900- * Releases all keys, pointers, and clears internal state.
901- *
902- * @return {!Promise<void> } a promise that will resolve when finished
903- * clearing all action state.
904- */
905- clear ( ) {
906- for ( const s of this . sequences_ . values ( ) ) {
907- s . length = 0
898+ /**
899+ * Releases all keys, pointers, and clears internal state.
900+ *
901+ * @return {!Promise<void> } a promise that will resolve when finished
902+ * clearing all action state.
903+ */
904+ clear ( ) {
905+ for ( const s of this . sequences_ . values ( ) ) {
906+ s . length = 0
907+ }
908+ return this . executor_ . execute ( new Command ( Name . CLEAR_ACTIONS ) )
908909 }
909- return this . executor_ . execute ( new Command ( Name . CLEAR_ACTIONS ) )
910- }
911910
912911 /**
913912 * Performs the configured action sequence.
@@ -916,22 +915,22 @@ clear() {
916915 * been completed.
917916 */
918917 async perform ( ) {
919- const _actions = [ ]
920- this . sequences_ . forEach ( ( actions , device ) => {
921- if ( ! isIdle ( actions ) ) {
922- actions = actions . concat ( ) // Defensive copy.
923- _actions . push ( Object . assign ( { actions } , device . toJSON ( ) ) )
918+ const _actions = [ ]
919+ this . sequences_ . forEach ( ( actions , device ) => {
920+ if ( ! isIdle ( actions ) ) {
921+ actions = actions . concat ( ) // Defensive copy.
922+ _actions . push ( Object . assign ( { actions } , device . toJSON ( ) ) )
923+ }
924+ } )
925+
926+ if ( _actions . length === 0 ) {
927+ return Promise . resolve ( )
924928 }
925- } )
926929
927- if ( _actions . length === 0 ) {
928- return Promise . resolve ( )
930+ await this . executor_ . execute (
931+ new Command ( Name . ACTIONS ) . setParameter ( 'actions' , _actions )
932+ )
929933 }
930-
931- await this . executor_ . execute (
932- new Command ( Name . ACTIONS ) . setParameter ( 'actions' , _actions )
933- )
934- }
935934}
936935
937936/**
0 commit comments