turkmen
turkmen

Reputation: 1

chrome browser doesn't closes after finishing test

@BeforeMethod
public void setup () 
{
    System.setProperty("webdriver.chrome.driver", "src\\test\\resources\\chromedriver.exe");
    driver = new ChromeDriver(); // Opens Chrome browser
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
    //driver.manage().window().maximize();
}

@AfterMethod
public void tearDown() throws Exception 
{
    Thread.sleep(5*1000); 
    driver.quit();
}

@Test
public void browserCommandsTests() 
{
    try {
        driver.get("http://www.costco.com");
        Thread.sleep(3 * 1000);
        driver.navigate().to("http://www.facebook.com");
        Thread.sleep(3 * 1000);
        driver.navigate().back();
        Thread.sleep(3 * 1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

}

When i'm testing this code after opening the urls it doesn't closes the testing browser. it opens only 1 link and closes browser when i'm getting only 1 url. but as soon as i try to get 2nd url it opens 2nd url and after it doesn't closes the browser under test.

Upvotes: 0

Views: 122

Answers (2)

suhit patel
suhit patel

Reputation: 1

@AfterMethod
public void tearDown() throws Exception 
{

    driver.quit();
}

Upvotes: 0

Xwris Stoixeia
Xwris Stoixeia

Reputation: 1861

It is your tag @AfterMethod change it to AfterClass (also you can try close instead of quit):

@AfterClass
public void tearDown() throws Exception 
{    
   driver.close();
}

Also, friendly advice, using the thread.sleep will cause you more grief than joy. The alternative is to use driver.findElement() in a try/catch and depending on the result (true/false) direct your flow from there.

Best of luck!

Upvotes: 1

Related Questions