Thursday, August 21, 2014




In this tutorial, I will tell you how to configure Selenium with eclipse. Before you configure Selenium with eclipse, You should be sure that you have installed TestNG plugin with eclipse. Click here to know how to install and configure TestNG with Eclipse.

Steps To Configure Selenium With Eclipse

1. First you need to download Selenium from “http://docs.seleniumhq.org/download/“  and then extract the Selenium folder.






2. Open eclipse and create project. Right click on project –> Properties –> Java Build Path –> click on “Libraries tab” –> click on “Add External JARs” button –> add all JARs files from Selenium folder.



3. Close and Re-open eclipse.

4. Right click on project –> Refresh

5. Project –> clean project.

Selenium installation with eclipse is done. Thanks for reading how to configure selenium with eclipse.





Thursday, August 14, 2014




In this tutorial, I will introduce you with TestNG annotations list. TestNG acts as a controller. TestNG controls the flow of execution of code with the help of annotations.

TestNG Annotations List


Annotations Description
@BeforeSuite The annotated method will run before all test methods run in this suite.
@AfterSuite The annotated method will run after all test methods run in this suite.
@BeforeTest The annotated method will run before any test method belonging to the classes.
@AfterTest The annotated method will run after all the test methods belonging to the classes.
@BeforeGroups The annotated method will run before the first test method that belongs to any of these groups is invoked.
@AfterGroups The annotated method will run after the last test method that belongs to any of these groups is invoked.
@BeforeClass The annotated method will run before the first test method run in the current class.
@AfterClass The annotated method will run before all the first test methods run in the current class.
@BeforeMethod The annotated method will run before each test method.
@AfterMethod The annotated method will run after each test method.
@DataProvider The annotated method provide data to the @Test methods. The annotated method returns an Object[][].
@Test The annotated method contains test cases.


To understand more about TestNG Annotations and attributes (i.e. @Test, @DataProvider,... etc) with examples then look at Data-Driven Framework tutorial.





Let's understand the TestNG Annotations list with an example


package testng;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class TestNGAnnotations {

 @BeforeSuite
 public void instantiate() {
  System.out.println("Instantiate Object");
 }

 @BeforeTest
 public void dataBaseConnection() {
  System.out.println("Database Connected");
 }

 @BeforeMethod
 public void BeforeMethod() {
  System.out.println("Run before each Test Case.");
 }

 @Test
 public void testCase1() {
  System.out.println("First Test Case Result..... ");
 }
 
 @Test
 public void testCase2() {
  System.out.println("Second Test Case Result.... ");
 }

 @AfterMethod
 public void AfterMethod() {
  System.out.println("Run after each Test Case");
 }

 @AfterTest
 public void dataBaseDisconnection() {
  System.out.println("Database Disconnected");
 }

 @AfterSuite
 public void destory() {
  System.out.println("Destory Object");
 }
}

 

How To Create testng.xml


testng.xml: Right click on Project --> TestNG --> Convert to TestNG.



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
  <test name="Test">
    <classes>
      <class name="testng.TestNGAnnotations"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->



How To Run Or Execute TestNG


Right click on testng.xml --> Run As --> TestNG Suite OR Right click on java file --> Run As --> TestNG Test


Output:

TestNG annotations list


Thanks for reading TestNG Annotations List.








In this tutorial, I will explain you TestNG installation in eclipse. TestNG comes with Eclipse plug-in that allow you to write and run TestNG tests from Eclipse in a convenient way. Before TestNG installation and configuration, you should be sure that the eclipse and java jdk 5 or higher has installed on the computer.

Once you are done with TestNG plugin installation, you need to add testng.jar in your project library. TestNG.jar comes with Selenium. So, I recommend you to configure Selenium with eclipse. Click here to know how to install Selenium WebDriver.


TestNG Installation in Eclipse

Look at the following steps for TestNG Installation in Eclipse -

Sept 1: Open eclipse, click on "Help" and then click on "Install New Software".



Step 2: Enter site URL and click on "Add " button
  • For Eclipse 3.4 and above, enter http://beust.com/eclipse.
  • For Eclipse 3.3 and below, enter http://beust.com/eclipse1.










Step 3: Enter Repository Name (For example, Enter Name as “TestNG”) and Click "OK" Button and then Click Next button











Step 4: Accept the License and then click "Finish" button
















Step 5: Wait for Installing Software











Step 6: Click Ok

















Step 7: Restart Eclipse. Click "Yes" button


 

 

 

 

How to verify that TestNG has successfully installed?


Open eclipse, click Window --> Show View --> Other






















New window will open, click on Java. You will see TestNg inside the Java folder. This shows that TestNG has successfully installed in the eclipse.






















Click here to know how to install or configure Selenium WebDriver with eclipse. Thanks for reading TestNG installation in eclipse.