問題描述:需要創建自定義註釋,它創建以字符串作爲參數並對其進行處理,並在平靜框架中返回Weblement。 我已經通過自定義註釋+谷歌注入嘗試過代碼,但無法在運行時寧靜期間初始化我的頁面。 某人可以提供一些相同的指導嗎?Selenity框架自定義註釋創建初始化問題
代碼:
HomePage類
public class Homepage {
@FindBy(css = ".sbibod")
public SearchForm searchForm;
@AutoxpathAnnotation(ValuesPair = ".sbibod")
public WebElement searchForm2;
註釋接口
//import net.serenitybdd.core.annotations.findby.How;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface AutoxpathAnnotation {
String[] ValuesPair() default {"{Customer Service Name2}"};
}
Proceess實現
Class c = obj.getClass();
// Here need to Pass HomePage Object, Don't Know How to Pass through Page Object Model. Also need to know where this function needs to be written.
@SuppressWarnings("unchecked")
Annotation an = c.getAnnotation(AutoxpathAnnotation.class);
AutoxpathAnnotation ref = (AutoxpathAnnotation)an;
xapthform = "//label[contains(text(),'"+VisibleText+"')]/../following-sibling::*/select";
//Input will Handle Checkbox, Button and radioBox
if (type.equals("input")) {
xapthform = "//label[contains(text(),'"+VisibleText+"')]/../following-sibling::*/input";
if (type.equals("textarea")) {
xapthform = "//label[contains(text(),'"+VisibleText+"')]/../following-sibling::*/textarea";
}
System.out.println("Searching values on the Screen: ");
System.out.println("------------------------------------------------------");
return (WebElement) getDriver().findElement(By.xpath(xapthform));
我已經下文稱一些文檔,其使用s注入使用guice
public class DriverModule extends AbstractModule implements MethodInterceptor {
@Inject
private WebDriver driver;
private static Injector injector;
@Override
protected void configure() {
bind(WebDriver.class)
.toProvider(WebDriverProvider.class)
.in(Singleton.class);
//Todo some Operation
}
But not sure how it will work exactly in RunTime.
我試過了,但沒能注入我註釋處理。它無法調用我的課程。 – user216112