Commands.pm 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. package Selenium::Remote::Commands;
  2. use strict;
  3. use warnings;
  4. sub new {
  5. my $class = shift;
  6. # http://code.google.com/p/selenium/wiki/JsonWireProtocol
  7. my $self = {
  8. 'status' => {
  9. 'method' => 'GET',
  10. 'url' => 'status'
  11. },
  12. 'newSession' => {
  13. 'method' => 'POST',
  14. 'url' => 'session'
  15. },
  16. 'getCapabilities' => {
  17. 'method' => 'GET',
  18. 'url' => 'session/:sessionId'
  19. },
  20. 'setImplicitWaitTimeout' => {
  21. 'method' => 'POST',
  22. 'url' => 'session/:sessionId/timeouts/implicit_wait'
  23. },
  24. 'quit' => {
  25. 'method' => 'DELETE',
  26. 'url' => "session/:sessionId"
  27. },
  28. 'getCurrentWindowHandle' => {
  29. 'method' => 'GET',
  30. 'url' => "session/:sessionId/window_handle"
  31. },
  32. 'getWindowHandles' => {
  33. 'method' => 'GET',
  34. 'url' => "session/:sessionId/window_handles"
  35. },
  36. 'getWindowSize' => {
  37. 'method' => 'GET',
  38. 'url' => "session/:sessionId/window/:windowHandle/size"
  39. },
  40. 'getWindowPosition' => {
  41. 'method' => 'GET',
  42. 'url' => "session/:sessionId/window/:windowHandle/position"
  43. },
  44. 'setWindowSize' => {
  45. 'method' => 'POST',
  46. 'url' => "session/:sessionId/window/:windowHandle/size"
  47. },
  48. 'setWindowPosition' => {
  49. 'method' => 'POST',
  50. 'url' => "session/:sessionId/window/:windowHandle/position"
  51. },
  52. 'getCurrentUrl' => {
  53. 'method' => 'GET',
  54. 'url' => "session/:sessionId/url"
  55. },
  56. 'get' => {
  57. 'method' => 'POST',
  58. 'url' => "session/:sessionId/url"
  59. },
  60. 'goForward' => {
  61. 'method' => 'POST',
  62. 'url' => "session/:sessionId/forward"
  63. },
  64. 'goBack' => {
  65. 'method' => 'POST',
  66. 'url' => "session/:sessionId/back"
  67. },
  68. 'refresh' => {
  69. 'method' => 'POST',
  70. 'url' => "session/:sessionId/refresh"
  71. },
  72. 'executeScript' => {
  73. 'method' => 'POST',
  74. 'url' => "session/:sessionId/execute"
  75. },
  76. 'executeAsyncScript' => {
  77. 'method' => 'POST',
  78. 'url' => "session/:sessionId/execute_async"
  79. },
  80. 'screenshot' => {
  81. 'method' => 'GET',
  82. 'url' => "session/:sessionId/screenshot"
  83. },
  84. 'availableEngines' => {
  85. 'method' => 'GET',
  86. 'url' => "session/:sessionId/ime/available_engines"
  87. },
  88. 'switchToFrame' => {
  89. 'method' => 'POST',
  90. 'url' => "session/:sessionId/frame"
  91. },
  92. 'switchToWindow' => {
  93. 'method' => 'POST',
  94. 'url' => "session/:sessionId/window"
  95. },
  96. 'getAllCookies' => {
  97. 'method' => 'GET',
  98. 'url' => "session/:sessionId/cookie"
  99. },
  100. 'addCookie' => {
  101. 'method' => 'POST',
  102. 'url' => "session/:sessionId/cookie"
  103. },
  104. 'deleteAllCookies' => {
  105. 'method' => 'DELETE',
  106. 'url' => "session/:sessionId/cookie"
  107. },
  108. 'deleteCookieNamed' => {
  109. 'method' => 'DELETE',
  110. 'url' => "session/:sessionId/cookie/:name"
  111. },
  112. 'getPageSource' => {
  113. 'method' => 'GET',
  114. 'url' => "session/:sessionId/source"
  115. },
  116. 'getTitle' => {
  117. 'method' => 'GET',
  118. 'url' => "session/:sessionId/title"
  119. },
  120. 'findElement' => {
  121. 'method' => 'POST',
  122. 'url' => "session/:sessionId/element"
  123. },
  124. 'findElements' => {
  125. 'method' => 'POST',
  126. 'url' => "session/:sessionId/elements"
  127. },
  128. 'getActiveElement' => {
  129. 'method' => 'POST',
  130. 'url' => "session/:sessionId/element/active"
  131. },
  132. 'describeElement' => {
  133. 'method' => 'GET',
  134. 'url' => "session/:sessionId/element/:id"
  135. },
  136. 'findChildElement' => {
  137. 'method' => 'POST',
  138. 'url' => "session/:sessionId/element/:id/element"
  139. },
  140. 'findChildElements' => {
  141. 'method' => 'POST',
  142. 'url' => "session/:sessionId/element/:id/elements"
  143. },
  144. 'clickElement' => {
  145. 'method' => 'POST',
  146. 'url' => "session/:sessionId/element/:id/click"
  147. },
  148. 'submitElement' => {
  149. 'method' => 'POST',
  150. 'url' => "session/:sessionId/element/:id/submit"
  151. },
  152. 'sendKeysToElement' => {
  153. 'method' => 'POST',
  154. 'url' => "session/:sessionId/element/:id/value"
  155. },
  156. 'sendModifier' => {
  157. 'method' => 'POST',
  158. 'url' => "session/:sessionId/modifier"
  159. },
  160. 'isElementSelected' => {
  161. 'method' => 'GET',
  162. 'url' => "session/:sessionId/element/:id/selected"
  163. },
  164. 'setElementSelected' => {
  165. 'method' => 'POST',
  166. 'url' => "session/:sessionId/element/:id/selected"
  167. },
  168. 'toggleElement' => {
  169. 'method' => 'POST',
  170. 'url' => "session/:sessionId/element/:id/toggle"
  171. },
  172. 'isElementEnabled' => {
  173. 'method' => 'GET',
  174. 'url' => "session/:sessionId/element/:id/enabled"
  175. },
  176. 'getElementLocation' => {
  177. 'method' => 'GET',
  178. 'url' => "session/:sessionId/element/:id/location"
  179. },
  180. 'getElementLocationInView' => {
  181. 'method' => 'GET',
  182. 'url' => "session/:sessionId/element/:id/location_in_view"
  183. },
  184. 'getElementTagName' => {
  185. 'method' => 'GET',
  186. 'url' => "session/:sessionId/element/:id/name"
  187. },
  188. 'clearElement' => {
  189. 'method' => 'POST',
  190. 'url' => "session/:sessionId/element/:id/clear"
  191. },
  192. 'getElementAttribute' => {
  193. 'method' => 'GET',
  194. 'url' =>
  195. "session/:sessionId/element/:id/attribute/:name"
  196. },
  197. 'elementEquals' => {
  198. 'method' => 'GET',
  199. 'url' => "session/:sessionId/element/:id/equals/:other"
  200. },
  201. 'isElementDisplayed' => {
  202. 'method' => 'GET',
  203. 'url' => "session/:sessionId/element/:id/displayed"
  204. },
  205. 'close' => {
  206. 'method' => 'DELETE',
  207. 'url' => "session/:sessionId/window"
  208. },
  209. 'dragElement' => {
  210. 'method' => 'POST',
  211. 'url' => "session/:sessionId/element/:id/drag"
  212. },
  213. 'getElementSize' => {
  214. 'method' => 'GET',
  215. 'url' => "session/:sessionId/element/:id/size"
  216. },
  217. 'getElementText' => {
  218. 'method' => 'GET',
  219. 'url' => "session/:sessionId/element/:id/text"
  220. },
  221. 'getElementValueOfCssProperty' => {
  222. 'method' => 'GET',
  223. 'url' => "session/:sessionId/element/:id/css/:propertyName"
  224. },
  225. 'hoverOverElement' => {
  226. 'method' => 'POST',
  227. 'url' => "session/:sessionId/element/:id/hover"
  228. },
  229. 'mouseMoveToLocation' => {
  230. 'method' => 'POST',
  231. 'url' => "session/:sessionId/moveto"
  232. },
  233. 'getAlertText' => {
  234. 'method' => 'GET',
  235. 'url' => 'session/:sessionId/alert_text'
  236. },
  237. 'sendKeysToPrompt' => {
  238. 'method' => 'POST',
  239. 'url' => 'session/:sessionId/alert_text'
  240. },
  241. 'acceptAlert' => {
  242. 'method' => 'POST',
  243. 'url' => 'session/:sessionId/accept_alert'
  244. },
  245. 'dismissAlert' => {
  246. 'method' => 'POST',
  247. 'url' => 'session/:sessionId/dismiss_alert'
  248. },
  249. 'click' => {
  250. 'method' => 'POST',
  251. 'url' => 'session/:sessionId/click'
  252. },
  253. 'doubleClick' => {
  254. 'method' => 'POST',
  255. 'url' => 'session/:sessionId/doubleclick'
  256. },
  257. 'buttonDown' => {
  258. 'method' => 'POST',
  259. 'url' => 'session/:sessionId/buttondown'
  260. },
  261. 'buttonUp' => {
  262. 'method' => 'POST',
  263. 'url' => 'session/:sessionId/buttonup'
  264. },
  265. #'setVisible' => {
  266. # 'method' => 'POST',
  267. # 'url' => "session/:sessionId/visible"
  268. #},
  269. #'getVisible' => {
  270. # 'method' => 'GET',
  271. # 'url' => "session/:sessionId/visible"
  272. #},
  273. };
  274. bless $self, $class or die "Can't bless $class: $!";
  275. return $self;
  276. }
  277. # This method will replace the template & return
  278. sub get_params {
  279. my ($self, $args) = @_;
  280. if (!(defined $args->{'session_id'})) {
  281. return;
  282. }
  283. my $data = {};
  284. my $command = $args->{'command'};
  285. my $url = $self->{$command}->{'url'};
  286. # Do the var substitutions.
  287. $url =~ s/:sessionId/$args->{'session_id'}/;
  288. $url =~ s/:id/$args->{'id'}/;
  289. $url =~ s/:name/$args->{'name'}/;
  290. $url =~ s/:propertyName/$args->{'property_name'}/;
  291. $url =~ s/:other/$args->{'other'}/;
  292. $url =~ s/:windowHandle/$args->{'window_handle'}/;
  293. $data->{'method'} = $self->{$command}->{'method'};
  294. $data->{'url'} = $url;
  295. return $data;
  296. }
  297. 1;
  298. __END__
  299. =head1 SEE ALSO
  300. For more information about Selenium , visit the website at
  301. L<http://code.google.com/p/selenium/>.
  302. =head1 BUGS
  303. The Selenium issue tracking system is available online at
  304. L<http://github.com/aivaturi/Selenium-Remote-Driver/issues>.
  305. =head1 CURRENT MAINTAINER
  306. Gordon Child C<< <gchild@gordonchild.com> >>
  307. =head1 AUTHOR
  308. Perl Bindings for Selenium Remote Driver by Aditya Ivaturi C<< <ivaturi@gmail.com> >>
  309. =head1 LICENSE
  310. Copyright (c) 2010-2011 Aditya Ivaturi, Gordon Child
  311. Licensed under the Apache License, Version 2.0 (the "License");
  312. you may not use this file except in compliance with the License.
  313. You may obtain a copy of the License at
  314. http://www.apache.org/licenses/LICENSE-2.0
  315. Unless required by applicable law or agreed to in writing, software
  316. distributed under the License is distributed on an "AS IS" BASIS,
  317. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  318. See the License for the specific language governing permissions and
  319. limitations under the License.