RemoteTouchScreen.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. namespace Facebook\WebDriver\Remote;
  16. use Facebook\WebDriver\Interactions\Touch\WebDriverTouchScreen;
  17. use Facebook\WebDriver\WebDriverElement;
  18. /**
  19. * Execute touch commands for RemoteWebDriver.
  20. */
  21. class RemoteTouchScreen implements WebDriverTouchScreen
  22. {
  23. /**
  24. * @var RemoteExecuteMethod
  25. */
  26. private $executor;
  27. /**
  28. * @param RemoteExecuteMethod $executor
  29. */
  30. public function __construct(RemoteExecuteMethod $executor)
  31. {
  32. $this->executor = $executor;
  33. }
  34. /**
  35. * @param WebDriverElement $element
  36. *
  37. * @return RemoteTouchScreen The instance.
  38. */
  39. public function tap(WebDriverElement $element)
  40. {
  41. $this->executor->execute(
  42. DriverCommand::TOUCH_SINGLE_TAP,
  43. ['element' => $element->getID()]
  44. );
  45. return $this;
  46. }
  47. /**
  48. * @param WebDriverElement $element
  49. *
  50. * @return RemoteTouchScreen The instance.
  51. */
  52. public function doubleTap(WebDriverElement $element)
  53. {
  54. $this->executor->execute(
  55. DriverCommand::TOUCH_DOUBLE_TAP,
  56. ['element' => $element->getID()]
  57. );
  58. return $this;
  59. }
  60. /**
  61. * @param int $x
  62. * @param int $y
  63. *
  64. * @return RemoteTouchScreen The instance.
  65. */
  66. public function down($x, $y)
  67. {
  68. $this->executor->execute(DriverCommand::TOUCH_DOWN, [
  69. 'x' => $x,
  70. 'y' => $y,
  71. ]);
  72. return $this;
  73. }
  74. /**
  75. * @param int $xspeed
  76. * @param int $yspeed
  77. *
  78. * @return RemoteTouchScreen The instance.
  79. */
  80. public function flick($xspeed, $yspeed)
  81. {
  82. $this->executor->execute(DriverCommand::TOUCH_FLICK, [
  83. 'xspeed' => $xspeed,
  84. 'yspeed' => $yspeed,
  85. ]);
  86. return $this;
  87. }
  88. /**
  89. * @param WebDriverElement $element
  90. * @param int $xoffset
  91. * @param int $yoffset
  92. * @param int $speed
  93. *
  94. * @return RemoteTouchScreen The instance.
  95. */
  96. public function flickFromElement(WebDriverElement $element, $xoffset, $yoffset, $speed)
  97. {
  98. $this->executor->execute(DriverCommand::TOUCH_FLICK, [
  99. 'xoffset' => $xoffset,
  100. 'yoffset' => $yoffset,
  101. 'element' => $element->getID(),
  102. 'speed' => $speed,
  103. ]);
  104. return $this;
  105. }
  106. /**
  107. * @param WebDriverElement $element
  108. *
  109. * @return RemoteTouchScreen The instance.
  110. */
  111. public function longPress(WebDriverElement $element)
  112. {
  113. $this->executor->execute(
  114. DriverCommand::TOUCH_LONG_PRESS,
  115. ['element' => $element->getID()]
  116. );
  117. return $this;
  118. }
  119. /**
  120. * @param int $x
  121. * @param int $y
  122. *
  123. * @return RemoteTouchScreen The instance.
  124. */
  125. public function move($x, $y)
  126. {
  127. $this->executor->execute(DriverCommand::TOUCH_MOVE, [
  128. 'x' => $x,
  129. 'y' => $y,
  130. ]);
  131. return $this;
  132. }
  133. /**
  134. * @param int $xoffset
  135. * @param int $yoffset
  136. *
  137. * @return RemoteTouchScreen The instance.
  138. */
  139. public function scroll($xoffset, $yoffset)
  140. {
  141. $this->executor->execute(DriverCommand::TOUCH_SCROLL, [
  142. 'xoffset' => $xoffset,
  143. 'yoffset' => $yoffset,
  144. ]);
  145. return $this;
  146. }
  147. /**
  148. * @param WebDriverElement $element
  149. * @param int $xoffset
  150. * @param int $yoffset
  151. *
  152. * @return RemoteTouchScreen The instance.
  153. */
  154. public function scrollFromElement(WebDriverElement $element, $xoffset, $yoffset)
  155. {
  156. $this->executor->execute(DriverCommand::TOUCH_SCROLL, [
  157. 'element' => $element->getID(),
  158. 'xoffset' => $xoffset,
  159. 'yoffset' => $yoffset,
  160. ]);
  161. return $this;
  162. }
  163. /**
  164. * @param int $x
  165. * @param int $y
  166. *
  167. * @return RemoteTouchScreen The instance.
  168. */
  169. public function up($x, $y)
  170. {
  171. $this->executor->execute(DriverCommand::TOUCH_UP, [
  172. 'x' => $x,
  173. 'y' => $y,
  174. ]);
  175. return $this;
  176. }
  177. }