Selenium WebDriver assertTrue assertion event amongst TestNG

Previously nosotros convey learnt ii assertions of selenium webdriver software testing tool. You tin ship away sentiment practical illustration pages of selenium webdriver assertionsassertEquals together with assertNotEquals before learning assertTrue(condition) assertion. There is also ane some other related assertion is assertFalse(condition) assertion but nosotros volition look about it inwards my adjacent post.

assertTrue(condition) Assertion
assertTrue assertion is to a greater extent than frequently than non used for Boolean status true. It volition overstep if status returns "true". If it volition supply fake together with then it volition neglect together with skip software attempt out execution from that specific method. Syntax for assertTrue assertion is every bit bellow.

Assert.assertTrue(condition);

Supposing y'all convey ane cheque box on page of software spider web application. You wants to cheque its status similar it is checked or not. And if it is non checked together with then y'all wants to skip software attempt out execution from that method together with wants to neglect that method inwards testng report. This matter tin ship away last done real easily using assertTrue assertion. Let nosotros await at practical illustration of assertTrue assertion.

Replace bellow given variables together with iii methods amongst illustration given on my THIS POST together with and then run it using testng.xml file.

        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 pass  @Test   populace void asserttrue1() {     System.out.print("\n"+chk1.isSelected());   Assert.assertTrue(chk1.isSelected());     System.out.print("\n asserttrue1 - > Executed - agency assertion is pass");  }   //Assertion Method - volition fail  @Test   populace void asserttrue2() {     System.out.print("\n"+chk2.isSelected());   Assert.assertTrue(chk2.isSelected());   System.out.print("\n asserttrue2 - > Executed - agency assertion is pass");  }

When y'all run to a higher house software attempt out illustration inwards eclipse together with acquire result, asserttrue1() method volition display overstep together with method asserttrue2() volition display neglect every bit shown inwards bellow given image.


asserttrue1() volition overstep because 1st cheque box is checked on page so chk1.isSelected() volition supply true.
asserttrue2() volition neglect because sec cheque box is non checked on page so chk2.isSelected() volition supply false. In assertion failure case, code written subsequently Assert.assertTrue(chk2.isSelected()); volition last non executed. Run to a higher house illustration inwards your eclipse together with verify the results together with then travail it for your ain project.

This way, Assert.assertTrue(condition) is helps role to assert Boolean status true.

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