Description du problème: Vous devez créer une annotation personnalisée qui crée une chaîne de caractères en tant qu'argument et la traite et renvoie Weblement dans le cadre de sérénité. J'ai essayé le code via des annotations personnalisées + google inject mais je n'ai pas pu initialiser ma page pendant la sérénité d'exécution. Est-ce que somebod peut fournir des conseils sur la même chose?Problème d'initialisation de la création d'annotations personnalisées avec Serenity Framework
code:
HomePage Classe
public class Homepage {
@FindBy(css = ".sbibod")
public SearchForm searchForm;
@AutoxpathAnnotation(ValuesPair = ".sbibod")
public WebElement searchForm2;
Interface Annotation
//import net.serenitybdd.core.annotations.findby.How;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface AutoxpathAnnotation {
String[] ValuesPair() default {"{Customer Service Name2}"};
}
Proceess Implémentations
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));
Je reffered certains documents dont l'utilisation s injection-using-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.
J'ai essayé, mais pas en mesure d'injecter mon traitement d'annotation. il n'est pas capable d'invoquer ma classe. – user216112