Commit 9639c602 9639c6029ffd8666c32dbc9a722906b087e7ccd0 by Laurent Jouanneau

Merge branch 'master' into slimerjs-2

2 parents b6cde77e 12ec6142
......@@ -168,6 +168,7 @@ casper.on('page.resource.requested', function(requestData, request) {
- merged [#427](https://github.com/n1k0/casperjs/issues/427) - Added `keepFocus` option to `Casper#sendKeys()`
- fixed [#441](https://github.com/n1k0/casperjs/issues/441) - added `--ssl-protocol` option support to the `casperjs` executable
- fixed [#452](https://github.com/n1k0/casperjs/pull/452) - allow uppercase http methods in `Casper#open()`
- fixed [#521](https://github.com/n1k0/casperjs/issue/521) - `sendKeys` for inputs without text attribute should not be restricted
- Added [`Casper#fillSelectors()`](http://docs.casperjs.org/en/latest/modules/casper.html#fillselectors) and [`Casper#fillXPath()`](http://docs.casperjs.org/en/latest/modules/casper.html#fillxpath)
- Added [`Casper#getElementsAttribute()`](http://docs.casperjs.org/en/latest/modules/casper.html#getelementsattribute) and [`Casper#getElementsInfo()`](http://docs.casperjs.org/en/latest/modules/casper.html#getelementsinfo)
- Added [`Casper#waitForUrl()`](http://docs.casperjs.org/en/latest/modules/casper.html#waitforurl)
......
......@@ -58,6 +58,12 @@ Run the script:
![](http://cl.ly/image/271e2i403A0F/Capture%20d%E2%80%99%C3%A9cran%202013-01-20%20%C3%A0%2009.26.15.png)
##Support
If you're having problems with using the project, use the support forum at CodersClan.
<a href="http://codersclan.net/forum/index.php?repo_id=32"><img src="http://www.codersclan.net/graphics/getSupport_blue_big.png" width="160"></a>
## Contributing
### Contributing code
......
......@@ -206,7 +206,7 @@ Asserts that current `HTTP status code <http://www.w3.org/Protocols/rfc2616/rfc2
Asserts that a provided string matches a provided javascript ``RegExp`` pattern::
casper.test.assertMatch('Chuck Norris', /^chuck/i, 'Chuck Norris' first name is Chuck');
casper.test.assertMatch('Chuck Norris', /^chuck/i, 'Chuck Norris\' first name is Chuck');
.. seealso::
......
......@@ -448,8 +448,8 @@ Casper.prototype.clickLabel = function clickLabel(label, tag) {
"use strict";
this.checkStarted();
tag = tag || "*";
var escapedLabel = label.toString().replace(/"/g, '\\"');
var selector = selectXPath(f('//%s[text()="%s"]', tag, escapedLabel));
var escapedLabel = utils.quoteXPathAttributeString(label);
var selector = selectXPath(f('//%s[text()=%s]', tag, escapedLabel));
return this.click(selector);
};
......@@ -1087,7 +1087,7 @@ Casper.prototype.getGlobal = function getGlobal(name) {
try {
result.value = JSON.stringify(window[name]);
} catch (e) {
var message = f("Unable to JSON encode window.%s: %s", name, e);
var message = "Unable to JSON encode window." + name + ": " + e;
__utils__.log(message, "error");
result.error = message;
}
......@@ -1559,7 +1559,7 @@ Casper.prototype.sendKeys = function(selector, keys, options) {
"hidden", "month", "number", "password", "range", "search",
"tel", "text", "time", "url", "week"],
isTextInput = false;
if (tag === 'textarea' || (tag === 'input' && supported.indexOf(type) !== -1)) {
if (tag === 'textarea' || (tag === 'input' && (typeof type === 'undefined' || supported.indexOf(type) !== -1))) {
// clicking on the input element brings it focus
isTextInput = true;
this.click(selector);
......
......@@ -673,6 +673,22 @@ function objectValues(obj) {
exports.objectValues = objectValues;
/**
* Prepares a string for xpath expression with the condition [text()=].
*
* @param String string
* @return String
*/
function quoteXPathAttributeString(string) {
"use strict";
if (/"/g.test(string)) {
return 'concat("' + string.toString().replace(/"/g, '", \'"\', "') + '")';
} else {
return '"' + string + '"';
}
}
exports.quoteXPathAttributeString = quoteXPathAttributeString;
/**
* Serializes a value using JSON.
*
* @param Mixed value
......
......@@ -10,6 +10,8 @@
<a id="test3" href="page1.html" onclick="results.test3 = true; return false">test3</a>
<a id="test4" href="http://www.google.com/">test4</a>
<a id="test5" href="#">test5</a>
<a id="test6" href="#">Label with double "quotes"</a>
<a id="test7" href="#">Label with single 'quotes'</a>
<script>
(function(window) {
window.results = {
......@@ -18,6 +20,8 @@
test3: false,
test4: false,
test5: [],
test6: false,
test7: false,
testdown: [],
testup: [],
testmove: [],
......@@ -47,6 +51,14 @@
test5elem.addEventListener('mouseup', function(event) {
results.test5.push('mouseup');
});
document.querySelector('#test6').onclick = function(event) {
results.test6 = true;
event.preventDefault();
};
document.querySelector('#test7').onclick = function(event) {
results.test7 = true;
event.preventDefault();
};
})(window);
</script>
</body>
......
......@@ -23,6 +23,9 @@
<input type="checkbox" name="checklist[]" value="3">
<input type="submit" name="submit" value="submit">
</form>
<form id="no-type-test-form" action="#" enctype="multipart/form-data">
<input name="notype">
<form>
<script>
(function () {
'use strict';
......
......@@ -35,7 +35,7 @@ casper.test.begin('onclick variants tests', 8, function(test) {
});
});
casper.test.begin('clickLabel tests tests', 8, function(test) {
casper.test.begin('clickLabel tests tests', 12, function(test) {
casper.start('tests/site/click.html', function() {
test.assert(this.clickLabel('test1'),
'Casper.clickLabel() can click an `href="javascript:` link');
......@@ -45,6 +45,10 @@ casper.test.begin('clickLabel tests tests', 8, function(test) {
'Casper.clickLabel() can click an `onclick=".*; return false"` link');
test.assert(this.clickLabel('test4'),
'Casper.clickLabel() can click an unobstrusive js handled link');
test.assert(this.clickLabel('Label with double "quotes"'),
'Casper.clickLabel() can click the link with double quotes in the label');
test.assert(this.clickLabel("Label with single 'quotes'"),
'Casper.clickLabel() can click the link with the single quotes in the label');
var results = this.getGlobal('results');
if (phantom.casperEngine === 'slimerjs') {
// "javascript:" link in Gecko are executed asynchronously, so we don't have result at this time
......@@ -59,6 +63,10 @@ casper.test.begin('clickLabel tests tests', 8, function(test) {
'Casper.clickLabel() has clicked an `onclick=".*; return false"` link');
test.assert(results.test4,
'Casper.clickLabel() has clicked an unobstrusive js handled link');
test.assert(results.test6,
'Casper.clickLabel() has clicked the link with double quotes in the label');
test.assert(results.test7,
'Casper.clickLabel() has clicked the link with single quotes in the label');
}).run(function() {
test.done();
});
......
......@@ -2,19 +2,25 @@
/*global CasperError, casper, console, phantom, require*/
var utils = require('utils');
casper.test.begin('sendKeys() tests', 3, function(test) {
casper.test.begin('sendKeys() tests', 4, function(test) {
casper.start('tests/site/form.html', function() {
this.sendKeys('input[name="email"]', 'duke@nuk.em');
this.sendKeys('input[name="language"]', 'fr', {keepFocus: true});
this.click('#autocomplete li:first-child');
this.sendKeys('textarea', "Damn, I’m looking good.");
var values = this.getFormValues('form');
var values = this.getFormValues('form[action="result.html"]');
test.assertEquals(values.email, 'duke@nuk.em',
'Casper.sendKeys() sends keys to given input');
test.assertEquals(values.language, 'french',
'Casper.sendKeys() sends keys to given input and keeps focus afterweards');
test.assertEquals(values.content, "Damn, I’m looking good.",
'Casper.sendKeys() sends keys to given textarea');
this.sendKeys('input[name="notype"]', "I have no type.");
values = this.getFormValues('form#no-type-test-form');
test.assertEquals(values.notype, "I have no type.",
'Casper.sendKeys() sends keys to given input without type attribute');
}).run(function() {
test.done();
});
......
......@@ -341,6 +341,19 @@ casper.test.begin('objectValues() tests', 2, function(test) {
test.done();
});
casper.test.begin('quoteXPathAttributeString() tests', 2, function(test) {
casper.start('tests/site/click.html', function() {
var selector = utils.format('//a[text()=%s]',
utils.quoteXPathAttributeString('Label with double "quotes"'));
test.assertExists(x(selector), utils.format('Xpath selector "%s" is found on "tests/site/click.html" page', selector));
selector = utils.format('//a[text()=%s]',
utils.quoteXPathAttributeString("Label with single 'quotes'"));
test.assertExists(x(selector), utils.format('Xpath selector "%s" is found on "tests/site/click.html" page', selector));
}).run(function() {
test.done();
});
});
casper.test.begin('unique() tests', 4, function(test) {
var testCases = [
{
......