org.jboss.arquillian.graphene.enricher.InFrameEnricher Maven / Gradle / Ivy
/**
* JBoss, Home of Professional Open Source
* Copyright 2013, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.arquillian.graphene.enricher;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import org.jboss.arquillian.graphene.enricher.exception.GrapheneTestEnricherException;
import org.jboss.arquillian.graphene.page.InFrame;
import org.jboss.arquillian.graphene.proxy.GrapheneProxyInstance;
import org.openqa.selenium.SearchContext;
/**
* @author Juraj Huska
*/
public class InFrameEnricher extends AbstractSearchContextEnricher {
@Override
public void enrich(SearchContext searchContext, Object objectToEnrich) {
Collection 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
© 2015 - 2025 Weber Informatics LLC | Privacy Policy