Assertions are real useful to banking enterprise correspond your expected upshot in addition to skip execution if assertion fails on operate time. If yous are selenium IDE user, yous tin read all these selenium IDE ASSERTION COMMANDS examples posts to purpose them inwards your show cases for your spider web application. Before describing about assertNull assertion of testng, I recommend yous all to READ OTHER WEBDRIVER ASSERTION METHOD examples for your reference.
assertNull(object) WebDriver Assertion
assertNull(object) assertion volition banking enterprise correspond in addition to verify that object is null. It volition drib dead if object institute null. If object institute non nil in addition to therefore it volition supply fault message similar "java.lang.AssertionError: expected [null] but institute [true]". Whenever your assertion fails, it volition score that specific show method equally neglect inwards TestNG result.
Let me introduce hither i elementary representative of assertNull assertion. We accept ii text boxes. 1st text box is enabled in addition to 2d is disabled. Now permit me purpose assertNull assertion inwards my show script to assert that textbox1 is enabled in addition to textbox2 is disabled. Here nosotros purpose textbox's disabled attribute for this assertion.
Copy in addition to supersede bellow given show methods amongst representative given on THIS PAGE in addition to and therefore operate it amongst 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 Pass @Test populace void null1() { System.out.print("\n"+txt1.getAttribute("disabled")); Assert.assertNull(txt1.getAttribute("disabled")); } //Example Assertion Method - volition Fail @Test populace void null2() { System.out.print("\n"+txt2.getAttribute("disabled")); Assert.assertNull(txt2.getAttribute("disabled")); }
In inwards a higher house given example, txt1.getAttribute("disabled") object volition supply "null" because at that spot is non whatever disabled attribute amongst 1st textbox. So that assertion volition pass. And method null1() volition drib dead too. txt2.getAttribute("disabled") object volition supply "true" because disabled attribute is available amongst textbox2. So inwards this representative that assertion in addition to method null2() volition neglect equally shown inwards bellow given image.
http://www.software-testing-tutorials-automation.com/