Assert.assertEquals TestNG With Selenium WebDriver Example

There are many assertions available inward Selenium WebDriver software testing tool amongst TestNG framework and nosotros volition expression at all of thus i yesteryear one. Assertions are of import too real useful inward whatever software automation tools to assert something during your seek execution. If you lot know, Selenium IDE software testing tool has many built inward assertion commands too if you lot are selenium IDE user thus you lot tin sack persuasion laid upward of selenium IDE assertion command examples on THIS LINK.

Difference betwixt Assertion too verification
Verification too assertion is piddling unlike inward software testing thus don't endure confused. Verification volition merely verify but assertion volition origin verify too if number is non every bit per expectation thus it volition halt execution of that specific seek method. Today allow nosotros expression at assertEquals assertion inward selenium webdriver.

Assert.assertEquals(actual, expected) assertion
This assertion is useful to compare expected too actual values inward selenium webdriver. If both values tally thus its fine too volition maintain execution. But if fails thus forthwith it volition score that specific seek method every bit neglect too move out from that seek method.

You tin sack role unlike types of values inward actual too expected like boolean, byte[], char, double, float, int, etc.. but business office is same for all. Let nosotros expression at uncomplicated instance to empathise it better.

Steps :
  • First of all, practice iii classes (BaseClassOne.java too ClassTwo.java) every bit pull inward THIS POST if you lot don't bring created.
  • Now re-create glue bellow given lines inward your ClassTwo.java file.
Assertion too Verification Example Of Selenium WebDriver With TestNg

package TestNGOnePack;  import org.openqa.selenium.By; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test;  world course of teaching ClassTwo extends TestNGOnePack.BaseClassOne{     String Actualtext;  @BeforeClass  world void load_url(){   driver.navigate().to(" ");  }   //Method Example For Assertion  @Test   world void assertion_method_1() {   Actualtext = driver.findElement(By.xpath("//h2/span")).getText();   Assert.assertEquals(Actualtext, "Tuesday, 28 Jan 2014");   System.out.print("\n assertion_method_1() -> Part executed");  }   //Method Example For Assertion  @Test  world void assertion_method_2() {     Assert.assertEquals(Actualtext, "Tuesday, 29 Jan 2014");   System.out.print("\n assertion_method_2() -> Part executed");  }    //Method Example For Verification  @Test  world void verification_method() {      String fourth dimension = driver.findElement(By.xpath("//div[@id='timeLeft']")).getText();      if (time == "Tuesday, 28 Jan 2014")   {    System.out.print("\nText Match");   }   else   {    System.out.print("\nText does Match");   }  } }

testng.xml instance to run unmarried class
To Run inward a higher house instance using testng.xml file, you lot volition bring to configure it every bit bellow.

<suite name="Suite One" configfailurepolicy="continue">   <test name="Test One">   <classes>    <class name="TestNGOnePack.ClassTwo" />         </classes>  </test> </suite>

If you lot run inward a higher house example, assertion_method_1() volition display overstep inward number but assertion_method_2() volition display neglect because hither expected too actual values volition non tally amongst each other.


If you lot volition expression inward console, Only "assertion_method_1() -> Part executed" volition endure printed over there. "assertion_method_2() -> Part executed" volition endure non in that place because execution of electrical current method was skipped later assertion failure. Last verification_method() is merely uncomplicated verification method which verifies text too impress message based on result.

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