I'm having a lot of trouble understanding how to test a simple form that makes an AJAX request and either loads a new page or displays an error, depending on the response.
The scope of 'this' is changing after the request. Once the form is submitted 'this' refers to the XHR result of the query, not to the page, so no title found of course. My code:
casper.test.begin('Tester.assertField(): unfilled inputs', 3, function(test) {
casper.start('http://www.myste.com/roku/', function() {
this.fill('form[id="id-lookup-form"]', {
'code': 'chuck@norris.com'
}, true);
test.assertField('code', 'chuck@norris.com', 'Tester.assertField() works as expected with inputs');
});
casper.wait(5000, function() {
test.assertField(this.title, 'myste.com', 'Title correct after form input');
});
casper.run(function() {
test.done();
});
});
I can increase the wait as long as I like and it will still fail. I know it is remedial, forgive me, but I've been all over trying to find a solution. This is similar: Update whole page on Ajax request and maybe I'm out to lunch, but since the page is making an AJAX request, I don't want to have to duplicate the request-- I want to let the page make the request and then see what happens. We do a lot of AJAX requests like this, I don't want to be intercepting/rewriting/parsing them all for every page I need to test. Casperjs, how to only proceed after receiving response from an ajax call seems to also suggest this method (though perhaps function getSomethingFromMyServerViaAjax() is not sending the request, i can't tell.)
Thanks very much, this is kicking me.