Is there a reason why .then() would cause a session to drop / (re-)load a page without the active session?
In the example below, you can see how the session is established with a login, then a search is performed and the result page is loaded. The session survives this navigation, but when separating tests on the now displayed page with .then(), the DOM no longer corresponds to what the logged in user would see. I fail to see why.
casper.start("http://example.dev", function() {
this.test.assertExists('form[name="login"]', 'login form is shown'); // PASS
this.fill('form[name="login"]', {
user: "username",
password: "Password1"
}, true);
});
casper.then(function() {
this.test.assertExists('body[data-userid="42"]', 'User is logged in'); // PASS
this.sendKeys("input#search", "12345");
this.click("button#submit_search"); // form submit causes redirect
});
casper.then(function() {
this.test.assertExists('body.page_id_12345', 'search for "12345" loads page?id=12345'); // PASS
this.test.assertExists('body[data-userid="42"]', 'User is logged in'); // PASS
});
// PROBLEM BELOW:
casper.then(function() {
this.test.assertExists('body[data-userid="42"]', 'User is logged in'); // FAIL
});
casper.run();
Using CasperJS 1.1.0-beta4 on OS X with PhantomJS