【发布时间】:2011-06-24 02:32:15
【问题描述】:
当我尝试运行连接到 SQL 数据库的简单 Selenium 测试时遇到了问题。测试将不会运行,它似乎在编译时失败,但没有提供任何有关错误发生位置的信息。
我已经查看了这个 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();
}
}
}
【问题讨论】: