How to pass data from XML file into application and I'm using page object model with page factory.
Code:
public class LoginPage extends BaseClass {
@FindBy(id="EmailAddress")
WebElement username;
@FindBy(id="Password")
WebElement password;
@FindBy(id="EligibilityNumber")
WebElement click;
@FindBy(id="CaptchaInputText")
WebElement captchavalue;
@FindBy(id="loginBtn")
WebElement Login;
public LoginPage()
{
PageFactory.initElements(driver, this);
}
public personal_details login(String username1, String password1)
{
username.sendKeys(username1);
password.sendKeys(password1);
Login.click();
return new personal_details();
}
testutils:
XML code:
public static void readxml()
{
try {
File fXmlFile = new File("E:\\DATAFLOWAUTOMATIONFRAMEWOK\\xml\\a.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("staff");
System.out.println("----------------------------");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
System.out.println("\nCurrent Element :" + nNode.getNodeName());
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
String id1= eElement.getAttribute("id");
//String username1=eElement.getElementsByTagName("username").item(0).getTextContent();
//String password1= eElement.getElementsByTagName("password").item(0).getTextContent();
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Test method code:
public class LoginTest extends BaseClass {
LoginPage loginpage;
personal_details pd;
private String password1;
public LoginTest()
{
super();
}
@BeforeMethod
public void setup()
{
initialization();
loginpage=new LoginPage();
}
@Test
public void loginmethod()
{
loginpage.login(username1,password1);// how to pass code here, could you please let me know
}
}