Selenium with Junit-Part 1

JUnit is a Unit Testing framework in Java. Combination with Selenium helps in building a framework for your tests.
Below is an example of Selenium Test + JUnit  with the usage of  frequently used annotations.

@Before Class- Usage of  this annotation makes a method call,  Before the Class (Java) starts execution.
Ex: Launching Application under Test.

@After Class- Usage of  this annotation makes a method call, After the Class (Java) completes execution.
Ex: Closing the Application under Test.

@BeforeMethod - Usage of  this annotation makes a method call , Before every Method  in the Class starts execution.

@AfterMethod - Usage of  this annotation makes a method call, After every Method in the Class completes execution.

@Test - Usage of  this annotation represents the Test to be executed .

@BeforeTest - Usage of  this annotation makes a method call, Before every Test in the Class .

@AfterTest- Usage of  this annotation makes a method call, After every Test in the Class.

@Ignore - Usage of this annotation ignores a method to be called during execution in the Class.


package junit;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

public class Test1 {

@BeforeClass

public static void Launchsite()
{
System.out.println("launching aut");
}

@Before

public void Login()
{
System.out.println("logging to the aut");
}

@ Test

public void getuserdetails()
{
System.out.println("get user details");

}

        @Ignore
@Test
public void Getaccountdetails()
{
System.out.println("Account details");
}


@After

public void Logoff()
{
System.out.println("logging out of application");
}

@AfterClass

public static void Closeapp()
{
System.out.println("closing the appl");
}

}

Comments

Popular posts from this blog

Cypress Cheat Sheet

Selenium WebDriver-Working with Listbox and Multi-Select Listbox

Selenium WebDriver -Handling JavaScript alerts