任何人都知道此代码有什么问题。 即使我有错误的凭据,它也会通过我的测试。 我在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();
}
答案 0 :(得分:0)
您不对valueFound进行任何检查或断言。我不知道你用它来测试它,但是你可以做类似于
的事情assertTrue(valueFound);
或
if(valueFound) {
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();
} else {
//dont login
}