I want to prepare the test where selenium has to read the data (username and password) from excel file and feed them in to login fields.
I'm using thucydides framework with selenium 2.0.
How can I do it?
Thank you.
I want to prepare the test where selenium has to read the data (username and password) from excel file and feed them in to login fields.
I'm using thucydides framework with selenium 2.0.
How can I do it?
Thank you.
Is "excel" a requirement?
You can always covert excel file to CSV format (save as...) and then Thucydides can work with it as described here
Test Data:
NAME,AGE,PLACE OF BIRTH
Jack Smith, 30, Smithville
Joe Brown, 40, Brownville
Mary Williams, 20, Williamsville
Code:
@RunWith(ThucydidesParameterizedRunner.class)
@UseTestDataFrom("test-data/simple-data.csv")
public class SampleCSVDataDrivenScenario {
private String name;
private String age;
private String placeOfBirth;
public SampleCSVDataDrivenScenario() {
}
@Qualifier
public String getQualifier() {
return name;
}
@Managed
public WebDriver webdriver;
@ManagedPages(defaultUrl = "http://www.google.com")
public Pages pages;
@Steps
public SampleScenarioSteps steps;
@Test
public void data_driven_test() {
System.out.println(getName() + "/" + getAge() + "/" + getCity());
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getPlaceOfBirth() {
return placeOfBirth;
}
public void setPlaceOfBirth(String placeOfBirth) {
this.placeOfBirth = placeOfBirth;
}
}
Use testNG data provider or use property file
testNG example
@DataProvider(name = "testData")
public Object[][] testData() throws Exception {
Object[][] results;
ArrayList<Object[]> resultArray = new ArrayList<Object[]>();
resultArray.add(new Object[] { "Test1" });
resultArray.add(new Object[] { "Test2" });
results = resultArray.toArray(new Object[resultArray.size()][]);
return results;
}
@Test( dataProvider = "testData")
public static void main(String testName) {
System.out.println(testName);
}
Result :
Test1
Test2
in your case you can add any user name and password that you want and run the same test