java - Continue to next tests IF assertEquals fails -
i new in java / selenium , trying automate tests. trying move next lines of code if test fails , print message if test pass. now, forcing test fail in order move next operations. here piece of code:
public class selfreportingtest { private webdriver driver; @before public void setup() { driver = new firefoxdriver(); } @test public void testloginfunctionality() string validusername = "testusername"; string validpassword = "testpassword"; string validurl = "https://testsite.com/users/profile/show" // url when user logged driver.get("http://testsite.com"); webelement loginlink =driver.findelement(by.id("loginlink")); loginlink.click(); webelement usernamefield = driver.findelement(by.id("loginusername")); webelement passwordfield = driver.findelement(by.id("loginpassword")); usernamefield.sendkeys(validusername); passwordfield.sendkeys(validpassword); webelement loginbutton =driver.findelement(by.xpath("/html/body/div[2]/div/div/div/div[1]/form/div/div[2]/input")); loginbutton.click(); if(validurl != driver.getcurrenturl()) { driver.get("http://test.jira.com"); } else { system.out.println("login successfull");
i struggling @ if condition - taking first condition, no matter if username/password correct/incorrect. it's not mandatory compare urls, can webelements, not sure right way? tried assertequals fails when actual , expected not equal, not fit needs. can guys suggest something, work in case? in advance.
try assert.true(driver.gettitle()=="page name");
or find element , check isdisplayed
.
ex: driver.findelement(by.id("")).isdisplayed;
Comments
Post a Comment