WebDriverSession.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. // Copyright 2004-present Facebook. All Rights Reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. final class WebDriverSession extends WebDriverContainer {
  16. protected function methods() {
  17. return array(
  18. 'url' => 'GET', // for POST, use open($url)
  19. 'forward' => 'POST',
  20. 'back' => 'POST',
  21. 'refresh' => 'POST',
  22. 'execute' => 'POST',
  23. 'execute_async' => 'POST',
  24. 'screenshot' => 'GET',
  25. 'window_handle' => 'GET',
  26. 'window_handles' => 'GET',
  27. 'frame' => 'POST',
  28. 'source' => 'GET',
  29. 'title' => 'GET',
  30. 'keys' => 'POST',
  31. 'orientation' => array('GET', 'POST'),
  32. 'alert_text' => array('GET', 'POST'),
  33. 'accept_alert' => 'POST',
  34. 'dismiss_alert' => 'POST',
  35. 'moveto' => 'POST',
  36. 'click' => 'POST',
  37. 'buttondown' => 'POST',
  38. 'buttonup' => 'POST',
  39. 'doubleclick' => 'POST',
  40. );
  41. }
  42. // /session/:sessionId/url (POST)
  43. public function open($url) {
  44. $this->curl('POST', '/url', array('url' => $url));
  45. return $this;
  46. }
  47. // /session/:sessionId (GET)
  48. public function capabilities() {
  49. $result = $this->curl('GET', '');
  50. return $result['value'];
  51. }
  52. // /session/:sessionId (DELETE)
  53. public function close() {
  54. $result = $this->curl('DELETE', '');
  55. return $result['value'];
  56. }
  57. // /session/:sessionId/cookie (GET)
  58. public function getAllCookies() {
  59. $result = $this->curl('GET', '/cookie');
  60. return $result['value'];
  61. }
  62. // /session/:sessionId/cookie (POST)
  63. public function setCookie($cookie_json) {
  64. $this->curl('POST', '/cookie', array('cookie' => $cookie_json));
  65. return $this;
  66. }
  67. // /session/:sessionId/cookie (DELETE)
  68. public function deleteAllCookies() {
  69. $this->curl('DELETE', '/cookie');
  70. return $this;
  71. }
  72. // /session/:sessionId/cookie/:name (DELETE)
  73. public function deleteCookie($cookie_name) {
  74. $this->curl('DELETE', '/cookie/' . $cookie_name);
  75. return $this;
  76. }
  77. public function timeouts() {
  78. $item = new WebDriverSimpleItem($this->url . '/timeouts');
  79. return $item->setMethods(array(
  80. 'async_script' => 'POST',
  81. 'implicit_wait' => 'POST',
  82. ));
  83. }
  84. public function ime() {
  85. $item = new WebDriverSimpleItem($this->url . '/ime');
  86. return $item->setMethods(array(
  87. 'available_engines' => 'GET',
  88. 'active_engine' => 'GET',
  89. 'activated' => 'GET',
  90. 'deactivate' => 'POST',
  91. 'activate' => 'POST',
  92. ));
  93. }
  94. // /session/:sessionId/window (DELETE)
  95. public function deleteWindow() {
  96. $this->curl('DELETE', '/window');
  97. return $this;
  98. }
  99. // /session/:sessionId/window (POST)
  100. public function focusWindow($name) {
  101. $this->curl('POST', '/window', array('name' => $name));
  102. return $this;
  103. }
  104. public function window($window_handle = 'current') {
  105. $item = new WebDriverSimpleItem($this->url . '/window/' . $window_handle);
  106. return $item->setMethods(array(
  107. 'size' => array('GET', 'POST'),
  108. 'position' => array('GET', 'POST'),
  109. ));
  110. }
  111. // /session/:sessionId/element/active (POST)
  112. public function activeElement() {
  113. $results = $this->curl('POST', '/element/active');
  114. return $this->webDriverElement($results['value']);
  115. }
  116. public function touch() {
  117. $item = new WebDriverSimpleItem($this->url . '/touch');
  118. return $item->setMethods(array(
  119. 'click' => 'POST',
  120. 'down' => 'POST',
  121. 'up' => 'POST',
  122. 'move' => 'POST',
  123. 'scroll' => 'POST',
  124. 'doubleclick' => 'POST',
  125. 'longclick' => 'POST',
  126. 'flick' => 'POST',
  127. ));
  128. }
  129. protected function getElementPath($element_id) {
  130. return sprintf('%s/element/%s', $this->url, $element_id);
  131. }
  132. }