/** * Checks if some annotation is present in the given array of annotations * * @param annotations - array of annotations * @param needle - annotation we are looking for * @return if the annotation is present an the given array of annotations */ private static boolean isAnnotationPresent(final Annotation[] annotations, final Class<? extends Annotation> needle) { return findAnnotation(annotations, needle) != null; }
@Override public void enrich(SearchContext searchContext, Object target) { List<Field> fields = ReflectionHelper.getFields(target.getClass()); for (Field field : fields) { checkFieldValidity(searchContext, target, field); } }
public static List<Field> getListOfFieldsAnnotatedWithFindBys(Object target) { List<Field> fields = ReflectionHelper.getFieldsWithAnnotation(target.getClass(), FindBy.class); fields.addAll(ReflectionHelper.getFieldsWithAnnotation(target.getClass(), FindBys.class)); fields.addAll(ReflectionHelper.getFieldsWithAnnotatedAnnotation(target.getClass(), ImplementsLocationStrategy.class)); return fields; } }
@Override public void enrich(final SearchContext searchContext, Object target) { Collection<Field> fields = ReflectionHelper.getFieldsWithAnnotation(target.getClass(), JavaScript.class); for (Field field : fields) { GrapheneContext grapheneContext = searchContext == null ? null : ((GrapheneProxyInstance) searchContext).getGrapheneContext(); if (grapheneContext == null) { grapheneContext = GrapheneContext.getContextFor(ReflectionHelper.getQualifier(field.getAnnotations())); } if (!field.isAccessible()) { field.setAccessible(true); } try { field.set(target, JSInterfaceFactory.create(grapheneContext, field.getType())); } catch (Exception e) { throw new IllegalStateException("Can't inject value to the field '" + field.getName() + "' declared in class '" + field.getDeclaringClass().getName() + "'", e); } } }
@Override public Object lookup(ArquillianResource resource, Annotation... qualifiers) { return GrapheneContext.getContextFor(ReflectionHelper.getQualifier(qualifiers)); }
@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; }
final ClassLoader tccl = getThreadContextClassLoader(); final Class<?> implClass = Class.forName(className, false, tccl); Constructor<?> constructor = getConstructor(implClass, argumentTypes); obj = constructor.newInstance(arguments); } catch (Exception e) {
if (ReflectionHelper.hasConstructor(clazz, argTypes)) { construtor = clazz.getDeclaredConstructor(argTypes); } else { construtor = ReflectionHelper.getAssignableConstructor(clazz, argTypes);
@Override public void enrich(final SearchContext searchContext, Object target) { List<Field> fields = new LinkedList<Field>(); fields.addAll(ReflectionHelper.getFieldsWithAnnotation(target.getClass(), Page.class)); for (Field field : fields) { Object page = createPage(searchContext, field.getAnnotations(), target, field, null, null); setValue(field, target, page); } }
protected final boolean isValidClass(Class<?> clazz) { Class<?> outerClass = clazz.getDeclaringClass(); if (outerClass == null || Modifier.isStatic(clazz.getModifiers())) { if (clazz.equals(GrapheneElement.class)) { return true; } else { return ReflectionHelper.hasConstructor(clazz, WebElement.class); } } else { return ReflectionHelper.hasConstructor(clazz, outerClass, WebElement.class); } }
public static boolean isClassPresent(String name) { try { ClassLoader classLoader = getThreadContextClassLoader(); classLoader.loadClass(name); return true; } catch (ClassNotFoundException e) { return 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, Page.class)); for (int i = 0; i < resolvedParams.length; i++) { if (paramCouple.get(i) != null) { Class<?> param = (Class<?>) paramCouple.get(i)[0]; Annotation[] parameterAnnotations = (Annotation[]) paramCouple.get(i)[1]; Object page = createPage(searchContext, parameterAnnotations, null, null, method, param); resolvedParams[i] = page; } } return resolvedParams; }
@Override public Object lookup(ArquillianResource resource, Annotation... qualifiers) { return GrapheneContext.getContextFor(ReflectionHelper.getQualifier(qualifiers)); }
@Override public void enrich(final SearchContext searchContext, Object target) { Collection<Field> fields = ReflectionHelper.getFieldsWithAnnotation(target.getClass(), JavaScript.class); for (Field field : fields) { GrapheneContext grapheneContext = searchContext == null ? null : ((GrapheneProxyInstance) searchContext).getGrapheneContext(); if (grapheneContext == null) { grapheneContext = GrapheneContext.getContextFor(ReflectionHelper.getQualifier(field.getAnnotations())); } if (!field.isAccessible()) { field.setAccessible(true); } try { field.set(target, JSInterfaceFactory.create(grapheneContext, field.getType())); } catch (Exception e) { throw new IllegalStateException("Can't inject value to the field '" + field.getName() + "' declared in class '" + field.getDeclaringClass().getName() + "'", e); } } }
@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; }
final ClassLoader tccl = getThreadContextClassLoader(); final Class<?> implClass = Class.forName(className, false, tccl); Constructor<?> constructor = getConstructor(implClass, argumentTypes); obj = constructor.newInstance(arguments); } catch (Exception e) {
if (ReflectionHelper.hasConstructor(clazz, argTypes)) { construtor = clazz.getDeclaredConstructor(argTypes); } else { construtor = ReflectionHelper.getAssignableConstructor(clazz, argTypes);
@Override public void enrich(final SearchContext searchContext, Object target) { List<Field> fields = new LinkedList<Field>(); fields.addAll(ReflectionHelper.getFieldsWithAnnotation(target.getClass(), Page.class)); for (Field field : fields) { Object page = createPage(searchContext, field.getAnnotations(), target, field, null, null); setValue(field, target, page); } }
protected final boolean isValidClass(Class<?> clazz) { Class<?> outerClass = clazz.getDeclaringClass(); if (outerClass == null || Modifier.isStatic(clazz.getModifiers())) { if (clazz.equals(GrapheneElement.class)) { return true; } else { return ReflectionHelper.hasConstructor(clazz, WebElement.class); } } else { return ReflectionHelper.hasConstructor(clazz, outerClass, WebElement.class); } }
public static boolean isClassPresent(String name) { try { ClassLoader classLoader = getThreadContextClassLoader(); classLoader.loadClass(name); return true; } catch (ClassNotFoundException e) { return false; } }