Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » Selenium » Solved Programs » Assert in Selenium Automation

Example of various Assert in Selenium Automation


package com.selenium.test;

import org.testng.Assert;
import org.testng.annotations.Test;

public class Assertion1 {

@Test
public void test1() {

	Assert.assertEquals(12, 12);
	System.out.println("TestCase Completed- test1"); 
	// this will be displayed only if above step is passed
}

@Test
public void test2() {

	Assert.assertEquals(12, 13, "Dropdown value doesn't match");
	// last statement in quote will display only if it fails.
	
	System.out.println("TestCase Completed- test2");
	// this will be displayed only if above step is passed
}

@Test
public void test3() {

	Assert.assertEquals("Hello", "Hello", "Words doesn't match.");
	// last statement in quote will display only if it fails.
	
	System.out.println("TestCase Completed- test3"); 
	// this will be displayed only if above step is passed
}

@Test
public void test4() {

	String mystr = "Asish";
	Assert.assertTrue(mystr.contains("Aravind"), "names not matching"); 
	// last statement in quote will display only if it fails.
	
	System.out.println("TestCase Completed- test4"); 
	// this will be displayed only if above step is passed
}

@Test
public void test5() {

	String mystr = "Aravind";
	Assert.assertTrue(mystr.contains("Aravind"), "names not matching"); 
	// last statement in quote will display only if it fails.
	
	System.out.println("TestCase Completed- test4"); 
	// this will be displayed only if above step is passed
}

}