title: Selenium WebDriver - Delete cookies and restart the browser during the test
body: <p>I have a test case to test is the cart items still exist after delete cookies and restart the browser</p>
  
  <ol>
  <li>Add the items to shopping cart (there will be a count to indicated number of items added)</li>
  <li><code>Delete the cookies</code> on the browser, </li>
  <li><code>Close the browser</code></li>
  <li><code>Relaunch the browser</code></li>
  <li>Check is the shopping cart count items still exists</li>
  </ol>
  
  <p>my main code are below.</p>
  
  <pre><code>// 1. Add items to shopping cart
  // code go here
  
  // 2. Clear the cookies on the browser
  driver.manage().deleteAllCookies();         
  driver.navigate().refresh();
  // 3. Close the browser
  driver.close();                             
  
  ProfilesIni firProfiles = new ProfilesIni();        
  FirefoxProfile wbdrverprofile = firProfiles.getProfile("default");  
  // 4. Relaunch the browser      
  driver = new FirefoxDriver(wbdrverprofile);                 
  driver.get("http://www.google.com");        
  
  Boolean isCartCountExists = driver.findElements(By.id(cartCount)).size()!=0;
  if(isCartCountExists == true){
      System.out.println("Test Failed.");
  }else{
      System.out.println("Test Passed.")
  }
  </code></pre>
  
  <p><code>@AfterTest</code> code</p>
  
  <pre><code>@AfterTest
      public void closeBrowser(){
  
          driver.close();
          ExistingmozillaBrowser=null;
  
      }
  </code></pre>
  
  <p>Getting error log below</p>
  
  <pre><code>[TestNG] Running:
  
  FAILED CONFIGURATION: @AfterTest closeBrowser
  org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
  Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:03:00'
  System info: host: 'C111400215M4232', ip: '192.168.0.11', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_45'
  Driver info: driver.version: RemoteWebDriver
      at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:593)
      at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:614)
      at org.openqa.selenium.remote.RemoteWebDriver.close(RemoteWebDriver.java:463)
      at testCases.SuiteBase.closeWebBrowser(SuiteBase.java:380)
      at testCases.ModuleOne.myTestCase01.closeBrowser(myTestCase01.java:387)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
      at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
      at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
      at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
      at org.testng.TestRunner.afterRun(TestRunner.java:1014)
      at org.testng.TestRunner.run(TestRunner.java:621)
      at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
      at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
      at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
      at org.testng.SuiteRunner.run(SuiteRunner.java:240)
      at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
      at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
      at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
      at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
      at org.testng.TestNG.run(TestNG.java:1057)
      at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
      at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
      at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
  Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:7056 [/127.0.0.1] failed: Connection refused: connect
      at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:140)
      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
      at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
      at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
      at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
      at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
      at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
      at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
      at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:215)
      at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
      at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:165)
      at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:362)
      at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572)
      ... 26 more
  Caused by: java.net.ConnectException: Connection refused: connect
      at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
      at java.net.PlainSocketImpl.connect(Unknown Source)
      at java.net.SocksSocketImpl.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:72)
      at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123)
      ... 40 more
  
  FAILED: myTestCase01Test("myTestCase01", "pc", "laptop", "2", "usd")
  org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
  Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:03:00'
  System info: host: 'C111400215M4232', ip: '192.168.0.11', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_45'
  Driver info: driver.version: RemoteWebDriver
      at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:593)
      at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:377)
      at org.openqa.selenium.remote.RemoteWebDriver.findElementsByXPath(RemoteWebDriver.java:453)
      at org.openqa.selenium.By$ByXPath.findElements(By.java:352)
      at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:340)
      at pageObjects.HomePage.check_noCartCount(HomePage.java:550)
      at testCases.ModuleOne.myTestCase01.myTestCase01Test(myTestCase01.java:317)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
      at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
      at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
      at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
      at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
      at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
      at org.testng.TestRunner.privateRun(TestRunner.java:767)
      at org.testng.TestRunner.run(TestRunner.java:617)
      at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
      at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
      at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
      at org.testng.SuiteRunner.run(SuiteRunner.java:240)
      at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
      at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
      at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
      at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
      at org.testng.TestNG.run(TestNG.java:1057)
      at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
      at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
      at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
  Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:7056 [/127.0.0.1] failed: Connection refused: connect
      at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:140)
      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
      at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
      at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
      at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
      at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
      at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
      at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
      at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:215)
      at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
      at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:165)
      at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:362)
      at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572)
      ... 30 more
  Caused by: java.net.ConnectException: Connection refused: connect
      at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
      at java.net.PlainSocketImpl.connect(Unknown Source)
      at java.net.SocksSocketImpl.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:72)
      at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123)
      ... 44 more
  
  
  ===============================================
      Default test
      Tests run: 1, Failures: 1, Skips: 0
      Configuration Failures: 1, Skips: 0
  ===============================================
  
  
  ===============================================
  Default suite
  Total tests run: 1, Failures: 1, Skips: 0
  Configuration Failures: 1, Skips: 0
  ===============================================
  </code></pre>
  
  <p>It seem like after close the browser, the test unable to continue after restart. Any help will be appreciate. Thanks.</p>