Selenium Overview

Selenium automation — TestNG

TestNG is a strong software evaluation framework, an advanced version of JUnit that has been being used for quite a while before TestNG came in to existence. NG represents for ‘Next Generation’

TestNG framework supplies these attributes :

Annotations help us arrange the tests readily.

Versatile evaluation settings. 
Test instances may be gathered quicker. 
Parallelization of evaluations may be realized using TestNG
 Help for data driven screening.

Built-in reporting
Installing TestNG for Eclipse
 Measure 1 : Start Eclipse and choose ‘Install New S/W ‘

2 : Enter the URL as ‘http://beustcom/eclipse' and click ‘ Include ‘

Measure 3 : The dialogue package ‘ Include Archive ‘ starts. Input the title as ‘TestNG’ and click ‘OK’

Step 4 : Click ‘Select All’ and ‘TestNG’ might be picked as shown in the figure

Step 5 : Click ‘Next’ to continue

Measure 6 : Review the things which are picked and click ‘Next’

Measure 7 : “Accept the License Agreement” and click ‘ Complete ‘

Measure 8 : TestNG begins installing and the advancement might be revealed uses.

Measure 9 : Protection Warning appears as the cogency of the applications can not be created. Click ‘ Okay ‘

Measure 10 : The Specialist requests to re-start Eclipse for the changes to take effect. Click ‘Yes’

Annotations in TestNG
Annotations were officially added to the Java language in JDK 5 and TestNG produced the choice to use annotations to annotate evaluation courses. Following are a few of the great things about using annotations. More regarding TestNG may be located here

TestNG recognizes the systems it is concerned in by searching for annotations. Thus, process names aren’t confined to any routine or structure.

We may move additional guidelines to annotations

Annotations are strongly entered, therefore the compiler may banner any errors immediately.

Check courses no further should widen something ( including test-case, for JUnit 3)

Annotation Description
@BeforeSuite The annotated process will be operate just once prior to all the tests in this package have operate. 
@AfterSuite The annotated procedure will be operate just once following every one of the tests in this package have operate. 
@BeforeClass The annotated procedure will be operate just as soon as just before the very first check technique in the present category is invoked
@AfterClass The annotated procedure will be operate just once following all of the check practices in the present group have run
@BeforeTest The annotated process will be operate just before any test technique owned by the categories inside of the tag is operate. 
@AfterTest The annotated approach will be follow every one of the check techniques from the groups inside the label have operate. 
@BeforeGroups The listing of teams this setup procedure will operate prior to. This procedure is guaranteed to perform briefly before the first check technique that belongs to some of these organizations is invoked
@AfterGroups The listing of teams this setup procedure will follow. This system is guaranteed to run right after the last check technique that belongs to some of these organizations is invoked
@BeforeMethod The annotated approach will be operate prior to every check approach. 
@AfterMethod The annotated procedure will be pursue every check approach. 
@DataProvider Marks a process as supplying information for a check technique. The annotated method must get back an Object[ ][ ] where each Item [ ] may be given the parameter checklist of the check method. The @ Check approach that desires to obtain information from this DataProvider requirements to utilize a dataProvider title means to the title of the annotation
@Factory Marks a process as a factory that returns items which will be employed by TestNG as Evaluation courses. The system should reunite Object[ ]
@ Hearers Defines hearers on a test course. 
@Parameters Describes just how to move parameters to some @Test approach. 
@ Evaluation Marks a course or a procedure included in the evaluation.

TestNG Eclipse Arrangement

Stage 1 : Establish Eclipse and generate a ‘New Coffee Project’ as shown below

Measure 2 : Enter the job title and click ‘Next’

Stage 3 : Navigate to “Libraries” Tablature and Include the Selenium Testing Tool Handheld Remote Control Machine JAR record by hitting “ A-Dd Outside JAR’s” as shown below

Measure 4 : The additional VESSEL document is revealed here. Click ‘ A Dd Collection ‘

Measure 5 : The ‘ A Dd Catalogue ‘ discussion starts. Pick ‘TestNG’ and click ‘Next’ in the ‘ A-Dd Catalogue ‘ dialogue package.

Measure 6 : The additional ‘TestNG’ Collection is added and it really is displayed as shown below

Measure 7 : Upon making the job, the construction of the task might be as shown below

Measure 8 : Correct — click ‘src’ file and select New >” id=”st-722">>> Additional.

Step 9 : Pick ‘TestNG’ and click ‘Next’

Step 10 : Choose the ‘ Resource Folder’ title and click ‘ Okay ‘

Step 1 1 : Choose the ‘ Program title ‘, the ‘ type title ‘, and click ‘ Complete ‘

Measure 1 2 : The Program traveler and the produced category might be exhibited.

First Evaluation in TestNG
 Today let’s begin scripting utilizing TestNG. Permit us software for exactly the same instance that people used for comprehending the WebDriver. We’ll utilize the trial program, wwwcalculatornet, and perform percentage calculator

In the next evaluation, you are going to see that there’s NO primary process, as testNG may drive the application performance circulation. After initializing the motorist, it’s going to run the ‘@BeforeTest’ procedure accompanied by ‘@ Evaluation ‘ and after that ‘@AfterTest’. Please be aware that there may be any amount of ‘@ Evaluation ‘ annotation in a course but ‘@BeforeTest’ along with ‘@AfterTest’ may appear just once

package TestNG;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class TestNGClass
 WebDriver driver = new FirefoxDriver();
 public void launchapp()
 // Puts an Implicit wait, Will wait for 10 seconds before throwing exception
 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
 // Launch website
 public void calculatepercent()
 // Click on Math Calculators
 // Click on Percent Calculators
 // Enter value 10 in the first number of the percent Calculator
 // Enter value 50 in the second number of the percent Calculator
 // Click Calculate Button
 // Get the Result Text based on its xpath
 String result = driver.findElement(By.xpath(“.//*[@id=’content’]/p[2]/span/font/b”)).getText();
 // Print a Log In message to the screen
 System.out.println(“ The Result is “ + result);
 System.out.println(“ The Result is Pass”);
 System.out.println(“ The Result is Fail”);
 public void terminatetest()
To run, right click the created XML and choose “ Operate As” >” id=”st-1016">>> “TestNG Package “>”” id=”st-1019">”


Outcome Investigation
The output signal is chucked to the games console and it would seem as shown below. The games console result even offers an performance outline.For more information on Selenium Webdriver tutorials visit here.