TestNG Assertion assertNotNull With WebDriver Example

As you lot know, at that spot are many assertions inward TestNG in addition to you lot volition uncovering nigh of them on assertNull assertion. assertNotNull assertion works reverse to assertNull assertion agency it volition assert non nix condition.

TestNG Assertion assertNotNull(object) WebDriver Assertion
assertNotNull assertion is designed to banking concern fit in addition to verify that values returned past times object is non null. Means it volition endure drib dead if returned value is non null. Else it volition fail.

Best instance to experiment assertNotNull assertion is assertion of enabled in addition to disabled text fields. Let me laissez passer you lot uncomplicated instance where nosotros volition assert "disabled" attribute of text box to verify is it disabled or non using assertNotNull assertion.

Copy glue bellow given code inward instance given on THIS PAGE in addition to and thence run it using testng.xml file.

        WebElement txt1, txt2;  @BeforeClass  populace void load_url(){   driver.get(" ");   txt1 = driver.findElement(By.xpath("//input[@id='text1']"));   txt2 = driver.findElement(By.xpath("//input[@id='text2']"));    }    //Example Of Assertion Method - volition Fail  @Test  populace void notnull1() {   System.out.print("\n"+txt1.getAttribute("disabled"));   Assert.assertNotNull(txt1.getAttribute("disabled"));  }    //Example Of Assertion Method - volition Pass  @Test  populace void notnull2() {   System.out.print("\n"+txt2.getAttribute("disabled"));   Assert.assertNotNull(txt2.getAttribute("disabled"));  }

In higher upward example, assertNotNull assertion of notnull1() method volition neglect because expected was non nix but textbox text1 is non disabled thence returned null. assertNotNull assertion of notnull2() volition drib dead because expected was non nix in addition to textbox text2 is disabled thence it has furnish truthful value agency non null.


Sameway, You tin dismiss run assertNotNull assertion to assert checkbox is checked or not, to assert textbox is visible or hidden, etc..
More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM

http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post