title: How to close all the windows before the next test in a test suite?
body: <pre><code>[7] pry(#&lt;RSpec::Core::ExampleGroup::Nested_1&gt;)&gt; page.execute_script "window.close()"
  Selenium::WebDriver::Error::NoSuchWindowError: Script execution failed. Script: window.close();
   The window could not be found
  
  [8] pry(#&lt;RSpec::Core::ExampleGroup::Nested_1&gt;)&gt; page.driver.browser.window_handles
  =&gt; ["f1-2"]
  </code></pre>
  
  <p>I had a browser open with two tabs, the above command does close one but the last tab never closes. It is open but when I try to run <code>page.execute_script "window.close()"</code> it gives the above error.</p>
  
  <pre><code>page.driver.browser.window_handles.each do |handle|
    page.driver.browser.switch_to.window(handle)
    page.execute_script "window.close()"
  end
  </code></pre>
  
  <p>The above code  was working for me sometime back but doesnt work anymore. It gives the same error.</p>
  
  <p>UPDATE:</p>
  
  <p>When I use,</p>
  
  <pre><code>page.driver.browser.window_handles.each do |handle| 
     page.driver.browser.switch_to.window(handle) 
     page.driver.browser.close 
  end
  </code></pre>
  
  <p>it gives the following error <code>Selenium::WebDriver::Error::UnknownError: 'auto_id'</code> does not refer to an open tab</p>