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