Thursday, 9 February 2017

SELENIUM: ThreadPoolSize:



ThreadPoolSize:


1.The size of the thread pool for this method i,e number of threads for the @Test method.The method will be invoked from multiple threads as specified by invocationCount.
2.This attribute is ignored if invocationCount is not specified.

Example:

package com.rameshsoft.rameshselenium;


import java.util.concurrent.TimeUnit; 
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class ThreadPoolSize {
         
          @BeforeMethod
          public void before()
          {
                   System.out.println("Before test running");
          }
          @AfterMethod
          public void after()
          {
                   System.out.println("After test running");
          }
         
          @Test(invocationCount=5,invocationTimeOut=300,threadPoolSize=2)
          public void execute() throws InterruptedException
          {
                   long thread_id=Thread.currentThread().getId();
                   System.out.println("Running Thread id is: "+thread_id);
                    System.setProperty("webdriver.gecko.driver", "C:\\Users\\ramesh\\Desktop\\java\\desk\\geckodriver-v0.11.1-win64\\geckodriver.exe");
                   WebDriver driver=new FirefoxDriver();
                   driver.manage().window().maximize();                   driver.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS);                  
                   driver.get("https://www.gmail.com");                                     driver.findElement(By.id("Email")).sendKeys("rameshsoft.selenium");                  
                   driver.findElement(By.id("next")).click();
                   Thread.sleep(2000);
                   driver.findElement(By.id("Passwd")).sendKeys("12345");
                   driver.findElement(By.id("signIn")).click();                  
                   driver.quit();
          }

}

OUTPUT:

Before test running
Before test running
Running Thread id is: 12
Running Thread id is: 11
After test running
Before test running
Running Thread id is: 12
After test running
Before test running
Running Thread id is: 11
After test running
Before test running
After test running
Running Thread id is: 12

No comments:

Post a Comment