Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Selenium Web驱动程序将SQL查询结果写入excel+;测试NG_Excel_Selenium Webdriver_Apache Poi - Fatal编程技术网

如何使用Selenium Web驱动程序将SQL查询结果写入excel+;测试NG

如何使用Selenium Web驱动程序将SQL查询结果写入excel+;测试NG,excel,selenium-webdriver,apache-poi,Excel,Selenium Webdriver,Apache Poi,如何使用SeleniumWebDriver+TestNG将SQL查询结果写入excel 示例: @Test(priority=5) public void VerifyDataBase() { try { String query = "SELECT * FROM [xxx].[dbo].[xxx_FEINProductionCompany] where ProductionCompanyName like'%xxx%'"; System.out

如何使用SeleniumWebDriver+TestNG将SQL查询结果写入excel

示例:

@Test(priority=5) 
    public void VerifyDataBase() {


 try {
        String query = "SELECT *  FROM [xxx].[dbo].[xxx_FEINProductionCompany] where ProductionCompanyName like'%xxx%'";
        System.out.println(query);
        statement = connection.createStatement();
        rs = statement.executeQuery(query);

        while (rs.next()) {

            int FEIN_ID = rs.getInt("ACA_FEINProductionCompany_ID");
            int FEIN_No = rs.getInt("FEIN");
            String ProductionCompanyName = rs.getString("ProductionCompanyName");
            String ProductionCompanyShortName = rs.getString("ProductionCompanyShortName");
            String  ModifiedDate = rs.getString("ModifiedDate");
            String Username = rs.getString("Username");
            String AddressLine1 = rs.getString("AddressLine1");
            String AddressLine2 = rs.getString("AddressLine2");
            String City = rs.getString("City");
            String State = rs.getString("State");
            int Zip = rs.getInt("Zip");
            String PhoneNumber = rs.getString("PhoneNumber");
            String ContactName = rs.getString("ContactName");
            String ContactPhone = rs.getString("ContactPhone");
            System.out.println("\nProductionCompanyName is: " + ProductionCompanyName);
            System.out.println("\nFEIN is: " + FEIN_No); 
            System.out.println("\nAddressLine2 is: " + AddressLine2);
            System.out.println("\nUsername is: " + Username);
            TestUtil.assertEquals(Username, "xxxx","FEINScreen_Username"); 
            TestUtil.assertEquals(AddressLine2, "2500 xx","FEINScreen_AddressLine2"); 
            System.out.println("\nQuery Result Set is: "+ ProductionCompanyName+"\t"+FEIN_No+"\t"+AddressLine2+"\t"+Username);
            System.out.println("\t");
        }

    }   
    catch (SQLException ex) {
        ex.printStackTrace();
    } 

}您需要使用java库/依赖项,如ApachePOI。 Selenium或TestNG没有任何与Excel交互的功能

使用下面的链接代码,并将sql查询数据作为输入参数传递给其中的

参考:


我的每个测试用例至少有10个SQL查询,每个查询将至少有30列/参数的数据。有没有最简单的方法代替将一个参数一个参数传递到excel工作表中。我必须进行数据验证测试。当然,我正在添加断言,以验证通过结果集返回的特定列数据上的数据,但我想将整个结果集保存到excel中,以备日后查看。首先,这是一个与此问题不同的问题。。如果解决方案有助于您,请接受同样的解决方案。答案的解决方案是创建一个excel工作表,添加Testcase编号和Testcase名称,现在使用loop以编程方式读取excel,并添加条件如果您的Testcase需要,则读取您在另一列vise或row wise中添加的查询,您可以根据需要执行读或写操作,您只需要创建一个具有逻辑的循环