I'm running into an issue when I try to run a simple Selenium test that connects to a SQL database. The test will not run, it seems to fail on compiling but does not provide any information on where the error was encountered.
I've looked into this http://automationtricks.blogspot.com/2010/05/how-to-pass-parameters-to-junit-or.html and Google groups but can't figure it out.
Here's the code, hope someone can point me in the right direction. Thanks!
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();
}
}
}