TestNG Annotations in Selenium

TestNG :


TestNG is an automation framework mostly used in Selenium automation scripts for Web applications.It is very important to understand the annotations while working with TestNG for Selenium WebDriver. Testng providing suitable annotations to prepare Test scripts in Selenium WebDriver where you can pass test data from different files such as Excel,XLS files and You can run the scripts before tarting the class Method etc.

TestNG Annotations in Selenium
TestNG Annotations in Selenium



TestNG has below annotations those are

  1. BeforeSuite 
  2. AfterSuite 
  3. BeforeTest 
  4. AfterTest
  5. BeforeGroups
  6. AfterGroups 
  7. BeforeClass
  8. AfterClass
  9. BeforeMethod 
  10. AfterMethod 
You can read TestNG Tutorials from Here

Explanation:


@BeforeSuite: This annotation method will be run before all tests in this Test suite have to run.
@After Suite: This annotated method will be run after all tests in this Test suite have to run.
@BeforeTest: This annotated method will run before any test method which is belongs to the classes inside the test tag.
@After Test: This annotated method will be run after all the test method which is belongs to the classes inside the test tag have to run.
@BeforeClass: This annotated method will run before the first test method in the current class is invoked.
@After Class: This annotated method will be run after all the test methods in the current class have run.
@BeforeMethod : This annotated method will be run before each test method.
@AfterMethod: This annotated method will be run after each test method.

Example:


Before Test Selenium Web Driver will initiate and run the Tests in classes.

package com.fs.msn.automate;
import java.io.File;
import java.io.IOException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeTest;

public class SeleniumWebDriv {
 public static WebDriver driver=null;  
 public String baseUrl;
 
   @BeforeTest public void BeforeTests () throws IOException{ 
   
  //Import Chrome extension from Local machine   
 File ChromeDriver = new File("D:\\Rajesh\\2014\\Java_Applications\\Zip Files\\chromedriver.exe");     
 //Set Chrome driver property    
 System.setProperty("webdriver.chrome.driver", ChromeDriver.getAbsolutePath());
 
    driver = new ChromeDriver();    
 driver.manage().window().maximize();    
 baseUrl="http://www.wikishown.com";   
 driver.get(baseUrl);      
 }
}

Please provide your valuable comments on this post and provide any suggestions in order to get users experience ,so that i can improve the site content to understand easily.Thank you for reading my blog.

Also Read


Complete Selenium Tutorials
Verify Element is Enable
Selenium Xpath Tutorial
Selenium DataDriven Framework

6 comments:

  1. Please read more

    https://swtestingtutorials.blogspot.in/2016/04/testng-annotations-in-selenium.html

    ReplyDelete
  2. Thanks for such awesome blog. Your article is very easy to understand, informative and provide complete overview about software testing. Please consider including rss feed in your website, so I get your recent post on my site. Best software testing training in Chennai.

    ReplyDelete

  3. Amazing, thanks a lot my friend, I was also siting like a your banner image when I was thrown into Selenium.When I started learning then I understood it has got really cool stuff.
    I can vouch webdriver has proved the best feature in Selenium framework.
    Thanks a lot for taking a time to share a wonderful article.

    Best Selenium Training Institute in Chennai |
    Selenium Training Center in Chennai

    ReplyDelete
  4. Useful information,don't stop sharing and Please keep updating us..... Thanks

    ReplyDelete
  5. Amazing, thanks a lot my friend, I was also siting like a your banner image when I was thrown into Selenium.When I started learning then I understood it has got really cool stuff.
    I can vouch webdriver has proved the best feature in
    Selenium framework.
    Thanks a lot for taking a time to share a wonderful article.

    ReplyDelete