API Docs for: 0.0.5
Show:

File: lib/commands/interaction.js

  1. /*!
  2. *
  3. * Copyright (c) 2013 Sebastian Golasch
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included
  13. * in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  16. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. */
  24.  
  25. /**
  26. * Interaction related Webdriver endpoints
  27. *
  28. * @param {Dalek.Internal.Webdriver} Driver Webdriver client instance
  29. * @return {Dalek.Internal.Webdriver} Driver Webdriver client instance
  30. */
  31.  
  32. module.exports = function (Driver) {
  33. 'use strict';
  34.  
  35. /**
  36. * Move the mouse by an offset of the specificed element.
  37. * If no element is specified, the move is relative to the current mouse cursor.
  38. * If an element is provided but no offset, the mouse will be moved to the center of the element.
  39. * If the element is not visible, it will be scrolled into view.
  40. *
  41. * @method moveto
  42. * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/moveto
  43. * @param {GET} sessionId ID of the session to route the command to
  44. * @param {POST} element Opaque ID assigned to the element to move to, as described in the WebElement JSON Object. If not specified or is null, the offset is relative to current position of the mouse.
  45. * @param {POST} xoffset X offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element.
  46. * @param {POST} yoffset Y offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element.
  47. */
  48.  
  49. Driver.addCommand({
  50. name: 'moveto',
  51. url: '/session/:sessionId/moveto',
  52. method: 'POST',
  53. params: ['element', 'xoffset', 'yoffset'],
  54. onRequest: function (params) {
  55. return params.element;
  56. }
  57. });
  58.  
  59. /**
  60. * Click any mouse button (at the coordinates set by the last moveto command).
  61. * Note that calling this command after calling buttondown and before calling button up
  62. * (or any out-of-order interactions sequence) will yield undefined behaviour).
  63. *
  64. * @method buttonClick
  65. * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/click
  66. * @param {GET} sessionId ID of the session to route the command to
  67. * @param {POST} button Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified.
  68. */
  69.  
  70. // FIXME: rename button* commands to pointerClick, pointerDown, etc.
  71. Driver.addCommand({
  72. name: 'buttonClick',
  73. url: '/session/:sessionId/click',
  74. method: 'POST',
  75. params: ['button']
  76. });
  77.  
  78. /**
  79. * Click and hold the left mouse button (at the coordinates set by the last moveto command).
  80. * Note that the next mouse-related command that should follow is buttonup.
  81. * Any other mouse command (such as click or another call to buttondown) will yield undefined behaviour.
  82. *
  83. * @method buttondown
  84. * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/buttondown
  85. * @param {GET} sessionId ID of the session to route the command to
  86. * @param {POST} button Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified.
  87. */
  88.  
  89. Driver.addCommand({
  90. name: 'buttondown',
  91. url: '/session/:sessionId/buttondown',
  92. method: 'POST',
  93. params: ['button']
  94. });
  95.  
  96. /**
  97. * Releases the mouse button previously held (where the mouse is currently at).
  98. * Must be called once for every buttondown command issued.
  99. * See the note in click and buttondown about implications of out-of-order commands.
  100. *
  101. * @method buttonup
  102. * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/buttonup
  103. * @param {GET} sessionId ID of the session to route the command to
  104. * @param {POST} button Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified.
  105. */
  106.  
  107. Driver.addCommand({
  108. name: 'buttonup',
  109. url: '/session/:sessionId/buttonup',
  110. method: 'POST',
  111. params: ['button']
  112. });
  113.  
  114. /**
  115. * Double-clicks at the current mouse coordinates (set by moveto).
  116. *
  117. * @method doubleclickPage
  118. * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/doubleclick
  119. * @param {GET} sessionId ID of the session to route the command to
  120. */
  121.  
  122. Driver.addCommand({
  123. name: 'buttonDoubleclick',
  124. url: '/session/:sessionId/doubleclick',
  125. method: 'POST'
  126. });
  127.  
  128. /**
  129. * Single tap on the touch enabled device.
  130. *
  131. * @method tap
  132. * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/click
  133. * @param {GET} sessionId ID of the session to route the command to
  134. */
  135.  
  136. // FIXME: rename touch* and tap commands to touchDown, touchUp, touchFlich, etc.
  137. Driver.addCommand({
  138. name: 'tap',
  139. url: '/session/:sessionId/touch/click',
  140. method: 'POST'
  141. });
  142.  
  143. /**
  144. * Finger down on the screen.
  145. *
  146. * @method touchdown
  147. * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/down
  148. * @param {GET} sessionId ID of the session to route the command to
  149. * @param {POST} x X coordinate on the screen.
  150. * @param {POST} y Y coordinate on the screen.
  151. */
  152.  
  153. Driver.addCommand({
  154. name: 'touchdown',
  155. url: '/session/:sessionId/touch/down',
  156. method: 'POST',
  157. params: ['x', 'y']
  158. });
  159.  
  160. /**
  161. * Finger up on the screen.
  162. *
  163. * @method touchup
  164. * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/up
  165. * @param {GET} sessionId ID of the session to route the command to
  166. * @param {POST} x X coordinate on the screen.
  167. * @param {POST} y Y coordinate on the screen.
  168. */
  169.  
  170. Driver.addCommand({
  171. name: 'touchup',
  172. url: '/session/:sessionId/touch/up',
  173. method: 'POST',
  174. params: ['x', 'y']
  175. });
  176.  
  177. /**
  178. * Finger move on the screen.
  179. *
  180. * @method touchmove
  181. * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/move
  182. * @param {GET} sessionId ID of the session to route the command to
  183. * @param {POST} x X coordinate on the screen.
  184. * @param {POST} y Y coordinate on the screen.
  185. */
  186.  
  187. Driver.addCommand({
  188. name: 'touchmove',
  189. url: 'session/:sessionId/touch/move',
  190. method: 'POST',
  191. params: ['x', 'y']
  192. });
  193.  
  194. /**
  195. * Scroll on the touch screen using finger based motion events.
  196. * Use this command if you don't care where the scroll starts on the screen.
  197. *
  198. * @method touchscroll
  199. * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/scroll
  200. * @param {GET} sessionId ID of the session to route the command to
  201. * @param {POST} x X coordinate on the screen.
  202. * @param {POST} y Y coordinate on the screen.
  203. */
  204.  
  205. Driver.addCommand({
  206. name: 'touchscroll',
  207. url: 'session/:sessionId/touch/scroll',
  208. method: 'POST',
  209. params: ['x', 'y']
  210. });
  211.  
  212. /**
  213. * Double tap on the touch screen using finger motion events.
  214. *
  215. * @method doubletap
  216. * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/doubleclick
  217. * @param {GET} sessionId ID of the session to route the command to
  218. */
  219.  
  220. Driver.addCommand({
  221. name: 'doubleTap',
  222. url: 'session/:sessionId/touch/doubleclick',
  223. method: 'POST'
  224. });
  225.  
  226. /**
  227. * Long press on the touch screen using finger motion events.
  228. *
  229. * @method longpress
  230. * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/longclick
  231. * @param {GET} sessionId ID of the session to route the command to
  232. */
  233.  
  234. Driver.addCommand({
  235. name: 'longpress',
  236. url: 'session/:sessionId/touch/longclick',
  237. method: 'POST'
  238. });
  239.  
  240. /**
  241. * Flick on the touch screen using finger motion events.
  242. * This flickcommand starts at a particulat screen location.
  243. *
  244. * @method flick
  245. * @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/touch/flick
  246. * @param {GET} sessionId ID of the session to route the command to
  247. * @param {POST} element ID of the element where the flick starts
  248. * @param {POST} xoffset The x offset in pixels to flick by
  249. * @param {POST} yoffset The y offset in pixels to flick by
  250. * @param {POST} speed The speed in pixels per seconds
  251. */
  252.  
  253. Driver.addCommand({
  254. name: 'flick',
  255. url: 'session/:sessionId/touch/flick',
  256. method: 'POST',
  257. params: ['id', 'x', 'y', 'speed']
  258. });
  259.  
  260.  
  261. Driver.addCommand({
  262. url: '/session/:sessionId/keys',
  263. method: 'GET'
  264. });
  265.  
  266. };
  267.