Commit dfa2c402 dfa2c402e643c07f2ef6fe7366fca40b3de34d54 by Nicolas Perriault

fixes #110 - google pagination sample doesn't wait for page change

1 parent c584fb09
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
4 # 4 #
5 # (all arguments will be used as the query) 5 # (all arguments will be used as the query)
6 6
7 casper = require('casper').create() 7 casper = require('casper').create(verbose: true, logLevel: "debug")
8 currentPage = 1 8 currentPage = 1
9 9
10 if casper.cli.args.length == 0 10 if casper.cli.args.length == 0
...@@ -13,7 +13,7 @@ if casper.cli.args.length == 0 ...@@ -13,7 +13,7 @@ if casper.cli.args.length == 0
13 13
14 processPage = -> 14 processPage = ->
15 casper.echo "capturing page #{currentPage}" 15 casper.echo "capturing page #{currentPage}"
16 casper.capture "google-results-p#{ currentPage }.png" 16 casper.capture "google-results-p#{currentPage}.png"
17 17
18 # don't go too far down the rabbit hole 18 # don't go too far down the rabbit hole
19 return if currentPage >= 5 19 return if currentPage >= 5
...@@ -21,15 +21,17 @@ processPage = -> ...@@ -21,15 +21,17 @@ processPage = ->
21 if casper.exists "#pnnext" 21 if casper.exists "#pnnext"
22 currentPage++ 22 currentPage++
23 casper.echo "requesting next page: #{currentPage}" 23 casper.echo "requesting next page: #{currentPage}"
24 casper.thenClick("#pnnext").then(processPage) 24 #casper.thenClick("#pnnext").then(processPage)
25 url = @getCurrentUrl()
26 casper.thenClick("#pnnext").then ->
27 check = -> url != @getCurrentUrl()
28 @waitFor check, processPage
25 else 29 else
26 casper.echo "that's all, folks." 30 casper.echo "that's all, folks."
27 31
28 casper.start 'http://google.fr/', -> 32 casper.start 'http://google.fr/', ->
29 @fill 'form[action="/search"]', q: casper.cli.args.join(' '), true 33 @fill 'form[action="/search"]', q: casper.cli.args.join(' '), true
30 34
31 casper.then -> 35 casper.then processPage
32 # google's being all ajaxy, wait for results to load...
33 @waitForSelector 'table#nav', => processPage(casper)
34 36
35 casper.run() 37 casper.run()
......