-> assertNotNull(object) assertion will check and verify that object is NOT NULL.
-> It will pass if object returns any value. That means without Null. and continue the execution. it will mark that specific test method as fail in TestNG result.
-> It will fail if object returns NULL. and continue the execution in method.
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.assertNOTNull(txt1.getAttribute("disabled"));
}
//Example Assertion Method - will Fail
@Test
public void null2() {
System.out.print("\n"+txt2.getAttribute("disabled"));
Assert.assertNOTNull(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 fail, because its not have the disabled attribute. So its return Null.
-> null2() will get pass, because its have the disabled attribute. So its return sone value. not return Null
No comments:
Post a Comment