當我嘗試運行連接到SQL數據庫的簡單Selenium測試時遇到問題。測試不會運行,它似乎在編譯時失敗,但不會提供有關遇到錯誤的位置的任何信息。Selenium SQL數據庫連接
我已經調查了這個http://automationtricks.blogspot.com/2010/05/how-to-pass-parameters-to-junit-or.html和Google羣組,但無法弄清楚。
這裏的代碼,希望有人能指出我在正確的方向。謝謝!
package com.XXX.Tests;
import java.sql.*;
import java.sql.Connection;
import org.junit.Test;
import org.testng.annotations.BeforeClass;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.SeleniumServer;
public class SeleniumandDB extends SeleneseTestBase {
@BeforeClass
public void setUp()throws Exception {
SeleniumServer seleniumServer=null;
try {
seleniumServer = new SeleniumServer();
seleniumServer.start();
} catch (Exception e) {
e.printStackTrace();
}
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://wwww-test/");
selenium.start();
}
@Test public void testUntitled2() throws Exception {
String userID = null;
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
selenium.open("/");
selenium.windowFocus();
selenium.windowMaximize();
Class.forName("net.sourceforge.jtds.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:jtds:sqlserver://XXXX:1433/XXX","XX","XXXX");
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT TOP 1 UserID FROM webuser ORDER BY 1 DESC");
while(rs.next()){
userID = rs.getString("UserID");
conn.close();
System.out.println(userID);
selenium.type("txtUserID", userID);
selenium.type("txtPassword", "password");
selenium.click("btnLogin2");
selenium.waitForPageToLoad("30000");
selenium.stop();
}
}
}
輝煌。我實際上在另一個軟件包中重寫了腳本,並且它工作正常。我仍然感到困惑,因爲這個爲什麼不起作用。我沒有注意到我正在導入兩個容器。謝謝! – BPK