I have written a selenium framework using page object
design pattern. To make it better I am also using PageFactory
.
Example:
BasePage.java
@FindBy(xpath= FinalLocators.userName)
WebElement uname;
@FindBy(xpath= FinalLocators.userpass)
WebElement userpwd;
sendkeys.uname("johndoe");
sendkeys.userpwd("kitty");
FinalLocators.java
public static final String userName=//input[text()='username']
public static final String userpass=//input[text()='password']
Now, I want loggers (log4j
) to give me:
Element uname
not found. I want the WebElement
name to be in logs not the xpath
declared in FinalLocators
.
Edit:
In non PageFactory
projects it is written something like this:
public void sendData(String xpathKey){
try{
driver.findElement(By.xpath(OR.getProperty(xpathKey))).sendKeys("abc");
logger.info("Found "+xpathKey);
}catch(Exception e){
logger.info("wait started for "+xpathKey);
}
}
But in PageFactory
based framework how to write such a generic function?