[英]Is there efficient way to retrieve and use test data in Selenium
I'm automating search functionality and want to perform data driven test on it. 我正在自动执行搜索功能,并希望对其执行数据驱动的测试。 I'm using an Excel sheet to store the test data and using Apache POI libraries to read the same.
我正在使用Excel工作表存储测试数据,并使用Apache POI库读取相同的数据。 This is how testdata stored.
这就是testdata的存储方式。
I've one common class in my Framework to read the data from excel file where i have to pass the sheet number while calling the method as mentioned below : 我在我的框架中有一个通用类,可以从excel文件中读取数据,在调用以下方法时,我必须传递工作表编号:
public ArrayList<String> getAllData(int sheetNumber)
{
list=new ArrayList<String>();
sheet = workbook.getSheetAt(sheetNumber);
for(int i=1;i<=sheet.getLastRowNum();i++)
{
for(int j=0;j<sheet.getRow(i).getLastCellNum();j++)
{
System.out.println(sheet.getRow(i).getCell(j).getStringCellValue());
list.add(sheet.getRow(i).getCell(j).getStringCellValue());
}
}
return list;
}
I'm facing trouble in how I use this data in my calling function. 我在调用函数中如何使用此数据时遇到麻烦。 Somehow I'm able to mange at my level like:
我能够以某种方式管理:
@Test
public void searchRcontacts() throws IOException, InterruptedException
{
LoginAnalyser.checkLogin();
if(!(driver.getCurrentUrl().equals(PropertyFileReader.getProperty("dashboardURL"))))
{
driver.get(PropertyFileReader.getProperty("dashboardURL"));
CommonMethods.waitUntilLoaderGetInvisible(driver);
}
//Calling the method from ExcelReader class
Iterator<String> itr=excel.getAllData(7).iterator();
while(itr.hasNext())
{
contacts.enterSearchText(itr.next());
TakeScreenshot.passedScreenShot("Search_");
LogWriter.logger.info("Search Text enterd");
contacts.clickSearchButton();
CommonMethods.waitUntilLoaderGetInvisible(driver);
LogWriter.logger.info("Search button clicked");
TakeScreenshot.passedScreenShot("Search_Result_For");
assertEquals(contacts.getSearchResult(),itr.next());
LogWriter.logger.info("Result : "+contacts.getSearchResult());
}
}
But it doesn't seem like an efficient way. 但这似乎不是一种有效的方法。 Can someone suggest a better way to do this?
有人可以建议一种更好的方法吗?
Consider using BDD methodology such as Cucumber or JBehave. 考虑使用BDD方法,例如Cucumber或JBehave。 In your example, a story could be created:
在您的示例中,可以创建一个故事:
Scenario: Positive tests
Given I am on the search page
When I enter <testdata>
Then the record is found
Examples:
|testdata |
|narrendra |
|9422320101|
|jec |
Scenario: Negative tests
Given I am on the search page
When I enter <testdata>
Then the record is not found
Examples:
|testdata|
|Alex$ |
|Mac100 |
You could also, in the case of JBehave, place the example data in a separate file, and use: 对于JBehave,您还可以将示例数据放在单独的文件中,并使用:
Examples:
.\tables\storyPosTestData.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.