I ran into a situation whereas I defined a customize annotation class (SeleniumTest.java), and use that annotation in another class(AppSeleniumTest.java). However, I need pass in a constructor parameter to one of the @Autowired field (AppSeleniumTest.driver). Anyone knows the best way to do that?
Code snippet:
SeleniumTest.java
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface SeleniumTest {
Class<? extends WebDriver> driver() default PhantomJSDriver.class;
}
AppSeleniumTest.java
@RunWith(SpringRunner.class)
@SeleniumTest
public class AppSeleniumTest {
@Autowired
private WebDriver driver; // Basically here, we want driver=new PhantomJSDriver(NEED_GIVE_PARAMETER) instead of just driver=new PhatomJSDriver(); by default.
}
one clue I might have is instead of @SeleniumTest
in AppSeleniumTest.java, we might give @SeleniumTest(driver = PhantomJSDriver.class)
. But how can we pass in parameters to this PhantomJSDriver's constructor?
Any hints much appreciated. Thanks