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) {
this.step = -1;
this.steps = [];
this.test = tester.create(this);
// basic event handlers
this.on('deprecated', function(message) {
this.echo('[deprecated] ' + message, 'COMMENT');
});
};
// Casper class is an EventEmitter
......@@ -223,23 +228,25 @@ Casper.prototype.checkStep = function(self, onComplete) {
};
/**
* Emulates a click on the element from the provided selector, if
* possible. In case of success, `true` is returned.
* Emulates a click on the element from the provided selector using the mouse
* pointer, if possible.
*
* In case of success, `true` is returned, `false` otherwise.
*
* @param String selector A DOM CSS3 compatible selector
* @param Boolean fallbackToHref Whether to try to relocate to the value of any href attribute (default: true)
* @return Boolean
*/
Casper.prototype.click = function(selector, fallbackToHref) {
fallbackToHref = utils.isType(fallbackToHref, "undefined") ? true : !!fallbackToHref;
this.log("Click on selector: " + selector, "debug");
this.emit('click', selector, fallbackToHref);
return this.evaluate(function(selector, fallbackToHref) {
return __utils__.click(selector, fallbackToHref);
}, {
selector: selector,
fallbackToHref: fallbackToHref
});
if (arguments.length > 1) {
this.emit("deprecated", "The click() method does not process the fallbackToHref argument since 0.6");
}
try {
this.mouse.click(selector);
} catch (e) {
return false;
}
return true;
};
/**
......@@ -629,10 +636,12 @@ Casper.prototype.log = function(message, level, space) {
*
* @param String selector A DOM CSS3 compatible selector
* @return Casper
* @deprecated
* @since 0.6
*/
Casper.prototype.mouseClick = function(selector) {
this.mouse.click(selector);
return this;
this.emit("deprecated", "The mouseClick() method has been deprecated since 0.6; use click() instead");
return this.click(selector);
};
/**
......@@ -890,14 +899,16 @@ Casper.prototype.then = function(step) {
*
* @param String selector A DOM CSS3 compatible selector
* @param Function then Next step function to execute on page loaded (optional)
* @param Boolean fallbackToHref Whether to try to relocate to the value of any href attribute (default: true)
* @return Casper
* @see Casper#click
* @see Casper#then
*/
Casper.prototype.thenClick = function(selector, then, fallbackToHref) {
if (arguments.length > 2) {
this.emit("deprecated", "The thenClick() method does not process the fallbackToHref argument since 0.6");
}
this.then(function(self) {
self.click(selector, fallbackToHref);
self.click(selector);
});
return utils.isFunction(then) ? this.then(then) : this;
};
......
......@@ -217,6 +217,16 @@ function isJsFile(file) {
exports.isJsFile = isJsFile;
/**
* Checks if the provided value is null
*
* @return Boolean
*/
function isNull(value) {
return isType(value, "null");
}
exports.isNull = isNull;
/**
* Checks if value is a javascript Number
*
* @param mixed value
......@@ -266,6 +276,16 @@ function isType(what, typeName) {
exports.isType = isType;
/**
* Checks if the provided value is undefined
*
* @return Boolean
*/
function isUndefined(value) {
return isType(value, "undefined");
}
exports.isUndefined = isUndefined;
/**
* Checks if the provided var is a WebPage instance
*
* @param mixed what
......
......@@ -16,8 +16,8 @@
t.comment('CasperUtils.click()');
self.test.assert(self.click('#test1'), 'CasperUtils.click() can click an `href="javascript:` link');
self.test.assert(self.click('#test2'), 'CasperUtils.click() can click an `href="#"` link');
self.test.assert(!self.click('#test3'), 'CasperUtils.click() can click an `onclick=".*; return false"` link');
self.test.assert(!self.click('#test4'), 'CasperUtils.click() can click an unobstrusive js handled link');
self.test.assert(self.click('#test3'), 'CasperUtils.click() can click an `onclick=".*; return false"` link');
self.test.assert(self.click('#test4'), 'CasperUtils.click() can click an unobstrusive js handled link');
var results = self.getGlobal('results');
self.test.assert(results.test1, 'CasperUtils.click() has clicked an `href="javascript:` link');
self.test.assert(results.test2, 'CasperUtils.click() has clicked an `href="#"` link');
......
(function(t) {
casper.start('tests/site/index.html', function(self) {
self.mouseClick('a[href="test.html"]');
});
casper.then(function(self) {
t.comment('Casper.mouseClick()');
t.assertTitle('CasperJS test target', 'Casper.mouseClick() can click on a link');
});
// onclick variants tests
casper.thenOpen('tests/site/click.html', function(self) {
t.comment('Casper.mouseClick()');
self.mouseClick('#test1');
self.mouseClick('#test2');
self.mouseClick('#test3');
self.mouseClick('#test4');
var results = self.getGlobal('results');
self.test.assert(results.test1, 'Casper.mouseClick() has clicked an `href="javascript:` link');
self.test.assert(results.test2, 'Casper.mouseClick() has clicked an `href="#"` link');
self.test.assert(results.test3, 'Casper.mouseClick() has clicked an `onclick=".*; return false"` link');
self.test.assert(results.test4, 'Casper.mouseClick() has clicked an unobstrusive js handled link');
});
casper.run(function(self) {
t.done();
});
})(casper.test);
\ No newline at end of file