Skip to content

04. How to read from JSON to Page Factory

Hemanth Sridhar edited this page Sep 15, 2019 · 5 revisions

If we have a JSON for example

[
 {
"name": "forgottenPasswordLinkInAlert",
"type": "xpath",
"value": "//div[@role='alert']/descendant::a"
},
{
"name": "error_msg",
"type": "xpath",
"value": "//div[@role='alert']"
}
]
  • name : name of the locator
  • type : type of the locator
  • value : value of the locator

Then In the Page Objects class

@SearchBy(locatorsFile = PageObjectsConfig.ERROR_MSG_PAGE, nameOfTheLocator = "forgottenPasswordLinkInAlert")
private WebElement forgottenPasswordLinkInAlert;
  • The locatorsFile value must be the path to the json
  • The nameOfTheLocator value must be the same as the one provided in the json. In this case it is forgottenPasswordLinkInAlert