When you lot are working alongside selenium webdriver, you lot must live on aware virtually dissimilar form of assertions which are available. If you lot accept a plenty cognition virtually testng assertions, You tin practice real effective assay cases for your assay scenarios. assertEquals, assertNotEquals and assertTrue assertions are already explained inward my previous posts. Now permit nosotros attempt to understand assertFalse assertion for selenium webdriver.
Assert.assertFalse(condition) Assertion
It volition banking firm lucifer boolean value returned past times status in addition to volition transcend if returned value is "False". If returned value is transcend in addition to then this assertion volition neglect in addition to skip execution from electrical current assay method. Syntax for assertFalse assertion is equally bellow.
Assert.assertFalse(condition);
In sort, assertFalse in addition to assertTrue assertions are reverse to each other. When you lot wants to assert "True" value - you lot tin purpose assertTrue assertion. And when you lot wants to assert fake value - you lot tin purpose assertFalse assertion inward your selenium webdriver test.
Let nosotros attempt to purpose assertFalse assertion alongside unproblematic example. Supposing nosotros accept ii checkboxs on page 1 from them is checked in addition to approximately other 1 is non checked. Let nosotros apply assertFalse assertion on both of these banking firm lucifer boxes for its checked status.
Replace bellow given illustration methods alongside illustration of THIS PAGE. in addition to run it alongside testng.xml equally described on that post.
WebElement chk1, chk2; @BeforeClass populace void load_url(){ driver.get(" "); chk1 = driver.findElement(By.xpath("//input[@name='option1']")); chk2 = driver.findElement(By.xpath("//input[@name='option2']")); } //Assertion Method - volition Fail @Test populace void assertfalse1() { System.out.print("\n"+chk1.isSelected()); Assert.assertFalse(chk1.isSelected()); } //Assertion Method - volition Pass @Test populace void assertfalse2() { System.out.print("\n"+chk1.isSelected()); Assert.assertFalse(chk2.isSelected()); }
In this case, assertfalse1() method volition neglect because it is already checked so chk1.isSelected() volition provide truthful value. assertfalse2() method volition transcend because 2d checkbox is non checked therefore it volition provide fake value. Execution outcome volition looks similar bellow.