使用ant脚本执行时,Selenium数据库测试失败

时间:2014-10-08 15:03:10

标签: java sql selenium ant webdriver

我有一个selenium webdriver测试,它连接到数据库,执行查询并将值存储在字符串中。然后我做了那件事。

当我在Twist中执行测试时(基于Eclipse),此测试工作正常。

但是当我使用ant脚本执行测试时,它无法声明空指针异常,也看到了这个.. [twist.runner] java.lang.ClassNotFoundException:com.microsoft.sqlserver.jdbc.SQ LServerDriver 即可。

The Code Snippets:

public void verifyUserCreatedInTslUserProfileAndSubscriptionTables() throws Exception {

    String userDetails = Products.verifyUserDetailsInSubscriptionTable(); 

    verifyTrue("User details in subscription table did not match, please check manually", userDetails.contentEquals("1215401"));
}


public static String verifyUserDetailsInSubscriptionTable() throws IOException, SQLException {

    String userSubscriptionDetails = null;

    DBAccess.getConnection(ConnectionStrings.databaseConnect("authentication"), ConnectionStrings.getLoginDetailsDB("username"), ConnectionStrings.getLoginDetailsDB("password"));  

    Statement stmt = DBAccess.con.createStatement();    
    ResultSet result = stmt.executeQuery(ConnectionStrings.getSqlQuery("verifySubscription"));

    while (result.next()) { userSubscriptionDetails = result.getString("ServiceID")+result.getString("Status")+result.getString("AutoRenew"); }

    DBAccess.closeConnection();
    return userSubscriptionDetails;
}


public class DBAccess {

 public static java.sql.Connection  con = null;

 public static java.sql.Connection getConnection(String conurl, String userName, String password) {

     try {

         Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
         con = java.sql.DriverManager.getConnection(conurl,userName,password);         
         if (con != null) System.out.println("Connection Successful!");       
     }
     catch(Exception e){

           e.printStackTrace();
           System.out.println("Error Trace in getConnection() : " + e.getMessage());
     }

      return con;
  }


public static String databaseConnect(String connection) throws IOException {

    String conurl = null; 
    String url = "jdbc:sqlserver://";

    switch (connection) {                       

    case "authentication": 
        if (Configuration.getSqlServerName().contains("stage")) { conurl = url + "tslauthentication.database.ST.tslweb.local"; break; } 
        else if (!Configuration.getSqlServerName().contains("stage")) { conurl = url + Configuration.getSqlServerName(); break; }
        else break;

    case "tes_connect":
        conurl = url
        +Configuration.getSqlServerName() + ".tslwebdev.local"+":"
        +1433+";databaseName="
        +"tes_connect"+";selectMethod="
        +"cursor"+";"; break;

    }

    connection = conurl;
    return connection; 
}

Ant返回错误:

显示java.lang.NullPointerException     at test.products.NewUserSubscribes.verifyUserCreatedInTslUserProfileAndSubscriptionTables(NewUserSubscribes.java:68)     at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:471)     在java.util.concurrent.FutureTask.run(FutureTask.java:262)     在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

1 个答案:

答案 0 :(得分:1)

真的很傻。设法通过将jdbc驱动程序添加到类路径来修复它。