누구든지이 코드의 문제점을 알고 있습니다. 잘못된 신임장이 있어도 테스트에 합격합니다. Eclipse에서 Java 및 Selenium WebDriver를 사용하고 있습니다.잘못된 자격 증명으로 로그인 테스트가 통과합니다.
무엇이 잘못되어 있는지, Google에서 답을 찾을 수없는 것 같지 않습니다.
public class LoginTest {
String url ="jdbc:sqlserver://CODESV3;databaseName=Codes;integratedSecurity=true";
String DBdriver ="com.microsoft.sqlserver.jdbc.SQLServerDriver";
Connection conn = null;
WebDriver driver = null;
PreparedStatement pstmt=null;
ResultSet rs=null;
@BeforeTest
public void establishConn()
{
driver = new FirefoxDriver();
driver.get("https://10.10.10.50/");
// establish connection
try{
Class.forName(DBdriver).newInstance();
conn = DriverManager.getConnection(url);
}catch(Exception e){
System.out.println("Database failed to connect ");
}
}
@Test
public void testLogin()
{
String forceID="1234";
String username="ayaslem";
String password="Delpiero10+";
boolean valueFound=false;
// Check the db
try{
pstmt=conn.prepareCall("select * from Login where ForceID=? and Username=? and Password=?");
pstmt.setString(2,forceID);
pstmt.setString(3,username);
pstmt.setString(4,password);
rs=pstmt.executeQuery();
valueFound =rs.next();
}catch(Exception e){
// report some error
}
// login into app
driver.findElement(By.xpath("//*[@id='LogonModel_OrganisationName']")).sendKeys(forceID);
driver.findElement(By.xpath("//*[@id='LogonModel_UserId']")).sendKeys(username);
driver.findElement(By.xpath("//*[@id='LogonModel_Password']")).sendKeys(password);
driver.findElement(By.xpath("//*[@id='maincontent']/form/div/fieldset/div[4]/div[2]/input")).click();
}
당신은 valueFound으로 아무것도하지 않는 비슷한을 할 수 있습니까? –
valueFound로 무엇을 할 것으로 예상됩니까? false로 설정되면, valueFound = rs.next(); 값이 db와 일치하지 않으면 false를 반환하고 db가 일치하면 true –
네, 볼 수있는 것으로부터 테스트하지 않습니까? rs.next()로 설정하면됩니다. Theres는 그것의 진실한다는 것을 주장 또는 체크하지 않는다. try 블록에서 나와 valueFound 값에 관계없이 앱에 로그인하면됩니다. –