samedi 14 janvier 2017

Custom annotation implementation for WebElements name in test report

I created test framework with Selenium and setup [ExtentReports][1] for test report. Used page object model and @FindBy annotation for fields to create own store of WebElements for each page. Now I would like to create custom annotation @Name

@Name(description = "google main page")
@FindBy(linkText = "Gmail")
private WebElement gmail;

And implementation for it, to be able to use description of each WebElement later in my report. I have my own implementation of click() method

public static void click(WebElement element) {
try{
    element.click();
    TestReport.addLog(LogStatus.INFO, "Element "+NameImpl.getDescription(element)+" clicked");
} catch (NoSuchElementException e) {
    TestReport.addLog(LogStatus.ERROR, "Element "+NameImpl.getDescription(element)+" not found");
}
}

I'm able to get description of all elements annotated in class with reflection like here

Is it possible to read the value of a annotation in java?

but cannot get description of specific element used in my click method.

Any ideas how to achieve that?





Aucun commentaire:

Enregistrer un commentaire