Monday 1 December 2014

Hard Assertion - Assert.assertNotEquals(actual, expected, message) assertion in Selenium Webdriver



-> It's function is opposite to assertEquals() assertion.

-> Means if both sides values will not match then this assertion will pass else it will fail.

-> Here you can write your own message for failure condition



Example :

package TestNG_Package;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.testng.Assert;

public class TestNG_Test1 {

WebDriver driver1=new FirefoxDriver();

@BeforeMethod
public void OpenBrowser(){
driver1.get("http://google.com");
driver1.manage().window().maximize();
}

@AfterMethod
public void CloseBrowser(){
driver1.quit();
}


@Test
public void Assertion_method1() {
String title = driver1.getTitle();
Assert.assertNotEquals(title,"Home Page","Assertion_method1 has been Executed");
System.out.println("title"+title);
}


}



From above Example,

-> Assertion_Method will get fail and execution goes to next method if title is equal to "Home Page".Then The remaining part in method wont be executed.

-> Assertion_Method will get Pass and execution goes to next method if title is NOT equal to "Home Page".Then The remaining part in method will be executed.

No comments:

Post a Comment