简体   繁体   English

有没有有效的方法来检索和使用Selenium中的测试数据

[英]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.

相关问题 使用 Selenium 获取数据的有效方法 - Efficient way to get data using Selenium 如何以有效的方式从 firebase 数据库中检索数据 - How to retrieve data from firebase database in a efficient way 从URL提取数据以用于硒测试 - Extract data from a URL to use in a selenium test 当我使用Selenium Java测试脚本从角度模型检索数据但运行时,我得到:没有这样的元素:无法找到元素:错误 - When I use to selenium java test script retrieve data from angular model but run time I get : no such element: Unable to locate element: errors 复制数据的有效方法 - Efficient way to replicate data 高效的数据显示方式 - Efficient way to display data 我可以使用gradle来获取测试数据的依赖性吗? - Can I use gradle to retrieve test data dependancies? 在不循环所有记录的情况下从数据库检索特定数据的最有效方法是什么? - What is the most efficient way to retrieve specific data from DB without doing loop for all records? 遍历vCenter清单和检索属性的有效方法 - Efficient way to traverse vcenter inventory and retrieve properties 高效的java数据结构来删除和检索信息? - Efficient java data structure to delete and retrieve information?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM