Search in sources :

Example 1 with ClickAction

use of org.openqa.selenium.interactions.ClickAction in project seleniumRobot by bhecquet.

the class CompositeActions method updateHandles.

/**
 * Update window handles when a click is requested in a composite Action (to get the same behavior between native clicks
 * and clicks in CompositeAction
 * Capture is done on all Action sub-classes, else it would never be done
 *
 * TO KEEP until ClickAction and other equivalents are there in selenium code
 *
 * @param joinPoint
 * @throws SecurityException
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 */
@Before("call(public void org.openqa.selenium.interactions.Action+.perform ())")
public void updateHandles(JoinPoint joinPoint) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    if (!(joinPoint.getTarget() instanceof CompositeAction)) {
        return;
    }
    CompositeAction compositeAction = (CompositeAction) joinPoint.getTarget();
    Field actionListField = CompositeAction.class.getDeclaredField("actionsList");
    actionListField.setAccessible(true);
    @SuppressWarnings("unchecked") List<Action> actionsList = (List<Action>) actionListField.get(compositeAction);
    boolean clickRequested = false;
    for (Action action : actionsList) {
        if (action instanceof ClickAction) {
            clickRequested = true;
        }
    }
    if (clickRequested) {
        ((CustomEventFiringWebDriver) WebUIDriver.getWebDriver(false)).updateWindowsHandles();
    }
}
Also used : Field(java.lang.reflect.Field) CompositeAction(org.openqa.selenium.interactions.CompositeAction) Action(org.openqa.selenium.interactions.Action) ClickAction(org.openqa.selenium.interactions.ClickAction) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) ClickAction(org.openqa.selenium.interactions.ClickAction) CompositeAction(org.openqa.selenium.interactions.CompositeAction) List(java.util.List) LinkedList(java.util.LinkedList) Before(org.aspectj.lang.annotation.Before)

Aggregations

CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)1 Field (java.lang.reflect.Field)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Before (org.aspectj.lang.annotation.Before)1 Action (org.openqa.selenium.interactions.Action)1 ClickAction (org.openqa.selenium.interactions.ClickAction)1 CompositeAction (org.openqa.selenium.interactions.CompositeAction)1