Saturday 25 June 2022

TestNG Assertions Tutorial | TestNG Assertions in Selenium | TestNG Assert Test Pass and Fail

                 In this post, we will see TestNG Assertions Tutorial | TestNG Assertions in Selenium | TestNG Assert Test Pass and Fail 


Following Statements are used in TestNG framework for assertions:

1. Assert.assertEquals(String actual, String expected)

2. Assert.assertEquals(String actual, String expected, String message)

3. Assert.assertEquals(boolean actual, boolean expected)

4. Assert.assertEquals(boolean actual, boolean expected, String message)

5. Assert.assertTrue(boolean condition)

6. Assert.assertTrue(boolean condition, String message)

7. Assert.assertFalse(boolean condition)

8. Assert.assertFalse(boolean condition, String message)


Program Code (Program1.java):

package mytest;



import org.testng.Assert;

import org.testng.annotations.Test;


public class Program1 {

@Test

public void test1()

{

//Assert.assertEquals(actual, expected);

Assert.assertEquals("parag", "parag");

}

@Test

public void test2()

{

Assert.assertEquals("parag", "comrevo", "Test to check title");

}

@Test

public void test3()

{

Assert.assertEquals(true, true);

}

@Test

public void test4()

{

Assert.assertEquals(true, false, "Test to check login credentials");

}

@Test

public void test5()

{

Assert.assertTrue(true);

}

@Test

public void test6()

{

Assert.assertTrue(false, "Test to check login credentials");

}

@Test

public void test7()

{

Assert.assertFalse(false));

}

@Test

public void test8()

{

Assert.assertFalse(true, "Test to check login credentials");

}


}


Program Code (testng.xml):

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">

<suite name="Suite">

  

  <test name="Test">

  <classes>

  <class name="mytest.Program1"></class>

  </classes>

  

  </test> 

</suite>  


Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=p_277c8Hj00

No comments:

Post a Comment