Here is the code for the connection to a mysql Database using Microsoft SQL Server JDBC driver.
public void DBtest() throws Exception
{
// Load Microsoft SQL Server JDBC driver.
Class.forName(“com.mysql.jdbc.Driver”);
// Prepare connection url.
String url = “jdbc:mysql://localhost/TEST_DB”;
// Get connection to DB.
Connection con = DriverManager.getConnection(url, “root”, “admin”);
// Create statement object which would be used in writing DDL and DML
// SQL statement.
Statement stmt = con.createStatement();
// Send SQL SELECT statements to the database via the
Statement.executeQuery
// method which returns the requested information as rows of data in a
// ResultSet object.
ResultSet result = stmt.executeQuery(“select email from user”);
if (result.next()){
// Fetch value of “email_address” from “result” object.
String emailaddress = result.getString(“email”);
// Use the fetched value to login to application.
selenium.open(“/”);
selenium.windowMaximize();
selenium.type(“login_email”, emailaddress);
}
}
I use Selenium scripts to do regression testing and I have all the test data in excel. This helps me manage the test data.
When doing regression testing you should have a standard data to test your application. If you are getting the data from the database to run the regression suite and if something fails you are not sure if its because of the test data from the database or because of the changes to the application.
I have seen a lot of people who encounter issue when they are dealing with the windows popup when they have to either upload a file or image.
In this solution I am giving you the page source and the the selenium code. The selenium code is in Visual Studio 2010 C sharp.
There are times when you would like to get the browser details when running the selenium scripts. Here is the selenium script that you can use to to get browser details.
String a = selenium.GetEval("navigator.appCodeName");
Console.WriteLine(a);
String b = selenium.GetEval("navigator.appName");
Console.WriteLine(b);
String c = selenium.GetEval("navigator.appVersion");
Console.WriteLine(c);
String d = selenium.GetEval("navigator.cookieEnabled");
Console.WriteLine(d);
String e = selenium.GetEval("navigator.platform");
Console.WriteLine(e);
String f = selenium.GetEval("navigator.userAgent");
Console.WriteLine(f);
Here is an example that shows you how you can connect to the database and how to execute the SQL queries in the selenium C# scripts.
In this example I am connecting the SQL server by passing the server name, username password and the database name. I then execute the SQL command “select Employee_no from employee where deptno =100″
You can use selenium.IsVisible when your xpath has display: none.
Here is an example where I am testing to see if “//span[@id='ctl00_content']” is not visible on the page.
if (selenium.IsVisible("//span[@id='ctl00_content']"))
{
Console.WriteLine("Fail");
}
else
{
Console.WriteLine("Pass");
}
Here is the xpath on the page