Automated tests 如何使用数据驱动方法从下拉列表中选择2个或多个值-这正在起作用

Automated tests 如何使用数据驱动方法从下拉列表中选择2个或多个值-这正在起作用,automated-tests,testng,testng-dataprovider,testng-eclipse,testng-annotation-test,Automated Tests,Testng,Testng Dataprovider,Testng Eclipse,Testng Annotation Test,这是我的代码: Excel util: public static Object [][] getTestData(String sheetName) { try { FileInputStream ip = new FileInputStream(TESTDATA_SHEET_PATH); try { book = WorkbookFactory.create(ip); }

这是我的代码:

Excel util:

public static Object [][] getTestData(String sheetName) 
{
    try 
    {
        FileInputStream ip = new FileInputStream(TESTDATA_SHEET_PATH);

        try 
        {
            book = WorkbookFactory.create(ip);
        } 
        catch (InvalidFormatException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        sheet = book.getSheet(sheetName);
            
        Object data[][] = new Object[sheet.getLastRowNum()][sheet.getRow(0).getLastCellNum()];

        for (int i = 0; i < sheet.getLastRowNum(); i++)
        {
            for (int k = 0; k < sheet.getRow(0).getLastCellNum(); k++)
            {
                // if(data[i][k]!=null)
                data[i][k] = sheet.getRow(i+1).getCell(k).toString();
            }
        }

        return data;
    }
    catch (FileNotFoundException e) 
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.println("Not able to fetch the values from the Excel");
    }

    return null;
}
    
测试页方法:

@DataProvider
public Object[][] dealpipeline()
{
        Object data[][] = ExcelUtil.getTestData(AppConstants.Deal_Pipeline_Sheet_Name);
        return data;
}
    
@Test(priority=10,dataProvider="dealpipeline")
public void getdealspipelineinfo(String selectfields,String savepipelineas)
{
    dealspage.pipeline(selectfields, savepipelineas);
}
页面:有一个下拉列表,我们可以从下拉列表中一次选择两个值

!![在此处输入图像描述][1]

屏幕截图显示了下拉列表

  [1]: https://i.stack.imgur.com/VuP03.png
Excel文件的值选择字段阶段,委员会


当我运行此测试时,它不会选择Excel中的值,也不会显示任何错误。有人能告诉我需要做什么吗?

您可以使用下面的方法来选择下拉列表中的值

public void pipeline(String fieldvalue,String savepipe){
    String[] str = fieldvalue.split(",");
    for(int i=0; i<str.length; i++) {
        //performed the required operations as per requirement by accessing the value using str[i]
    }
}
public void管道(String fieldvalue,String savepipe){
字符串[]str=fieldvalue.split(“,”);

对于(int i=0;iCross检查您是否能够从excel中读取数据,并且所有数据都显示在那里。因此,我们可以检查其他区域。如果在excel中输入了一个值,它将读取该值,但是如果输入了两个值,其中的值用逗号分隔,则它不会在下拉列表中显示该值。在这种情况下,我可以做什么Est您的意思是说excel工作表中的数据可以是例如
user0
user0,user1
。如果是这种情况,则问题在于
elementutils的
pipeline
函数。selectvaluefromdropdown(selectfieldsvalueselection,fieldvalue)
line。这一行代码是问题所在,对解决方案有任何建议检查更新后的答案,现在可以使用了。注意,一次只能从下拉列表中选择两个值。注释不用于扩展讨论;此对话已被取消。
public void pipeline(String fieldvalue,String savepipe){
    String[] str = fieldvalue.split(",");
    for(int i=0; i<str.length; i++) {
        //performed the required operations as per requirement by accessing the value using str[i]
    }
}
public void multiselectdropdown(By locator,String value) { 
    String[] valueTemp = value.split(",");
    for(int i=0;i<valueTemp.length;i++) { 
        List<WebElement> dropdownoptions = driver.findElements(locator); 
        for(int j=0; j<dropdownoptions.size(); j++) {
            String text = dropdownoptions.get(j).getText();
            try { 
                if(!text.isEmpty()) { 
                    if(text.equalsIgnoreCase(valueTemp[i])) { 
                        dropdownoptions.get(j).click(); 
                        break; 
                    } 
                } 
            }catch (Exception e) { }
        }
    }
}