|
44 | 44 | import org.cerberus.core.util.StringUtil;
|
45 | 45 | import org.json.JSONException;
|
46 | 46 | import org.openqa.selenium.*;
|
| 47 | +import org.openqa.selenium.interactions.PointerInput; |
| 48 | +import org.openqa.selenium.interactions.Sequence; |
47 | 49 | import org.openqa.selenium.support.ui.ExpectedConditions;
|
48 | 50 | import org.openqa.selenium.support.ui.WebDriverWait;
|
49 | 51 | import org.springframework.beans.factory.annotation.Autowired;
|
50 | 52 |
|
51 | 53 | import java.awt.geom.Line2D;
|
52 | 54 | import java.time.Duration;
|
| 55 | +import java.util.Arrays; |
| 56 | +import java.util.List; |
53 | 57 | import java.util.Set;
|
54 | 58 | import java.util.concurrent.TimeUnit;
|
55 | 59 | import java.util.regex.Matcher;
|
@@ -193,22 +197,40 @@ public MessageEvent type(Session session, Identifier identifier, String valueToT
|
193 | 197 | public MessageEvent click(final Session session, final Identifier identifier, Integer hOffset, Integer vOffset) {
|
194 | 198 | try {
|
195 | 199 | MessageEvent foundElementMsg;
|
196 |
| - final TouchAction action = new TouchAction((PerformsTouchActions)session.getAppiumDriver()); |
| 200 | + AppiumDriver appiumDriver = session.getAppiumDriver(); |
| 201 | + |
| 202 | + final PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger"); |
197 | 203 |
|
198 | 204 | if (identifier.isSameIdentifier(Identifier.Identifiers.COORDINATE)) {
|
199 | 205 | final Coordinates coordinates = getCoordinates(identifier);
|
200 | 206 | Point offset = new Point(coordinates.getX(), coordinates.getY());
|
201 | 207 | foundElementMsg = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_FOUND_ELEMENT);
|
202 | 208 | foundElementMsg.resolveDescription("NUMBER", "1");
|
203 | 209 | foundElementMsg.resolveDescription("ELEMENT", identifier.toString());
|
204 |
| - action.tap(PointOption.point(offset)).perform(); |
| 210 | + |
| 211 | + Sequence tapSequence = new Sequence(finger, 0); |
| 212 | + tapSequence.addAction(finger.createPointerMove( |
| 213 | + Duration.ofMillis(0), PointerInput.Origin.viewport(), offset.getX(), offset.getY())); |
| 214 | + tapSequence.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg())); |
| 215 | + tapSequence.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg())); |
| 216 | + appiumDriver.perform(List.of(tapSequence)); |
205 | 217 | } else {
|
206 | 218 | WebElement element = getElement(session, identifier, false, false);
|
207 | 219 | Integer numberOfElement = this.getNumberOfElements(session, identifier);
|
208 | 220 | foundElementMsg = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_FOUND_ELEMENT);
|
209 | 221 | foundElementMsg.resolveDescription("NUMBER", numberOfElement.toString());
|
210 | 222 | foundElementMsg.resolveDescription("ELEMENT", identifier.toString());
|
211 |
| - action.tap(ElementOption.element(element, hOffset, vOffset)).perform(); |
| 223 | + |
| 224 | + Rectangle rect = element.getRect(); |
| 225 | + int elementX = rect.getX() + (hOffset != null ? hOffset : rect.getWidth() / 2); |
| 226 | + int elementY = rect.getY() + (vOffset != null ? vOffset : rect.getHeight() / 2); |
| 227 | + |
| 228 | + Sequence tapSequence = new Sequence(finger, 0); |
| 229 | + tapSequence.addAction(finger.createPointerMove( |
| 230 | + Duration.ofMillis(0), PointerInput.Origin.viewport(), elementX, elementY)); |
| 231 | + tapSequence.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg())); |
| 232 | + tapSequence.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg())); |
| 233 | + appiumDriver.perform(List.of(tapSequence)); |
212 | 234 | }
|
213 | 235 | return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLICK).resolveDescription("ELEMENT", identifier.toString()).resolveDescription("ELEMENTFOUND", foundElementMsg.getDescription());
|
214 | 236 | } catch (NoSuchElementException e) {
|
|
0 commit comments