Selenium 2 WebDriver Advanced
  • Preface
  • 1. API Testing Using Selenium WebDriver
    • 1.1 Code Snippet for API testing
    • 1.2 SoapUI
      • 1.2.1 Add selenium jars to soapUI
      • 1.2.2 Run selenium tests
      • 1.2.3 Data Driven Testing using SoapUI
  • 2. Advanced Profiles for Browsers
    • 2.1 Profile for Firefox Browser
    • 2.2 Profile for Chrome Browser
    • 2.3 Profile for IE Browser
    • 2.4 Profile for Safari Browser
    • 2.5 Profile for Opera Browser
  • 3. TestNG
    • 3.1 Sample TestNG class
    • 3.2 Parallel execution
    • 3.3 Execution of tests from batch file
  • 4. ExtentReports
    • 4.1 Basics
    • 4.2 Sample Extent Reports
  • 5. Advanced tricks
    • 5.1 Keystroke handling
    • 5.2 Screenshot capture
    • 5.3 Get HTML Source of WebElement
Powered by GitBook
On this page

Was this helpful?

  1. 3. TestNG

3.1 Sample TestNG class

Create a New Class Named SimpleTestNGClassExample in Eclipse. and copy paste the below code to the class. Run the Script by right Clicking anywhere in the code editor and click "Run As" > TestNG Test. Please note the option "Run As > TestNG" won't appear if you don't have testNG plugins. Follow this tutorial to install testng plugins.

package com.selenium;

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

public class SimpleTestNGClassExample {

    @BeforeTest
    public void initialization() {
        System.out.println("This method will be executed once before the"
                + "testMethod gets called..");
        System.out.println("All the statements like browser setup, "
                + "data-variable Initilization etc. should be done here..");
    }

    @Test
    public void testMethod() {
        System.out.println("This method will be called after the setup method"
                + "is called..");
        System.out.println("All the statements related to test execution"
                + "Should appear here..");
    }

    @AfterTest
    public void cleanup() {
        System.out
                .println("This method will be called after all previous methods"
                        + "are executed..");
        System.out.println("All the statements related to clean up activity"
                + "or closure activity should be listed here..");
    }

}

Testng works by looking for Annotation in the code, name @BeforeTest, @Test, @AfterTest and so on. The code in these annotations is run sequentially.

Previous3. TestNGNext3.2 Parallel execution

Last updated 5 years ago

Was this helpful?