private void checkInFrameParameters(Method method, Class<?> param, int index, String nameOrId) { if (checkInFrameParameters(index, nameOrId)) { throw new GrapheneTestEnricherException( "You have to provide either non empty nameOrId or non negative index value of the frame/iframe in the @InFrame. Check parameter " + param + " of the method: " + method.getName() + " declared in: " + method.getDeclaringClass()); } }
private void registerInFrameInterceptor(Object objectToEnrich, Field field, int index, String nameOrId) throws IllegalAccessException, ClassNotFoundException { GrapheneProxyInstance proxy = (GrapheneProxyInstance) field.get(objectToEnrich); registerInFrameInterceptor(proxy, index, nameOrId); }
@Override public void enrich(SearchContext searchContext, Object objectToEnrich) { Collection<Field> inFrameFields = ReflectionHelper.getFieldsWithAnnotation(objectToEnrich.getClass(), InFrame.class); for (Field field : inFrameFields) { boolean isAccessible = field.isAccessible(); if (!isAccessible) { field.setAccessible(true); } InFrame inFrame = field.getAnnotation(InFrame.class); int index = inFrame.index(); String nameOrId = inFrame.nameOrId(); checkInFrameParameters(field, index, nameOrId); try { registerInFrameInterceptor(objectToEnrich, field, index, nameOrId); } catch (IllegalArgumentException e) { throw new GrapheneTestEnricherException( "Only org.openqa.selenium.WebElement, Page fragments fields and Page Object fields can be annotated with @InFrame. Check the field: " + field + " declared in the class: " + objectToEnrich.getClass(), e); } catch (Exception e) { throw new GrapheneTestEnricherException(e); } if (!isAccessible) { field.setAccessible(false); } } }
@Override public Object[] resolve(SearchContext searchContext, Method method, Object[] resolvedParams) { StringBuffer errorMsgBegin = new StringBuffer(""); List<Object[]> paramCouple = new LinkedList<Object[]>(); paramCouple.addAll(ReflectionHelper.getParametersWithAnnotation(method, InFrame.class)); for (int i = 0; i < resolvedParams.length; i++) { if (paramCouple.get(i) != null && resolvedParams[i] != null) { Class<?> param = (Class<?>) paramCouple.get(i)[0]; Annotation[] parameterAnnotations = (Annotation[]) paramCouple.get(i)[1]; InFrame inFrame = ReflectionHelper.findAnnotation(parameterAnnotations, InFrame.class); int index = inFrame.index(); String nameOrId = inFrame.nameOrId(); checkInFrameParameters(method, param, index, nameOrId); try { registerInFrameInterceptor((GrapheneProxyInstance) resolvedParams[i], index, nameOrId); } catch (IllegalArgumentException e) { throw new GrapheneTestEnricherException( "Only org.openqa.selenium.WebElement, Page fragments fields and Page Object fields can be annotated with @InFrame. Check parameter " + param + " of the method: " + method.getName() + " declared in: " + method .getDeclaringClass(), e); } catch (Exception e) { throw new GrapheneTestEnricherException(e); } } } return resolvedParams; }
@Override public void enrich(SearchContext searchContext, Object objectToEnrich) { Collection<Field> inFrameFields = ReflectionHelper.getFieldsWithAnnotation(objectToEnrich.getClass(), InFrame.class); for (Field field : inFrameFields) { boolean isAccessible = field.isAccessible(); if (!isAccessible) { field.setAccessible(true); } InFrame inFrame = field.getAnnotation(InFrame.class); int index = inFrame.index(); String nameOrId = inFrame.nameOrId(); checkInFrameParameters(field, index, nameOrId); try { registerInFrameInterceptor(objectToEnrich, field, index, nameOrId); } catch (IllegalArgumentException e) { throw new GrapheneTestEnricherException( "Only org.openqa.selenium.WebElement, Page fragments fields and Page Object fields can be annotated with @InFrame. Check the field: " + field + " declared in the class: " + objectToEnrich.getClass(), e); } catch (Exception e) { throw new GrapheneTestEnricherException(e); } if (!isAccessible) { field.setAccessible(false); } } }
private void checkInFrameParameters(Field field, int index, String nameOrId) { if (checkInFrameParameters(index, nameOrId)) { throw new GrapheneTestEnricherException( "You have to provide either non empty nameOrId or non negative index value of the frame/iframe in the @InFrame. Check field " + field + " declared in: " + field.getDeclaringClass()); } }
private void registerInFrameInterceptor(Object objectToEnrich, Field field, int index, String nameOrId) throws IllegalAccessException, ClassNotFoundException { GrapheneProxyInstance proxy = (GrapheneProxyInstance) field.get(objectToEnrich); registerInFrameInterceptor(proxy, index, nameOrId); }
@Override public Object[] resolve(SearchContext searchContext, Method method, Object[] resolvedParams) { StringBuffer errorMsgBegin = new StringBuffer(""); List<Object[]> paramCouple = new LinkedList<Object[]>(); paramCouple.addAll(ReflectionHelper.getParametersWithAnnotation(method, InFrame.class)); for (int i = 0; i < resolvedParams.length; i++) { if (paramCouple.get(i) != null && resolvedParams[i] != null) { Class<?> param = (Class<?>) paramCouple.get(i)[0]; Annotation[] parameterAnnotations = (Annotation[]) paramCouple.get(i)[1]; InFrame inFrame = ReflectionHelper.findAnnotation(parameterAnnotations, InFrame.class); int index = inFrame.index(); String nameOrId = inFrame.nameOrId(); checkInFrameParameters(method, param, index, nameOrId); try { registerInFrameInterceptor((GrapheneProxyInstance) resolvedParams[i], index, nameOrId); } catch (IllegalArgumentException e) { throw new GrapheneTestEnricherException( "Only org.openqa.selenium.WebElement, Page fragments fields and Page Object fields can be annotated with @InFrame. Check parameter " + param + " of the method: " + method.getName() + " declared in: " + method .getDeclaringClass(), e); } catch (Exception e) { throw new GrapheneTestEnricherException(e); } } } return resolvedParams; }
private void checkInFrameParameters(Field field, int index, String nameOrId) { if (checkInFrameParameters(index, nameOrId)) { throw new GrapheneTestEnricherException( "You have to provide either non empty nameOrId or non negative index value of the frame/iframe in the @InFrame. Check field " + field + " declared in: " + field.getDeclaringClass()); } }
private void checkInFrameParameters(Method method, Class<?> param, int index, String nameOrId) { if (checkInFrameParameters(index, nameOrId)) { throw new GrapheneTestEnricherException( "You have to provide either non empty nameOrId or non negative index value of the frame/iframe in the @InFrame. Check parameter " + param + " of the method: " + method.getName() + " declared in: " + method.getDeclaringClass()); } }