How to perfectly isolate and clear environments between each test?

久未见 提交于 2019-12-04 08:18:54

To clear server-side session cache, calling: phantom.clearCookies(); did the trick for me. This cleared my session between test files. Example here:

casper.test.begin("Test", {
  test: function(test) {
    casper.start(
      "http://example.com",
      function() {
        ... //Some testing here
      }
    );
    casper.run(function() {
      test.done();
    });
  }, 
  tearDown: function(test) {
    phantom.clearCookies();
  }
});

If you're still having issues, check the way you are executing your tests.

Where did you call casper.clear() ?

I think you have to call it immediately after you have opened a page like:

casper.start('http://www.google.fr/', function() {
    this.clear(); // javascript execution in this page has been stopped
    //rest of code
});

From the doc: Clears the current page execution environment context. Useful to avoid having previously loaded DOM contents being still active.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!