-
-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make scroll tracking configurable with a cap #284
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,10 @@ | |
|
||
import io.appium.uiautomator2.common.exceptions.UiAutomator2Exception; | ||
|
||
import io.appium.uiautomator2.model.AppiumUIA2Driver; | ||
import io.appium.uiautomator2.model.Session; | ||
import io.appium.uiautomator2.utils.Logger; | ||
|
||
import static io.appium.uiautomator2.utils.ReflectionUtils.invoke; | ||
import static io.appium.uiautomator2.utils.ReflectionUtils.method; | ||
|
||
|
@@ -32,6 +36,7 @@ public class InteractionController { | |
private static final String METHOD_TOUCH_DOWN = "touchDown"; | ||
private static final String METHOD_TOUCH_UP = "touchUp"; | ||
private static final String METHOD_TOUCH_MOVE = "touchMove"; | ||
private static final String TRACK_SCROLL_EVENT_CAP = "trackScrollEvents"; | ||
private final Object interactionController; | ||
|
||
public InteractionController(Object interactionController) { | ||
|
@@ -62,48 +67,92 @@ public boolean injectEventSync(final InputEvent event) throws UiAutomator2Except | |
return injectEventSync(event, true); | ||
} | ||
|
||
public boolean shouldTrackScrollEvents() { | ||
Session session = AppiumUIA2Driver.getInstance().getSessionOrThrow(); | ||
Boolean trackScrollEvents = true; | ||
if (session.hasCapability(TRACK_SCROLL_EVENT_CAP)) { | ||
try { | ||
trackScrollEvents = (Boolean) session.getCapability(TRACK_SCROLL_EVENT_CAP); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about using String.format? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same below There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally think the |
||
Logger.error("Capability '" + TRACK_SCROLL_EVENT_CAP + "': " + trackScrollEvents); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this meant to be an error log? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, no. That was just all that would show up in my logs without fiddling. I'll fix. |
||
} catch (Exception e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is getCapability supposed to throw an exception? |
||
Logger.error("Could not set '" + TRACK_SCROLL_EVENT_CAP + "' from capability: ", e); | ||
trackScrollEvents = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is redundant |
||
} | ||
} | ||
|
||
return trackScrollEvents; | ||
} | ||
|
||
private boolean doTouchDown(final int x, final int y) { | ||
return (Boolean) invoke(method(CLASS_INTERACTION_CONTROLLER, | ||
METHOD_TOUCH_DOWN, int.class, int.class), interactionController, x, y); | ||
} | ||
|
||
public boolean touchDown(final int x, final int y) throws UiAutomator2Exception { | ||
return EventRegister.runAndRegisterScrollEvents(new ReturningRunnable<Boolean>() { | ||
@Override | ||
public void run() { | ||
Boolean result = (Boolean) invoke(method(CLASS_INTERACTION_CONTROLLER, | ||
METHOD_TOUCH_DOWN, int.class, int.class), interactionController, x, y); | ||
setResult(result); | ||
} | ||
}); | ||
if (shouldTrackScrollEvents()) { | ||
return EventRegister.runAndRegisterScrollEvents(new ReturningRunnable<Boolean>() { | ||
@Override | ||
public void run() { | ||
setResult(doTouchDown(x, y)); | ||
} | ||
}); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. else is redundant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same below |
||
return doTouchDown(x, y); | ||
} | ||
} | ||
|
||
private boolean doTouchUp(final int x, final int y) { | ||
return (Boolean) invoke(method(CLASS_INTERACTION_CONTROLLER, METHOD_TOUCH_UP, | ||
int.class, int.class), interactionController, x, y); | ||
} | ||
|
||
public boolean touchUp(final int x, final int y) throws UiAutomator2Exception { | ||
return EventRegister.runAndRegisterScrollEvents(new ReturningRunnable<Boolean>() { | ||
@Override | ||
public void run() { | ||
Boolean result = (Boolean) invoke(method(CLASS_INTERACTION_CONTROLLER, METHOD_TOUCH_UP, | ||
int.class, int.class), interactionController, x, y); | ||
setResult(result); | ||
} | ||
}); | ||
if (shouldTrackScrollEvents()) { | ||
return EventRegister.runAndRegisterScrollEvents(new ReturningRunnable<Boolean>() { | ||
@Override | ||
public void run() { | ||
setResult(doTouchUp(x, y)); | ||
} | ||
}); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spacing seems off in this block |
||
return doTouchUp(x, y); | ||
} | ||
} | ||
|
||
private boolean doTouchMove(final int x, final int y) { | ||
return (Boolean) invoke(method(CLASS_INTERACTION_CONTROLLER, | ||
METHOD_TOUCH_MOVE, int.class, int.class), interactionController, x, y); | ||
} | ||
|
||
public boolean touchMove(final int x, final int y) throws UiAutomator2Exception { | ||
return EventRegister.runAndRegisterScrollEvents(new ReturningRunnable<Boolean>() { | ||
@Override | ||
public void run() { | ||
Boolean result = (Boolean) invoke(method(CLASS_INTERACTION_CONTROLLER, | ||
METHOD_TOUCH_MOVE, int.class, int.class), interactionController, x, y); | ||
setResult(result); | ||
} | ||
}); | ||
if (shouldTrackScrollEvents()) { | ||
return EventRegister.runAndRegisterScrollEvents(new ReturningRunnable<Boolean>() { | ||
@Override | ||
public void run() {; | ||
setResult(doTouchMove(x, y)); | ||
} | ||
}); | ||
} else { | ||
return doTouchMove(x, y); | ||
} | ||
} | ||
|
||
private boolean doPerformMultiPointerGesture(final PointerCoords[][] pcs) { | ||
return (Boolean) invoke(method(CLASS_INTERACTION_CONTROLLER, | ||
METHOD_PERFORM_MULTI_POINTER_GESTURE, PointerCoords[][].class), | ||
interactionController, (Object) pcs); | ||
} | ||
|
||
public Boolean performMultiPointerGesture(final PointerCoords[][] pcs) throws UiAutomator2Exception { | ||
return EventRegister.runAndRegisterScrollEvents(new ReturningRunnable<Boolean>() { | ||
@Override | ||
public void run() { | ||
Boolean result = (Boolean) invoke(method(CLASS_INTERACTION_CONTROLLER, | ||
METHOD_PERFORM_MULTI_POINTER_GESTURE, PointerCoords[][].class), | ||
interactionController, (Object) pcs); | ||
setResult(result); | ||
} | ||
}); | ||
if (shouldTrackScrollEvents()) { | ||
return EventRegister.runAndRegisterScrollEvents(new ReturningRunnable<Boolean>() { | ||
@Override | ||
public void run() { | ||
setResult(doPerformMultiPointerGesture(pcs)); | ||
} | ||
}); | ||
} else { | ||
return doPerformMultiPointerGesture(pcs); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather make it an appium setting