Update currentResponse on Navigation
Previously, when clicking on a link in a page or submitting a form, Casper.page would be updated to reflect the newly loaded page, but Casper.currentResponse would not. This caused the response passed to 'then' callbacks to only reflect the initial page load. This patch resolves that issue so that Casper's page and currentResponse are consistent and subsequent 'then' call backs receive the response of the most recent main page load.
Showing
2 changed files
with
56 additions
and
0 deletions
... | @@ -2267,6 +2267,10 @@ function createPage(casper) { | ... | @@ -2267,6 +2267,10 @@ function createPage(casper) { |
2267 | url, type, willNavigate, isMainFrame), "debug"); | 2267 | url, type, willNavigate, isMainFrame), "debug"); |
2268 | if (isMainFrame && casper.requestUrl !== url) { | 2268 | if (isMainFrame && casper.requestUrl !== url) { |
2269 | casper.navigationRequested = true; | 2269 | casper.navigationRequested = true; |
2270 | |||
2271 | if(willNavigate) { | ||
2272 | casper.requestUrl = url; | ||
2273 | } | ||
2270 | } | 2274 | } |
2271 | casper.emit('navigation.requested', url, type, willNavigate, isMainFrame); | 2275 | casper.emit('navigation.requested', url, type, willNavigate, isMainFrame); |
2272 | }; | 2276 | }; | ... | ... |
tests/suites/casper/navigation.js
0 → 100644
1 | |||
2 | |||
3 | var server = require('webserver').create(); | ||
4 | var service = server.listen(8090, function(request, response) { | ||
5 | response.statusCode = 200; | ||
6 | response.setHeader('Content-type', 'text/html'); | ||
7 | response.write('<a href="/link">a link</a>'); | ||
8 | response.write('<form action="/form" method="POST"><input type="submit" /></form>'); | ||
9 | response.close(); | ||
10 | }); | ||
11 | |||
12 | |||
13 | casper.test.begin('Link Navigation updates response', function(test) { | ||
14 | casper.start('http://localhost:8090', function(response) { | ||
15 | casper.click('a'); | ||
16 | casper.then(function(response) { | ||
17 | test.assertUrlMatch( | ||
18 | /\/link$/, | ||
19 | 'URL matches anchor href' | ||
20 | ); | ||
21 | test.assertEquals( | ||
22 | response.url, | ||
23 | casper.page.url, | ||
24 | 'response is consisitent with the internal page' | ||
25 | ); | ||
26 | |||
27 | }); | ||
28 | }).run(function() { | ||
29 | test.done(); | ||
30 | }); | ||
31 | }); | ||
32 | |||
33 | casper.test.begin('Form Submittal updates the response', function(test) { | ||
34 | casper.start('http://localhost:8090', function(response) { | ||
35 | casper.fill('form', {}, true); | ||
36 | casper.then(function(response) { | ||
37 | test.assertUrlMatch( | ||
38 | /\/form$/, | ||
39 | 'URL matches form action' | ||
40 | ); | ||
41 | test.assertEquals( | ||
42 | response.url, | ||
43 | casper.page.url, | ||
44 | 'response is consisitent with the internal page' | ||
45 | ); | ||
46 | }); | ||
47 | }).run(function() { | ||
48 | test.done(); | ||
49 | server.close(); | ||
50 | }); | ||
51 | }); | ||
52 |
-
Please register or sign in to post a comment