-> assertNull(object) assertion will check and verify that object is NULL.
-> It will pass if object returns Null. and continue the execution
-> It will fail if object returns any value. then it will return error message like "java.lang.AssertionError: expected [null] but found [true]". Whenever your assertion fails, it will mark that specific test method as fail in TestNG result.
Example :
Let us take example like we have two text box. one is Enabled in application. Second is disabled in application.
WebElement txt1, txt2;
@BeforeClass
public void load_url(){
driver.get("google.com");
txt1 = driver.findElement(By.xpath("//input[@id='text1']"));
txt2 = driver.findElement(By.xpath("//input[@id='text2']"));
}
//Example Of Assertion Method - will Pass
@Test
public void null1() {
System.out.print("\n"+txt1.getAttribute("disabled"));
Assert.assertNull(txt1.getAttribute("disabled"));
}
//Example Assertion Method - will Fail
@Test
public void null2() {
System.out.print("\n"+txt2.getAttribute("disabled"));
Assert.assertNull(txt2.getAttribute("disabled"));
}
From the above example
First Text box -> Enabled="True". Its dont have Disabled attribute. So its returns NULL.
Second Text box -> Disabled="True". Its dont have Disabled attribute. So its returns value.
So o/p will be
-> null1() will get pass, because its not have the disabled attribute. So its return Null.
-> null2() will get fails, because its have the disabled attribute. So its return sone value. not return Null
No comments:
Post a Comment