WebDriverTouchActions.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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\Interactions;
  16. use Facebook\WebDriver\Interactions\Touch\WebDriverDoubleTapAction;
  17. use Facebook\WebDriver\Interactions\Touch\WebDriverDownAction;
  18. use Facebook\WebDriver\Interactions\Touch\WebDriverFlickAction;
  19. use Facebook\WebDriver\Interactions\Touch\WebDriverFlickFromElementAction;
  20. use Facebook\WebDriver\Interactions\Touch\WebDriverLongPressAction;
  21. use Facebook\WebDriver\Interactions\Touch\WebDriverMoveAction;
  22. use Facebook\WebDriver\Interactions\Touch\WebDriverScrollAction;
  23. use Facebook\WebDriver\Interactions\Touch\WebDriverScrollFromElementAction;
  24. use Facebook\WebDriver\Interactions\Touch\WebDriverTapAction;
  25. use Facebook\WebDriver\Interactions\Touch\WebDriverTouchScreen;
  26. use Facebook\WebDriver\WebDriver;
  27. use Facebook\WebDriver\WebDriverElement;
  28. use Facebook\WebDriver\WebDriverUpAction;
  29. /**
  30. * WebDriver action builder for touch events
  31. */
  32. class WebDriverTouchActions extends WebDriverActions
  33. {
  34. /**
  35. * @var WebDriverTouchScreen
  36. */
  37. protected $touchScreen;
  38. public function __construct(WebDriver $driver)
  39. {
  40. parent::__construct($driver);
  41. $this->touchScreen = $driver->getTouch();
  42. }
  43. /**
  44. * @param WebDriverElement $element
  45. * @return WebDriverTouchActions
  46. */
  47. public function tap(WebDriverElement $element)
  48. {
  49. $this->action->addAction(
  50. new WebDriverTapAction($this->touchScreen, $element)
  51. );
  52. return $this;
  53. }
  54. /**
  55. * @param int $x
  56. * @param int $y
  57. * @return WebDriverTouchActions
  58. */
  59. public function down($x, $y)
  60. {
  61. $this->action->addAction(
  62. new WebDriverDownAction($this->touchScreen, $x, $y)
  63. );
  64. return $this;
  65. }
  66. /**
  67. * @param int $x
  68. * @param int $y
  69. * @return WebDriverTouchActions
  70. */
  71. public function up($x, $y)
  72. {
  73. $this->action->addAction(
  74. new WebDriverUpAction($this->touchScreen, $x, $y)
  75. );
  76. return $this;
  77. }
  78. /**
  79. * @param int $x
  80. * @param int $y
  81. * @return WebDriverTouchActions
  82. */
  83. public function move($x, $y)
  84. {
  85. $this->action->addAction(
  86. new WebDriverMoveAction($this->touchScreen, $x, $y)
  87. );
  88. return $this;
  89. }
  90. /**
  91. * @param int $x
  92. * @param int $y
  93. * @return WebDriverTouchActions
  94. */
  95. public function scroll($x, $y)
  96. {
  97. $this->action->addAction(
  98. new WebDriverScrollAction($this->touchScreen, $x, $y)
  99. );
  100. return $this;
  101. }
  102. /**
  103. * @param WebDriverElement $element
  104. * @param int $x
  105. * @param int $y
  106. * @return WebDriverTouchActions
  107. */
  108. public function scrollFromElement(WebDriverElement $element, $x, $y)
  109. {
  110. $this->action->addAction(
  111. new WebDriverScrollFromElementAction($this->touchScreen, $element, $x, $y)
  112. );
  113. return $this;
  114. }
  115. /**
  116. * @param WebDriverElement $element
  117. * @return WebDriverTouchActions
  118. */
  119. public function doubleTap(WebDriverElement $element)
  120. {
  121. $this->action->addAction(
  122. new WebDriverDoubleTapAction($this->touchScreen, $element)
  123. );
  124. return $this;
  125. }
  126. /**
  127. * @param WebDriverElement $element
  128. * @return WebDriverTouchActions
  129. */
  130. public function longPress(WebDriverElement $element)
  131. {
  132. $this->action->addAction(
  133. new WebDriverLongPressAction($this->touchScreen, $element)
  134. );
  135. return $this;
  136. }
  137. /**
  138. * @param int $x
  139. * @param int $y
  140. * @return WebDriverTouchActions
  141. */
  142. public function flick($x, $y)
  143. {
  144. $this->action->addAction(
  145. new WebDriverFlickAction($this->touchScreen, $x, $y)
  146. );
  147. return $this;
  148. }
  149. /**
  150. * @param WebDriverElement $element
  151. * @param int $x
  152. * @param int $y
  153. * @param int $speed
  154. * @return WebDriverTouchActions
  155. */
  156. public function flickFromElement(WebDriverElement $element, $x, $y, $speed)
  157. {
  158. $this->action->addAction(
  159. new WebDriverFlickFromElementAction(
  160. $this->touchScreen,
  161. $element,
  162. $x,
  163. $y,
  164. $speed
  165. )
  166. );
  167. return $this;
  168. }
  169. }