webdriver 的CSV数据驱动

2020-11-16 07:42

阅读:754

标签:des   style   blog   http   java   使用   

1.获取CSV数据内容

public static Object[][] getFromCSV(String filename) {
  
    if (!(new File(filename)).exists()){
     return null;
    }
    Object[][] content;
    CSVReader reader;
    try {
     reader = new CSVReader(new FileReader(filename));
     Vector vec = new Vector();
     String[] nextLine;
     reader.readNext(); //skip title
     while ((nextLine = reader.readNext()) != null) {   
      vec.add(nextLine);   
     }
     content = new Object[vec.size()][];
     for (int i = 0; i       content[i] = vec.get(i);
     }
     return content;
    } catch (Exception e) {
     System.out.println("Read CSV File:" + filename + "failed.");
     e.printStackTrace();  
    }
    return null;
  }

 

2.定义数据驱动

String file = "src/test/java/data/page/TaxIssueAnswerTest.csv";

  @DataProvider(name="CsvDataProvider")
  public Object[][] inputData(){
   return getFromCSV(file);
  }

 

3.使用数据驱动

@Test(dataProvider = "CsvDataProvider",description ="正常业务场景测试")
 public void answerIssue(String caseId, String description,String userName, String pwd){

//执行用例

}

 

4.图例文件路径

mamicode.com,搜素材

webdriver 的CSV数据驱动,搜素材,soscw.com

webdriver 的CSV数据驱动

标签:des   style   blog   http   java   使用   

原文地址:http://www.cnblogs.com/joewu/p/3699628.html


评论


亲,登录后才可以留言!