Added settings to thenOpen()
Showing
2 changed files
with
68 additions
and
4 deletions
... | @@ -1245,10 +1245,14 @@ Casper.prototype.thenEvaluate = function thenEvaluate(fn, context) { | ... | @@ -1245,10 +1245,14 @@ Casper.prototype.thenEvaluate = function thenEvaluate(fn, context) { |
1245 | * @return Casper | 1245 | * @return Casper |
1246 | * @see Casper#open | 1246 | * @see Casper#open |
1247 | */ | 1247 | */ |
1248 | Casper.prototype.thenOpen = function thenOpen(location, then) { | 1248 | Casper.prototype.thenOpen = function thenOpen(location, settings, then) { |
1249 | "use strict"; | 1249 | "use strict"; |
1250 | if (!(settings && !utils.isFunction(settings))) { | ||
1251 | then = settings; | ||
1252 | settings = null; | ||
1253 | } | ||
1250 | this.then(this.createStep(function _step() { | 1254 | this.then(this.createStep(function _step() { |
1251 | this.open(location); | 1255 | this.open(location, settings); |
1252 | }, { | 1256 | }, { |
1253 | skipLog: true | 1257 | skipLog: true |
1254 | })); | 1258 | })); | ... | ... |
... | @@ -22,7 +22,31 @@ var t = casper.test, current = 0, tests = [ | ... | @@ -22,7 +22,31 @@ var t = casper.test, current = 0, tests = [ |
22 | username: 'bob', | 22 | username: 'bob', |
23 | password: 'sinclar' | 23 | password: 'sinclar' |
24 | }, "Casper.open() used the expected HTTP auth settings"); | 24 | }, "Casper.open() used the expected HTTP auth settings"); |
25 | } | 25 | }, |
26 | function(settings) { | ||
27 | t.assertEquals(settings, { | ||
28 | method: "get" | ||
29 | }, "Casper.thenOpen() used the expected GET settings"); | ||
30 | }, | ||
31 | function(settings) { | ||
32 | t.assertEquals(settings, { | ||
33 | method: "post", | ||
34 | data: "plop=42&chuck=norris" | ||
35 | }, "Casper.thenOpen() used the expected POST settings"); | ||
36 | }, | ||
37 | function(settings) { | ||
38 | t.assertEquals(settings, { | ||
39 | method: "put", | ||
40 | data: "plop=42&chuck=norris" | ||
41 | }, "Casper.thenOpen() used the expected PUT settings"); | ||
42 | }, | ||
43 | function(settings) { | ||
44 | t.assertEquals(settings, { | ||
45 | method: "get", | ||
46 | username: 'bob', | ||
47 | password: 'sinclar' | ||
48 | }, "Casper.thenOpen() used the expected HTTP auth settings"); | ||
49 | }, | ||
26 | ]; | 50 | ]; |
27 | 51 | ||
28 | casper.start(); | 52 | casper.start(); |
... | @@ -67,7 +91,43 @@ casper.open('tests/site/index.html', { | ... | @@ -67,7 +91,43 @@ casper.open('tests/site/index.html', { |
67 | t.pass("Casper.open() can open and load a location using HTTP auth"); | 91 | t.pass("Casper.open() can open and load a location using HTTP auth"); |
68 | }); | 92 | }); |
69 | 93 | ||
94 | // GET with thenOpen | ||
95 | casper.thenOpen('tests/site/index.html').then(function() { | ||
96 | t.pass("Casper.thenOpen() can open and load a location using GET"); | ||
97 | }); | ||
98 | |||
99 | // POST with thenOpen | ||
100 | casper.thenOpen('tests/site/index.html', { | ||
101 | method: 'post', | ||
102 | data: { | ||
103 | plop: 42, | ||
104 | chuck: 'norris' | ||
105 | } | ||
106 | }, function() { | ||
107 | t.pass("Casper.thenOpen() can open and load a location using POST"); | ||
108 | }); | ||
109 | |||
110 | // PUT with thenOpen | ||
111 | casper.thenOpen('tests/site/index.html', { | ||
112 | method: 'put', | ||
113 | data: { | ||
114 | plop: 42, | ||
115 | chuck: 'norris' | ||
116 | } | ||
117 | }, function() { | ||
118 | t.pass("Casper.thenOpen() can open and load a location using PUT"); | ||
119 | }); | ||
120 | |||
121 | // HTTP Auth with thenOpen | ||
122 | casper.thenOpen('tests/site/index.html', { | ||
123 | method: 'get', | ||
124 | username: 'bob', | ||
125 | password: 'sinclar' | ||
126 | }, function() { | ||
127 | t.pass("Casper.thenOpen() can open and load a location using HTTP auth"); | ||
128 | }); | ||
129 | |||
70 | casper.run(function() { | 130 | casper.run(function() { |
71 | this.removeAllListeners('open'); | 131 | this.removeAllListeners('open'); |
72 | t.done(); | 132 | t.done(); |
73 | }); | 133 | }); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment