0

Find below my code

TestBase.java
protected WebDriver driver;
@BeforeMethod   
public void setUpDriver() {
System.setProperty("webdriver.chrome.driver", getConfigProp.getChromeDriverPath());
            driver = new ChromeDriver();
            }           
            
@AfterMethod
    public void quitDriver() {
        driver.close();
        driver.quit();
    }

MyTests.java extends TestBase.java
@Test
Test1 (){
driver.doSomething()
}
@Test
Test2 (){
driver.doSomething()
}

Error:
org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?

I understand it is because of driver.quit(). So I used only driver. close() in AfterMethod. Still failed. I am not using static as well. What is the Solution.

Vijay
  • 33
  • 5
  • @AfterMethod should only be called after at the rate Test has executed, can you show me entire console output with error ? – cruisepandey Aug 05 '21 at 10:31
  • @cruisepandey AfterMethod is executing afer Test only. But by the time next test coming to Aftermethod. driver.quit is performed by test1. So it might be throwing error. I tried driver.close() only even then the same error. org.openqa.selenium.NoSuchWindowException: no such window: target window already closed from unknown error: web view not found (Session info: chrome=92.0.4515.131) Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' – Vijay Aug 05 '21 at 10:38
  • okay, can you share the entire two classes as well ? – cruisepandey Aug 05 '21 at 10:41
  • mailed to your email id. Please check. - Thanks – Vijay Aug 05 '21 at 10:53
  • @cruisepandey Please let me know if you got chance to take a look ? – Vijay Aug 06 '21 at 09:46

1 Answers1

0

I got it working using Threadlocal driver. Thanks

Vijay
  • 33
  • 5