Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DatabaseTest;
- import java.sql.*;
- import org.openqa.selenium.firefox.FirefoxDriver;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.By;
- public class SeleniumDatabaseTest {
- public static void main(String[] args) {
- //Test Data
- String user_name = "test1";
- String user_passwd = "test1";
- //Selenium
- WebDriver driver = new FirefoxDriver();
- driver.get("http://127.0.0.1:81/projautomatyzacja");
- //driver.findElement(By.xpath("html/body/form/input[1]")).sendKeys(user_name);
- //driver.findElement(By.xpath("html/body/form/input[2]")).sendKeys(user_passwd);
- //driver.findElement(By.xpath("html/body/form/input[3]")).click();
- //DB Connection
- Connection conn = null;
- String url = "jdbc:mysql://localhost:3306/sys";
- String username = "root";
- String password = "root";
- try{
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection(url, username, password);
- String sqlQuery = "Select * from databasetest";
- Statement statement = conn.createStatement();
- ResultSet result = statement.executeQuery(sqlQuery);
- if(!result.next()){
- System.out.println("No Data Found");
- }
- else do {
- result.next();
- String login = result.getString("user_name");
- String haslo = result.getString("user_passwd");
- driver.findElement(By.xpath("html/body/form/input[1]")).sendKeys(login);
- driver.findElement(By.xpath("html/body/form/input[2]")).sendKeys(haslo);
- driver.findElement(By.xpath("html/body/form/input[3]")).click();
- if(driver.findElement(By.className("poprawne")) != null)
- System.out.println(result.getString("user_name"));
- System.out.println("Wynik testu logowania pozytywny");
- } while (result.next());
- // System.out.println(result.getString("user_name"));
- // System.out.println(result.getString("user_passwd"));
- //Database Test
- // if(!result.getString("user_name").equals(user_name))
- // System.out.println("Wrong username fetched from DB");
- // if(!result.getString("user_passwd").equals(user_passwd))
- // System.out.println("Wrong password fetched from DB");
- }
- catch(Exception e){
- System.out.println(e);
- }
- finally{
- if(conn!=null){
- conn=null;//Close the DB Connection
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement