Commit e011e92a e011e92a4d96447bcda6fc8679ffdef680c1849b by Nicolas Perriault

changed Casper.click() to use the native mouse events, deprecated Casper.mouseClick()

1 parent f42e380f
...@@ -109,6 +109,11 @@ var Casper = function(options) { ...@@ -109,6 +109,11 @@ var Casper = function(options) {
109 this.step = -1; 109 this.step = -1;
110 this.steps = []; 110 this.steps = [];
111 this.test = tester.create(this); 111 this.test = tester.create(this);
112
113 // basic event handlers
114 this.on('deprecated', function(message) {
115 this.echo('[deprecated] ' + message, 'COMMENT');
116 });
112 }; 117 };
113 118
114 // Casper class is an EventEmitter 119 // Casper class is an EventEmitter
...@@ -223,23 +228,25 @@ Casper.prototype.checkStep = function(self, onComplete) { ...@@ -223,23 +228,25 @@ Casper.prototype.checkStep = function(self, onComplete) {
223 }; 228 };
224 229
225 /** 230 /**
226 * Emulates a click on the element from the provided selector, if 231 * Emulates a click on the element from the provided selector using the mouse
227 * possible. In case of success, `true` is returned. 232 * pointer, if possible.
233 *
234 * In case of success, `true` is returned, `false` otherwise.
228 * 235 *
229 * @param String selector A DOM CSS3 compatible selector 236 * @param String selector A DOM CSS3 compatible selector
230 * @param Boolean fallbackToHref Whether to try to relocate to the value of any href attribute (default: true)
231 * @return Boolean 237 * @return Boolean
232 */ 238 */
233 Casper.prototype.click = function(selector, fallbackToHref) { 239 Casper.prototype.click = function(selector, fallbackToHref) {
234 fallbackToHref = utils.isType(fallbackToHref, "undefined") ? true : !!fallbackToHref;
235 this.log("Click on selector: " + selector, "debug"); 240 this.log("Click on selector: " + selector, "debug");
236 this.emit('click', selector, fallbackToHref); 241 if (arguments.length > 1) {
237 return this.evaluate(function(selector, fallbackToHref) { 242 this.emit("deprecated", "The click() method does not process the fallbackToHref argument since 0.6");
238 return __utils__.click(selector, fallbackToHref); 243 }
239 }, { 244 try {
240 selector: selector, 245 this.mouse.click(selector);
241 fallbackToHref: fallbackToHref 246 } catch (e) {
242 }); 247 return false;
248 }
249 return true;
243 }; 250 };
244 251
245 /** 252 /**
...@@ -629,10 +636,12 @@ Casper.prototype.log = function(message, level, space) { ...@@ -629,10 +636,12 @@ Casper.prototype.log = function(message, level, space) {
629 * 636 *
630 * @param String selector A DOM CSS3 compatible selector 637 * @param String selector A DOM CSS3 compatible selector
631 * @return Casper 638 * @return Casper
639 * @deprecated
640 * @since 0.6
632 */ 641 */
633 Casper.prototype.mouseClick = function(selector) { 642 Casper.prototype.mouseClick = function(selector) {
634 this.mouse.click(selector); 643 this.emit("deprecated", "The mouseClick() method has been deprecated since 0.6; use click() instead");
635 return this; 644 return this.click(selector);
636 }; 645 };
637 646
638 /** 647 /**
...@@ -890,14 +899,16 @@ Casper.prototype.then = function(step) { ...@@ -890,14 +899,16 @@ Casper.prototype.then = function(step) {
890 * 899 *
891 * @param String selector A DOM CSS3 compatible selector 900 * @param String selector A DOM CSS3 compatible selector
892 * @param Function then Next step function to execute on page loaded (optional) 901 * @param Function then Next step function to execute on page loaded (optional)
893 * @param Boolean fallbackToHref Whether to try to relocate to the value of any href attribute (default: true)
894 * @return Casper 902 * @return Casper
895 * @see Casper#click 903 * @see Casper#click
896 * @see Casper#then 904 * @see Casper#then
897 */ 905 */
898 Casper.prototype.thenClick = function(selector, then, fallbackToHref) { 906 Casper.prototype.thenClick = function(selector, then, fallbackToHref) {
907 if (arguments.length > 2) {
908 this.emit("deprecated", "The thenClick() method does not process the fallbackToHref argument since 0.6");
909 }
899 this.then(function(self) { 910 this.then(function(self) {
900 self.click(selector, fallbackToHref); 911 self.click(selector);
901 }); 912 });
902 return utils.isFunction(then) ? this.then(then) : this; 913 return utils.isFunction(then) ? this.then(then) : this;
903 }; 914 };
......
...@@ -217,6 +217,16 @@ function isJsFile(file) { ...@@ -217,6 +217,16 @@ function isJsFile(file) {
217 exports.isJsFile = isJsFile; 217 exports.isJsFile = isJsFile;
218 218
219 /** 219 /**
220 * Checks if the provided value is null
221 *
222 * @return Boolean
223 */
224 function isNull(value) {
225 return isType(value, "null");
226 }
227 exports.isNull = isNull;
228
229 /**
220 * Checks if value is a javascript Number 230 * Checks if value is a javascript Number
221 * 231 *
222 * @param mixed value 232 * @param mixed value
...@@ -266,6 +276,16 @@ function isType(what, typeName) { ...@@ -266,6 +276,16 @@ function isType(what, typeName) {
266 exports.isType = isType; 276 exports.isType = isType;
267 277
268 /** 278 /**
279 * Checks if the provided value is undefined
280 *
281 * @return Boolean
282 */
283 function isUndefined(value) {
284 return isType(value, "undefined");
285 }
286 exports.isUndefined = isUndefined;
287
288 /**
269 * Checks if the provided var is a WebPage instance 289 * Checks if the provided var is a WebPage instance
270 * 290 *
271 * @param mixed what 291 * @param mixed what
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
16 t.comment('CasperUtils.click()'); 16 t.comment('CasperUtils.click()');
17 self.test.assert(self.click('#test1'), 'CasperUtils.click() can click an `href="javascript:` link'); 17 self.test.assert(self.click('#test1'), 'CasperUtils.click() can click an `href="javascript:` link');
18 self.test.assert(self.click('#test2'), 'CasperUtils.click() can click an `href="#"` link'); 18 self.test.assert(self.click('#test2'), 'CasperUtils.click() can click an `href="#"` link');
19 self.test.assert(!self.click('#test3'), 'CasperUtils.click() can click an `onclick=".*; return false"` link'); 19 self.test.assert(self.click('#test3'), 'CasperUtils.click() can click an `onclick=".*; return false"` link');
20 self.test.assert(!self.click('#test4'), 'CasperUtils.click() can click an unobstrusive js handled link'); 20 self.test.assert(self.click('#test4'), 'CasperUtils.click() can click an unobstrusive js handled link');
21 var results = self.getGlobal('results'); 21 var results = self.getGlobal('results');
22 self.test.assert(results.test1, 'CasperUtils.click() has clicked an `href="javascript:` link'); 22 self.test.assert(results.test1, 'CasperUtils.click() has clicked an `href="javascript:` link');
23 self.test.assert(results.test2, 'CasperUtils.click() has clicked an `href="#"` link'); 23 self.test.assert(results.test2, 'CasperUtils.click() has clicked an `href="#"` link');
......
1 (function(t) {
2 casper.start('tests/site/index.html', function(self) {
3 self.mouseClick('a[href="test.html"]');
4 });
5
6 casper.then(function(self) {
7 t.comment('Casper.mouseClick()');
8 t.assertTitle('CasperJS test target', 'Casper.mouseClick() can click on a link');
9 });
10
11 // onclick variants tests
12 casper.thenOpen('tests/site/click.html', function(self) {
13 t.comment('Casper.mouseClick()');
14 self.mouseClick('#test1');
15 self.mouseClick('#test2');
16 self.mouseClick('#test3');
17 self.mouseClick('#test4');
18 var results = self.getGlobal('results');
19 self.test.assert(results.test1, 'Casper.mouseClick() has clicked an `href="javascript:` link');
20 self.test.assert(results.test2, 'Casper.mouseClick() has clicked an `href="#"` link');
21 self.test.assert(results.test3, 'Casper.mouseClick() has clicked an `onclick=".*; return false"` link');
22 self.test.assert(results.test4, 'Casper.mouseClick() has clicked an unobstrusive js handled link');
23 });
24
25 casper.run(function(self) {
26 t.done();
27 });
28 })(casper.test);
...\ No newline at end of file ...\ No newline at end of file