use of org.openqa.selenium.interactions.InputSource in project seleniumRobot by bhecquet.
the class ReplayAction method updateScrollFlagForElement.
/**
* Updates the scrollToelementBeforeAction flag of HtmlElement for CompositeActions
* Therefore, it looks at origin field of PointerInput$Move CompositeAction and update the flag
* @throws SecurityException
* @throws NoSuchFieldException
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
private void updateScrollFlagForElement(ProceedingJoinPoint joinPoint, Boolean forcedValue, WebDriverException parentException) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
Object actions = joinPoint.getTarget();
// Only the later case is covered here
if (!actions.getClass().toString().contains("BuiltAction")) {
return;
}
Field sequencesField = actions.getClass().getDeclaredField("sequences");
sequencesField.setAccessible(true);
Map<InputSource, Sequence> sequences = (Map<InputSource, Sequence>) sequencesField.get(actions);
for (Sequence sequence : sequences.values()) {
Field actionsField = Sequence.class.getDeclaredField("actions");
actionsField.setAccessible(true);
LinkedList<Interaction> actionsList = (LinkedList<Interaction>) actionsField.get(sequence);
for (Interaction action : actionsList) {
if (action.getClass().getName().contains("PointerInput$Move")) {
Field originField = action.getClass().getDeclaredField("origin");
originField.setAccessible(true);
try {
PointerInput.Origin origin = (PointerInput.Origin) originField.get(action);
// so that it can be treated elsewhere (mainly inside replayHtmlElement())
if (origin.asArg() instanceof HtmlElement) {
HtmlElement element = (HtmlElement) origin.asArg();
if (forcedValue == null) {
if (element.isScrollToElementBeforeAction()) {
element.setScrollToElementBeforeAction(false);
} else {
element.setScrollToElementBeforeAction(true);
}
} else {
element.setScrollToElementBeforeAction(forcedValue);
}
} else if (origin.asArg() instanceof RemoteWebElement && parentException != null) {
throw parentException;
}
} catch (ClassCastException e1) {
// nothing
}
}
}
}
}
Aggregations