I am using selenium webdriver with Java jdbc. Below are my queries.
First: I am trying to login to the application with username and password from database (Using SQL Query). I am getting the username and password, but password is in encrypted format. So how to decrypt the password? and use it for login?.
Second: Suppose, if I want to login with all the username and password from the database then how to write the code or query.
Below is the code sample:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.Statement;
public class Test123 {
WebDriver driver;
String url ="";
@BeforeTest
public void setUp() throws Exception{
driver = new FirefoxDriver();
url = "localhost:12345/login.do";
driver.get(url);
}
@Test
public void CreateDB() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException{
String url1 ="jdbc:mysql://123.0.0.1:12345/actitime";
String dbClass = "com.mysql.jdbc.Driver";
Class.forName(dbClass).newInstance();
Connection con = DriverManager.getConnection(url1,"test", "test1");
Statement stmt = (Statement) con.createStatement();
ResultSet result = (ResultSet) stmt.executeQuery("SELECT * FROM at_user where username='s'");
if(result.next())
{
String id = result.getString(2);
String info = result.getString(4);
driver.getCurrentUrl();
WebElement a = driver.findElement(By.id("username"));
a.sendKeys(id);
WebElement b = driver.findElement(By.xpath(".//*[@id='loginFormContainer']/tbody/tr[1]/td/table/tbody/tr[2]/td/input"));
b.sendKeys(info);
WebElement btnclick = driver.findElement(By.xpath(".//*[@id='loginButton']/div"));
btnclick.click();
System.out.print("Passed");
}
}
@AfterTest
public void tearDown(){
driver.close();
}
}
Username and Password are
s (Username)
03c7c0ace395d80182db07ae2c30f034 (Password)