casperjs 1.0.0.RC1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/CHANGELOG.md +289 -1
  2. data/CONTRIBUTING.md +93 -0
  3. data/CONTRIBUTORS.md +53 -0
  4. data/README.md +29 -1
  5. data/batchbin/casperjs.bat +5 -0
  6. data/bin/bootstrap.js +164 -114
  7. data/bin/casperjs +84 -0
  8. data/bin/usage.txt +2 -1
  9. data/casperjs.gemspec +7 -4
  10. data/modules/casper.js +661 -239
  11. data/modules/clientutils.js +240 -54
  12. data/modules/colorizer.js +2 -1
  13. data/modules/events.js +13 -1
  14. data/modules/http.js +70 -0
  15. data/modules/mouse.js +1 -2
  16. data/modules/pagestack.js +166 -0
  17. data/modules/tester.js +1013 -659
  18. data/modules/utils.js +519 -367
  19. data/modules/vendors/coffee-script.js +2 -2
  20. data/modules/xunit.js +56 -24
  21. data/package.json +2 -2
  22. data/rpm/casperjs.spec +203 -0
  23. data/rpm/mkrpm.sh +25 -0
  24. data/rubybin/casperjs +9 -4
  25. data/samples/bbcshots.coffee +11 -10
  26. data/samples/bbcshots.js +16 -15
  27. data/samples/cliplay.js +3 -0
  28. data/samples/customevents.js +3 -0
  29. data/samples/customlogging.coffee +17 -19
  30. data/samples/customlogging.js +26 -27
  31. data/samples/download.js +4 -1
  32. data/samples/dynamic.js +3 -0
  33. data/samples/each.js +3 -0
  34. data/samples/events.js +4 -2
  35. data/samples/extends.js +4 -1
  36. data/samples/googlelinks.coffee +4 -1
  37. data/samples/googlelinks.js +10 -3
  38. data/samples/googlematch.coffee +1 -1
  39. data/samples/googlematch.js +5 -2
  40. data/samples/googlepagination.js +4 -1
  41. data/samples/googletesting.js +3 -0
  42. data/samples/logcolor.js +3 -0
  43. data/samples/metaextract.js +3 -0
  44. data/samples/multirun.js +3 -0
  45. data/samples/screenshot.js +4 -1
  46. data/samples/statushandlers.js +4 -1
  47. data/samples/steptimeout.js +3 -0
  48. data/samples/timeout.js +4 -1
  49. data/samples/translate.coffee +23 -0
  50. data/samples/translate.js +30 -0
  51. data/tests/commands/mytest.js +14 -0
  52. data/tests/commands/script.js +3 -0
  53. data/tests/run.js +82 -37
  54. data/tests/sample_modules/config.json +1 -0
  55. data/tests/sample_modules/csmodule.coffee +1 -0
  56. data/tests/sample_modules/jsmodule.js +1 -0
  57. data/tests/selftest.js +57 -0
  58. data/tests/site/dummy.js +1 -0
  59. data/tests/site/field-array.html +14 -0
  60. data/tests/site/frame1.html +10 -0
  61. data/tests/site/frame2.html +11 -0
  62. data/tests/site/frame3.html +11 -0
  63. data/tests/site/frames.html +12 -0
  64. data/tests/site/global.html +6 -1
  65. data/tests/site/includes/include1.js +6 -0
  66. data/tests/site/includes/include2.js +6 -0
  67. data/tests/site/index.html +3 -0
  68. data/tests/site/popup.html +19 -0
  69. data/tests/site/resources.html +7 -8
  70. data/tests/site/urls.html +14 -0
  71. data/tests/suites/casper/agent.js +3 -1
  72. data/tests/suites/casper/alert.js +14 -0
  73. data/tests/suites/casper/auth.js +24 -0
  74. data/tests/suites/casper/capture.js +12 -12
  75. data/tests/suites/casper/click.js +11 -1
  76. data/tests/suites/casper/confirm.js +24 -16
  77. data/tests/suites/casper/debug.js +10 -0
  78. data/tests/suites/casper/elementattribute.js +3 -1
  79. data/tests/suites/casper/encode.js +6 -2
  80. data/tests/suites/casper/evaluate.js +78 -18
  81. data/tests/suites/casper/events.js +3 -1
  82. data/tests/suites/casper/exists.js +3 -1
  83. data/tests/suites/casper/fetchtext.js +3 -1
  84. data/tests/suites/casper/flow.coffee +1 -1
  85. data/tests/suites/casper/formfill.js +39 -4
  86. data/tests/suites/casper/frames.js +43 -0
  87. data/tests/suites/casper/global.js +9 -3
  88. data/tests/suites/casper/headers.js +41 -0
  89. data/tests/suites/casper/history.js +3 -1
  90. data/tests/suites/casper/hooks.js +3 -1
  91. data/tests/suites/casper/keys.js +15 -0
  92. data/tests/suites/casper/location.js +21 -0
  93. data/tests/suites/casper/logging.js +3 -1
  94. data/tests/suites/casper/mouseevents.js +3 -1
  95. data/tests/suites/casper/onerror.js +3 -1
  96. data/tests/suites/casper/open.js +63 -1
  97. data/tests/suites/casper/popup.js +86 -0
  98. data/tests/suites/casper/prompt.js +11 -15
  99. data/tests/suites/casper/request.js +36 -0
  100. data/tests/suites/casper/resources.coffee +5 -5
  101. data/tests/suites/casper/scripts.js +32 -0
  102. data/tests/suites/casper/start.js +3 -1
  103. data/tests/suites/casper/steps.js +4 -2
  104. data/tests/suites/casper/urls.js +21 -0
  105. data/tests/suites/casper/viewport.js +3 -1
  106. data/tests/suites/casper/visible.js +3 -1
  107. data/tests/suites/casper/wait.js +22 -12
  108. data/tests/suites/casper/xpath.js +3 -1
  109. data/tests/suites/cli.js +3 -1
  110. data/tests/suites/clientutils.js +57 -3
  111. data/tests/suites/coffee.coffee +1 -1
  112. data/tests/suites/fs.js +3 -1
  113. data/tests/suites/http_status.js +19 -3
  114. data/tests/suites/popup.js +33 -0
  115. data/tests/suites/require.js +31 -0
  116. data/tests/suites/tester.js +134 -29
  117. data/tests/suites/utils.js +108 -8
  118. data/tests/suites/xunit.js +37 -6
  119. metadata +49 -15
  120. data/modules/injector.js +0 -93
  121. data/tests/suites/injector.js +0 -64
@@ -1,3 +1,5 @@
1
+ /*global casper*/
2
+ /*jshint strict:false*/
1
3
  // events
2
4
 
3
5
  casper.test.comment("events");
@@ -35,4 +37,4 @@ casper.test.assertEquals(casper.foo, 42, "filter() applies the correct context")
35
37
 
36
38
  delete casper.foo;
37
39
 
38
- casper.test.done();
40
+ casper.test.done(5);
@@ -1,3 +1,5 @@
1
+ /*global casper*/
2
+ /*jshint strict:false*/
1
3
  casper.test.comment('Casper.exists()');
2
4
 
3
5
  casper.start('tests/site/index.html', function() {
@@ -5,5 +7,5 @@ casper.start('tests/site/index.html', function() {
5
7
  });
6
8
 
7
9
  casper.run(function() {
8
- this.test.done();
10
+ this.test.done(1);
9
11
  });
@@ -1,3 +1,5 @@
1
+ /*global casper*/
2
+ /*jshint strict:false*/
1
3
  casper.test.comment('Casper.fetchText()');
2
4
 
3
5
  casper.start('tests/site/index.html', function() {
@@ -5,5 +7,5 @@ casper.start('tests/site/index.html', function() {
5
7
  });
6
8
 
7
9
  casper.run(function() {
8
- this.test.done();
10
+ this.test.done(1);
9
11
  });
@@ -35,4 +35,4 @@ casper.then ->
35
35
  casper.then ->
36
36
  @test.assertEquals ++step, 13, "last step"
37
37
 
38
- casper.run(-> @test.done())
38
+ casper.run(-> @test.done(13))
@@ -1,3 +1,5 @@
1
+ /*global casper*/
2
+ /*jshint strict:false*/
1
3
  casper.start('tests/site/form.html', function() {
2
4
  this.test.comment('Casper.fill()');
3
5
  this.fill('form[action="result.html"]', {
@@ -39,6 +41,23 @@ casper.start('tests/site/form.html', function() {
39
41
  !document.querySelector('input[name="checklist[]"][value="2"]').checked &&
40
42
  document.querySelector('input[name="checklist[]"][value="3"]').checked);
41
43
  }, true, 'Casper.fill() can fill a list of checkboxes');
44
+
45
+ });
46
+
47
+ casper.then(function() {
48
+ this.test.comment('Casper.getFormValues()');
49
+ this.test.assertEquals(this.getFormValues('form'), {
50
+ "check": true,
51
+ "checklist[]": ["1", "3"],
52
+ "choice": "no",
53
+ "content": "Am watching thou",
54
+ "email": "chuck@norris.com",
55
+ "file": "C:\\fakepath\\README.md",
56
+ "password": "chuck",
57
+ "submit": "submit",
58
+ "topic": "bar"
59
+ }, 'Casper.getFormValues() retrieves filled values');
60
+ this.test.comment('submitting form');
42
61
  this.click('input[type="submit"]');
43
62
  });
44
63
 
@@ -52,18 +71,34 @@ casper.then(function() {
52
71
  this.test.assertUrlMatch(/topic=bar/, 'Casper.fill() select field was submitted');
53
72
  });
54
73
 
74
+ casper.thenOpen('tests/site/form.html', function() {
75
+ this.test.comment('Unexistent fields');
76
+ this.test.assertRaises(this.fill, ['form[action="result.html"]', {
77
+ unexistent: 42
78
+ }, true], 'Casper.fill() raises an exception when unable to fill a form');
79
+ });
80
+
55
81
  // multiple forms
56
82
  casper.thenOpen('tests/site/multiple-forms.html', function() {
57
83
  this.test.comment('Multiple forms');
58
84
  this.fill('form[name="f2"]', {
59
85
  yo: "ok"
60
86
  }, true);
87
+ }).then(function() {
88
+ this.test.assertUrlMatch(/\?f=f2&yo=ok$/, 'Casper.fill() handles multiple forms');
61
89
  });
62
90
 
63
- casper.then(function() {
64
- this.test.assertUrlMatch(/\?f=f2&yo=ok$/, 'Casper.fill() handles multiple forms');
65
- }),
91
+ // issue #267: array syntax field names
92
+ casper.thenOpen('tests/site/field-array.html', function() {
93
+ this.test.comment('Field arrays');
94
+ this.fill('form', {
95
+ 'foo[bar]': "bar",
96
+ 'foo[baz]': "baz"
97
+ }, true);
98
+ }).then(function() {
99
+ this.test.assertUrlMatch('?foo[bar]=bar&foo[baz]=baz', 'Casper.fill() handles array syntax field names');
100
+ });
66
101
 
67
102
  casper.run(function() {
68
- this.test.done();
103
+ this.test.done(19);
69
104
  });
@@ -0,0 +1,43 @@
1
+ /*global casper __utils__*/
2
+ /*jshint strict:false*/
3
+ casper.start('tests/site/frames.html');
4
+
5
+ casper.withFrame('frame1', function() {
6
+ this.test.assertTitle('CasperJS frame 1');
7
+ this.test.assertExists("#f1");
8
+ this.test.assertDoesntExist("#f2");
9
+ this.test.assertEval(function() {
10
+ return '__utils__' in window && 'getBinary' in __utils__;
11
+ }, '__utils__ object is available in child frame');
12
+ this.test.assertMatches(this.page.frameContent, /This is frame 1/);
13
+ this.test.assertMatches(this.getHTML(), /This is frame 1/);
14
+ });
15
+
16
+ casper.withFrame('frame2', function() {
17
+ this.test.assertTitle('CasperJS frame 2');
18
+ this.test.assertExists("#f2");
19
+ this.test.assertDoesntExist("#f1");
20
+ this.test.assertEval(function() {
21
+ return '__utils__' in window && 'getBinary' in __utils__;
22
+ }, '__utils__ object is available in other child frame');
23
+ this.clickLabel('frame 3');
24
+ });
25
+
26
+ casper.withFrame('frame2', function() {
27
+ this.test.assertTitle('CasperJS frame 3');
28
+ });
29
+
30
+ casper.withFrame(0, function() {
31
+ this.test.assertTitle('CasperJS frame 1');
32
+ this.test.assertExists("#f1");
33
+ this.test.assertDoesntExist("#f2");
34
+ });
35
+
36
+ casper.withFrame(1, function() {
37
+ this.test.assertTitle('CasperJS frame 3');
38
+ });
39
+
40
+ casper.run(function() {
41
+ this.test.assertTitle('CasperJS test frames');
42
+ this.test.done(16);
43
+ });
@@ -1,9 +1,15 @@
1
+ /*global casper*/
2
+ /*jshint strict:false*/
1
3
  casper.start('tests/site/global.html', function() {
2
4
  this.test.comment('Casper.getGlobal()');
3
- this.test.assertEquals(this.getGlobal('myGlobal'), 'awesome string', 'Casper.getGlobal() can retrieve a remote global variable');
4
- this.test.assertRaises(this.getGlobal, ['myUnencodableGlobal'], 'Casper.getGlobal() does not fail trying to encode an unencodable global');
5
+ this.test.assertEquals(this.getGlobal('myGlobal'), 'awesome string',
6
+ 'Casper.getGlobal() can retrieve a remote global variable');
7
+ this.test.assertEquals(this.getGlobal('myObject').foo.bar, 'baz',
8
+ 'Casper.getGlobal() can retrieves a serializable object');
9
+ this.test.assertRaises(this.getGlobal, ['myUnencodableGlobal'],
10
+ 'Casper.getGlobal() does not fail trying to encode an unserializable global');
5
11
  });
6
12
 
7
13
  casper.run(function() {
8
- this.test.done();
14
+ this.test.done(3);
9
15
  });
@@ -0,0 +1,41 @@
1
+ /*global casper*/
2
+ /*jshint strict:false*/
3
+ casper.test.comment('Casper.headers.get()');
4
+
5
+ var server = require('webserver').create();
6
+ var service = server.listen(8090, function(request, response) {
7
+ response.statusCode = 200;
8
+ response.headers = {
9
+ 'Content-Language': 'en',
10
+ 'Content-Type': 'text/html',
11
+ 'Date': new Date().toUTCString()
12
+ };
13
+ response.write("ok");
14
+ response.close();
15
+ });
16
+
17
+ function dumpHeaders() {
18
+ casper.test.comment('Dumping current response headers');
19
+
20
+ casper.currentResponse.headers.forEach(function(header) {
21
+ casper.test.comment('- ' + header.name + ': ' + header.value);
22
+ });
23
+ }
24
+
25
+ // local file:// url
26
+ casper.start('file://' + phantom.casperPath + 'tests/site/index.html', function thenLocalPage(response) {
27
+ this.test.assertEquals(response, undefined, 'No response available on local page');
28
+ });
29
+
30
+ casper.thenOpen('http://localhost:8090/', function thenLocalhost(response) {
31
+ var headers = response.headers;
32
+
33
+ this.test.assertEquals(headers.get('Content-Language'), 'en', 'Checking existing header (case sensitive)');
34
+ this.test.assertEquals(headers.get('content-language'), 'en', 'Checking existing header (case insensitive)');
35
+ this.test.assertEquals(headers.get('X-Is-Troll'), null, 'Checking unexisting header');
36
+ });
37
+
38
+ casper.run(function() {
39
+ server.close();
40
+ this.test.done(4);
41
+ });
@@ -1,3 +1,5 @@
1
+ /*global casper*/
2
+ /*jshint strict:false*/
1
3
  casper.start('tests/site/page1.html');
2
4
  casper.thenOpen('tests/site/page2.html');
3
5
  casper.thenOpen('tests/site/page3.html');
@@ -17,5 +19,5 @@ casper.then(function() {
17
19
  casper.run(function() {
18
20
  this.test.assert(this.history.length > 0, 'Casper.history contains urls');
19
21
  this.test.assertMatch(this.history[0], /tests\/site\/page1\.html$/, 'Casper.history has the correct first url');
20
- this.test.done();
22
+ this.test.done(4);
21
23
  });
@@ -1,3 +1,5 @@
1
+ /*global casper*/
2
+ /*jshint strict:false*/
1
3
  // Dear curious test reader,
2
4
  // The on* family of methods is considered deprecated since 0.6.0; please use events instead
3
5
 
@@ -37,5 +39,5 @@ casper.then(function() {
37
39
 
38
40
  casper.run(function() {
39
41
  this.options.onAlert = null;
40
- this.test.done();
42
+ this.test.done(5);
41
43
  });
@@ -0,0 +1,15 @@
1
+ /*jshint strict:false*/
2
+ /*global CasperError casper console phantom require*/
3
+ casper.start('tests/site/form.html', function() {
4
+ this.sendKeys('input[name="email"]', 'duke@nuk.em');
5
+ this.sendKeys('textarea', "Damn, I’m looking good.");
6
+ var values = this.getFormValues('form');
7
+ this.test.assertEquals(values['email'], 'duke@nuk.em',
8
+ 'Casper.sendKeys() sends keys to given input');
9
+ this.test.assertEquals(values['content'], "Damn, I’m looking good.",
10
+ 'Casper.sendKeys() sends keys to given textarea');
11
+ });
12
+
13
+ casper.run(function() {
14
+ this.test.done(2);
15
+ });
@@ -0,0 +1,21 @@
1
+ /*jshint strict:false*/
2
+ /*global CasperError casper console phantom require*/
3
+ if (phantom.version.major === 1 && phantom.version.minor < 8) {
4
+ // https://github.com/n1k0/casperjs/issues/101
5
+ casper.warn('document.location is broken under phantomjs < 1.8');
6
+ casper.test.done();
7
+ } else {
8
+ casper.start('tests/site/index.html', function() {
9
+ this.evaluate(function() {
10
+ document.location = '/tests/site/form.html';
11
+ });
12
+ });
13
+
14
+ casper.then(function() {
15
+ this.test.assertUrlMatches(/form\.html$/);
16
+ });
17
+
18
+ casper.run(function() {
19
+ this.test.done();
20
+ });
21
+ }
@@ -1,3 +1,5 @@
1
+ /*jshint strict:false*/
2
+ /*global casper __utils__*/
1
3
  casper.start('tests/site/index.html');
2
4
 
3
5
  var oldLevel = casper.options.logLevel;
@@ -34,5 +36,5 @@ casper.then(function() {
34
36
 
35
37
  casper.run(function() {
36
38
  this.test.assertEquals(this.result.log.length, 3, 'Casper.log() logged messages');
37
- this.test.done();
39
+ this.test.done(4);
38
40
  });
@@ -1,3 +1,5 @@
1
+ /*global casper*/
2
+ /*jshint strict:false maxstatements:99*/
1
3
  casper.start('tests/site/mouse-events.html');
2
4
 
3
5
  casper.then(function() {
@@ -23,5 +25,5 @@ casper.then(function() {
23
25
  });
24
26
 
25
27
  casper.run(function() {
26
- this.test.done();
28
+ this.test.done(16);
27
29
  });
@@ -1,3 +1,5 @@
1
+ /*global casper*/
2
+ /*jshint strict:false*/
1
3
  casper.test.comment("page.error event");
2
4
 
3
5
  var error = {};
@@ -15,5 +17,5 @@ casper.thenOpen('tests/site/error.html', function() {
15
17
  });
16
18
 
17
19
  casper.run(function() {
18
- this.test.done();
20
+ this.test.done(2);
19
21
  });
@@ -1,3 +1,5 @@
1
+ /*global casper*/
2
+ /*jshint strict:false*/
1
3
  var t = casper.test, current = 0, tests = [
2
4
  function(settings) {
3
5
  t.assertEquals(settings, {
@@ -22,6 +24,30 @@ var t = casper.test, current = 0, tests = [
22
24
  username: 'bob',
23
25
  password: 'sinclar'
24
26
  }, "Casper.open() used the expected HTTP auth settings");
27
+ },
28
+ function(settings) {
29
+ t.assertEquals(settings, {
30
+ method: "get"
31
+ }, "Casper.thenOpen() used the expected GET settings");
32
+ },
33
+ function(settings) {
34
+ t.assertEquals(settings, {
35
+ method: "post",
36
+ data: "plop=42&chuck=norris"
37
+ }, "Casper.thenOpen() used the expected POST settings");
38
+ },
39
+ function(settings) {
40
+ t.assertEquals(settings, {
41
+ method: "put",
42
+ data: "plop=42&chuck=norris"
43
+ }, "Casper.thenOpen() used the expected PUT settings");
44
+ },
45
+ function(settings) {
46
+ t.assertEquals(settings, {
47
+ method: "get",
48
+ username: 'bob',
49
+ password: 'sinclar'
50
+ }, "Casper.thenOpen() used the expected HTTP auth settings");
25
51
  }
26
52
  ];
27
53
 
@@ -67,7 +93,43 @@ casper.open('tests/site/index.html', {
67
93
  t.pass("Casper.open() can open and load a location using HTTP auth");
68
94
  });
69
95
 
96
+ // GET with thenOpen
97
+ casper.thenOpen('tests/site/index.html').then(function() {
98
+ t.pass("Casper.thenOpen() can open and load a location using GET");
99
+ });
100
+
101
+ // POST with thenOpen
102
+ casper.thenOpen('tests/site/index.html', {
103
+ method: 'post',
104
+ data: {
105
+ plop: 42,
106
+ chuck: 'norris'
107
+ }
108
+ }, function() {
109
+ t.pass("Casper.thenOpen() can open and load a location using POST");
110
+ });
111
+
112
+ // PUT with thenOpen
113
+ casper.thenOpen('tests/site/index.html', {
114
+ method: 'put',
115
+ data: {
116
+ plop: 42,
117
+ chuck: 'norris'
118
+ }
119
+ }, function() {
120
+ t.pass("Casper.thenOpen() can open and load a location using PUT");
121
+ });
122
+
123
+ // HTTP Auth with thenOpen
124
+ casper.thenOpen('tests/site/index.html', {
125
+ method: 'get',
126
+ username: 'bob',
127
+ password: 'sinclar'
128
+ }, function() {
129
+ t.pass("Casper.thenOpen() can open and load a location using HTTP auth");
130
+ });
131
+
70
132
  casper.run(function() {
71
133
  this.removeAllListeners('open');
72
- t.done();
134
+ t.done(16);
73
135
  });
@@ -0,0 +1,86 @@
1
+ /*jshint strict:false*/
2
+ /*global CasperError casper console phantom require*/
3
+ var utils = require('utils');
4
+ var x = require('casper').selectXPath;
5
+
6
+ casper.on('popup.created', function(popup) {
7
+ this.test.pass('"popup.created" event is fired');
8
+ this.test.assert(utils.isWebPage(popup),
9
+ '"popup.created" event callback get a popup page instance');
10
+ });
11
+
12
+ casper.on('popup.loaded', function(popup) {
13
+ this.test.pass('"popup.loaded" event is fired');
14
+ this.test.assertEquals(popup.evaluate(function() {
15
+ return document.title;
16
+ }), 'CasperJS test index',
17
+ '"popup.loaded" is triggered when popup content is actually loaded');
18
+ });
19
+
20
+ casper.on('popup.closed', function(popup) {
21
+ this.test.assertEquals(this.popups.length, 0, '"popup.closed" event is fired');
22
+ });
23
+
24
+ casper.start('tests/site/popup.html');
25
+
26
+ casper.waitForPopup('index.html', function() {
27
+ this.test.pass('Casper.waitForPopup() waits for a popup being created');
28
+ this.test.assertEquals(this.popups.length, 1, 'A popup has been added');
29
+ this.test.assert(utils.isWebPage(this.popups[0]), 'A popup is a WebPage');
30
+ });
31
+
32
+ casper.withPopup('index.html', function() {
33
+ this.test.assertUrlMatches(/index\.html$/,
34
+ 'Casper.withPopup() switched to popup as current active one');
35
+ this.test.assertEval(function() {
36
+ return '__utils__' in window;
37
+ }, 'Casper.withPopup() has client utils injected');
38
+ this.test.assertExists('h1',
39
+ 'Casper.withPopup() can perform assertions on the DOM');
40
+ this.test.assertExists(x('//h1'),
41
+ 'Casper.withPopup() can perform assertions on the DOM using XPath');
42
+ });
43
+
44
+ casper.then(function() {
45
+ this.test.assertUrlMatches(/popup\.html$/,
46
+ 'Casper.withPopup() has reverted to main page after using the popup');
47
+ });
48
+
49
+ casper.thenClick('.close', function() {
50
+ this.test.assertEquals(this.popups.length, 0, 'Popup is removed when closed');
51
+ });
52
+
53
+ casper.thenOpen('tests/site/popup.html');
54
+
55
+ casper.waitForPopup(/index\.html$/, function() {
56
+ this.test.pass('Casper.waitForPopup() waits for a popup being created');
57
+ });
58
+
59
+ casper.withPopup(/index\.html$/, function() {
60
+ this.test.assertTitle('CasperJS test index',
61
+ 'Casper.withPopup() can use a regexp to identify popup');
62
+ });
63
+
64
+ casper.thenClick('.close', function() {
65
+ this.test.assertUrlMatches(/popup\.html$/,
66
+ 'Casper.withPopup() has reverted to main page after using the popup');
67
+ this.test.assertEquals(this.popups.length, 0, 'Popup is removed when closed');
68
+ this.removeAllListeners('popup.created');
69
+ this.removeAllListeners('popup.loaded');
70
+ this.removeAllListeners('popup.closed');
71
+ });
72
+
73
+ casper.thenClick('a[target="_blank"]');
74
+
75
+ casper.waitForPopup('form.html', function() {
76
+ this.test.pass('Casper.waitForPopup() waits when clicked on a link with target=_blank');
77
+ });
78
+
79
+ casper.withPopup('form.html', function() {
80
+ this.test.assertTitle('CasperJS test form');
81
+ });
82
+
83
+ casper.run(function() {
84
+ // removes event listeners as they've now been tested already
85
+ this.test.done(25);
86
+ });