casper.test.begin('Test foo', 1, function suite(test) {
casper.start("http://www.foo.com", function() {
casper.waitForResource("bar", function(resource) {
casper.echo(resource.url);
});
});
casper.run(function() {
test.done();
});
});
casper.echo
returns www.foo.com
resource (the one in casper.start
), not the one with "bar".
How can I get the resource i've waited for with waitForResource
?
You actually waited for the
"bar"
resource. The problem is thatresource
inside thethen
callback function ofwaitForResource
is actually the page resource of the laststart
oropen
(thenOpen
) call. It may also be the current page resource for single page applications.If you want to wait for the resource and do something based on it, you would have to jump through some hoops:
If you don't need to do something for the current flow, you can always do the resource handling in the event handler: