org.jbehave.web.selenium.pico.WebDriverConstructorAndSetterInjection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbehave-web-selenium Show documentation
Show all versions of jbehave-web-selenium Show documentation
Selenium and WebDriver API bindings for JBehave
The newest version!
package org.jbehave.web.selenium.pico;
import org.openqa.selenium.WebElement;
import org.picocontainer.ComponentAdapter;
import org.picocontainer.ComponentMonitor;
import org.picocontainer.LifecycleStrategy;
import org.picocontainer.Parameter;
import org.picocontainer.PicoCompositionException;
import org.picocontainer.injectors.CompositeInjection;
import org.picocontainer.injectors.ConstructorInjection;
import org.picocontainer.injectors.SetterInjection;
import org.picocontainer.injectors.SetterInjector;
import java.lang.reflect.Method;
import java.util.Properties;
@SuppressWarnings("serial")
public class WebDriverConstructorAndSetterInjection extends CompositeInjection {
public WebDriverConstructorAndSetterInjection() {
super(new ConstructorInjection(),
new SetterInjection() {
@Override
public ComponentAdapter createComponentAdapter(ComponentMonitor monitor, LifecycleStrategy lifecycleStrategy, Properties componentProperties, Object componentKey, Class componentImplementation, Parameter... parameters) throws PicoCompositionException {
return new SetterInjector(componentKey, componentImplementation, parameters, monitor, "set", "", false, true) {
@Override
protected boolean isInjectorMethod(Method method) {
Class> type = method.getParameterTypes()[0];
// WebElements as properties, are not injected by PicoContainer.
// See http://code.google.com/p/selenium/wiki/PageFactory
// Similarly, there are some inner-class properties made by Groovy's
// compiler that should not be injected.
if (type.equals(WebElement.class) || type.getName().matches("^.*Component$")) {
return false;
}
return super.isInjectorMethod(method);
}
};
}
});
}
}