title: How to perfectly isolate and clear environments between each test?
body: <p>I'm trying to connect to SoundCloud using CasperJS. What is interesting is once you signed in and rerun the login feature later, the previous login is still active. Before going any further, here is the code:</p>
  
  <pre><code>casper.thenOpen('https://soundcloud.com/', function() {
    casper.click('.header__login');
  
    popup = /soundcloud\.com\/connect/;
  
    casper.waitForPopup(popup, function() {
      casper.withPopup(popup, function() {
        selectors = {
          '#username': username,
          '#password': password
        };
  
        casper.fillSelectors('form.log-in', selectors, false);
  
        casper.click('#authorize');
      });
    });
  });
  </code></pre>
  
  <p>If you run this code at least twice, you should see the following error appears:</p>
  
  <pre><code>CasperError: Cannot dispatch mousedown event on nonexistent selector: .header__login
  </code></pre>
  
  <p>If you analyse the logs you will see that the second time, you were redirected to <a href="https://soundcloud.com/stream" rel="nofollow">https://soundcloud.com/stream</a> meaning that you were already logged in.</p>
  
  <p>I did some research to clear environments between each test but it seems that the following lines don't solve the problem.</p>
  
  <pre><code>phantom.clearCookies()
  casper.clear()
  localStorage.clear()
  sessionStorage.clear()
  </code></pre>
  
  <p>Technically, I'm really interested about understanding what is happening here. Maybe SoundCloud built a system to also store some variables server-side. In this case, I would have to log out before login. But my question is how can I perfectly isolate and clear everything between each test? Does someone know how to make the environment unsigned between each test?</p>