Saturday, 16 August 2014

TestNG Multi-Browser and Parallel Test Run

I ll give simple example about TestNG and parallel running

1- Create Java Project
2- Add TestNG library
3- Write your test class and annotations
4- Configure your TestNG.xml file


My simple test class below :
 package browserTestNG;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.firefox.FirefoxDriver;  
 import org.openqa.selenium.ie.InternetExplorerDriver;  
 import org.testng.annotations.AfterClass;  
 import org.testng.annotations.BeforeClass;  
 import org.testng.annotations.Parameters;  
 import org.testng.annotations.Test;  
 public class MultiBrowser {  
   public WebDriver driver;  
    @Parameters("browser")  
    @BeforeClass  
    // Passing Browser parameter from TestNG xml  
    public void beforeTest(String browser) {  
    // If the browser is Firefox, then do this  
    if(browser.equalsIgnoreCase("firefox")) {  
      driver = new FirefoxDriver();  
    // If browser is IE, then do this     
    }else if (browser.equalsIgnoreCase("ie")) {  
      // Here I am setting up the path for my IEDriver  
      System.setProperty("webdriver.ie.driver", "C://webdrivers/iedriver_64/IEDriverServer.exe");  
      driver = new InternetExplorerDriver();  
    }  
    // Doesn't the browser type, lauch the Website  
    driver.get("http://www.google.com.tr");  
    }  
    // Once Before method is completed, Test method will start  
    @Test public void login() throws InterruptedException {  
     }   
    @AfterClass public void afterTest() {  
       driver.quit();  
     }  
 }  

My testng.xml configuration file below :


















If you run this code you will see both Firefox and Internet Explorer parallel running