qaf
qaf copied to clipboard
Support to define component with locator repository
Self descriptive locator has capability to provide meta-data with the locator. There can be a way where user can define component class in meta-data that can be used to create element from the locator by the framework.
How to use component-class
to init List of Component?
I have tried below code but its not working as expected.
My locator is
productdetail.grid={"locator":"xpath=//*[@content-desc='product_list']","desc":"product detail","component-class":"com.flipkart.component.SearchResultComponent"}
My java code
List<QAFWebElement> productList = getDriver().findElements("productdetail.grid");
for (int i = 0; i < productList.size() - 1; i++) {
((SearchResultComponent) productList.get(i)).getProductName());
}
It throws java.lang.ClassCastException. com.qmetry.qaf.automation.ui.webdriver.QAFExtendedWebElement cannot be cast to com.flipkart.component.SearchResultComponent.
I am using qaf version 2.1.13.
Custom component list with driver.findElements(loc)
is not supported at present. I am reopening this issue for support of driver.findElements(loc)
. By the time you can warp it in search Result component For instance:
productdetail.grid={"locator":"xpath=.//*[@content-desc='product_list']","desc":"product detail"}
search.results.containter={"locator":"<container loc>","desc":"product detail","component-class":"com.flipkart.component.SearchResultsContainer"}
public class SearchResultsContainer extends QAFWebComponent{
@FindBy("locator"="productdetail.grid")
List<SearchResultComponent> searchResults;
...
}
SearchResultsContainer resultContainer = (SearchResultsContainer)getDriver().findElement("search.results.containter");
//or short hand
//import static com.qmetry.qaf.automation.ui.webdriver.ElementFactory.$;
//SearchResultsContainer resultContainer = (SearchResultsContainer)$("search.results.containter");
List<SearchResultComponent> searchResults = resultContainer.getSearchResults();