0

I have executed the below code to perform load test

 @Test(invocationCount = 5, threadPoolSize = 1)
 public void GmailLogin() throws InterruptedException {

 System.setProperty("webdriver.chrome.driver", "D:\\CIPL0564\\D 
Drive\\Software\\chromedriver_win32\\chromedriver.exe");
 driver = new ChromeDriver();
 driver.manage().window().maximize();
driver.get("https://tst-oec-ebooking.azurewebsites.net/");
driver.manage().timeouts().implicitlyWait(6000, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id=\"Email\"]")).sendKeys("mad@dayrep.com");
driver.manage().timeouts().implicitlyWait(6000, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id=\"Password\"]")).sendKeys("Pass@123");
driver.findElement(By.xpath("//*[@id=\"login_submit\"]")).click();
Thread.sleep(1500);
driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS);
driver.quit();

}

It executed 5 times with no errors but one after other.I need to execute this at a time by opening multiple windows. I have tried by giving threadPoolSize = 5,but i got error as session not created.

Bhuvana
  • 75
  • 6

1 Answers1

1

TestNG runner would create just one test class instance for all test methods run. This logic also occurs when running in parallel. It seems like your WebDriver object is defined globally, so in each invocation when you call "driver = new ChromeDriver()" it overrides the other.

My advice for you is to use ThreadLocal object to define your WebDriver sessions. In that way, each WebDriver object in given thread acts as independent data set. See this link http://seleniumautomationhelper.blogspot.com/2014/02/initializing-webdriver-object-as-thread.html for more detailed explanation about this subject.

AutomatedOwl
  • 1,039
  • 1
  • 8
  • 14
  • Thanks for the response. I got clear view on the concept you have given. But i didn't get how to implement that in my code. Can you please mention how can i implement it – Bhuvana Jun 27 '18 at 10:18
  • You need to create a separate class, such as DriverFactory which described in the attached link. You can even copy-pase the code, with some adjustments this implementation should solve your case. – AutomatedOwl Jun 27 '18 at 10:38
  • There is another issue for me..Using the above code the application is running 5 times with same login.I want to run it with 5 logins at a time in multiple browsers. – Bhuvana Jun 28 '18 at 06:27
  • What's the problem with multiple browser? You mean like, firefox, chrome, IE etc? – AutomatedOwl Jun 28 '18 at 08:50
  • Yes i want to run it in Firefox,Chrome and IE – Bhuvana Jun 28 '18 at 09:50
  • Use TestNG parameters https://www.tutorialspoint.com/testng/testng_parameterized_test.htm and give your test methods the values of desired browsers like void seleniumTest("CHROME", "FIREFOX", "IE") then create WebDriver instance accordingly. – AutomatedOwl Jun 28 '18 at 09:53