How to valid a login page using Java and Selenium WebDriver? -


in database have username = user@javachap.com , password = javachap

if run code below, passes test although username , password not exist in database.

@test public void testlogin() {   string username="abc";   string password="123";   boolean valuefound=false; // check db try {   pstmt=conn.preparecall("select * user usr_email=? , usd_password=?");   pstmt.setstring(1,username);   pstmt.setstring(2,password);   rs=pstmt.executequery();   valuefound = rs.next(); } catch(exception e) {   // report error } 

public class loginpagetest extends integrationtest {  private htmlunitdriver driver;  @before public void setup() throws malformedurlexception, unknownhostexception{     driver = new htmlunitdriver(true);     driver.get(system.getproperty("login.url")); }  @test public void testauthenticationfailurewhenprovidingbadcredentials(){     driver.findelement(by.id("username")).sendkeys("fakeuser");     driver.findelement(by.id("password")).sendkeys("fakepassword");          driver.findelement(by.id("login")).click();      asserttrue(driver.getcurrenturl().endswith("failed")); }  @test public void testauthenticationsuccesswhenprovidingcorrectcredentials(){     driver.findelement(by.id("username")).sendkeys("validuser");     driver.findelement(by.id("password")).sendkeys("validpassword");     driver.findelement(by.id("login")).click();      asserttrue(driver.getcurrenturl().endswith("/<name_of_webapp>/")); }  } 

that's how example.

edit: noticed comments. anyway code shows how test actual login page selenium.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

netbeans - Remove indent guide lines -

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -