Commit 0d445eba 0d445eba12dd6161844b15fcba291586aa45dafd by Nicolas Perriault

added Casper#fetchText

1 parent 35ac229d
......@@ -332,6 +332,21 @@
},
/**
* Fetches innerText within the element(s) matching a given CSS3
* selector.
*
* @param String selector A CSS3 selector
* @return String
*/
fetchText: function(selector) {
return this.evaluate(function() {
return __utils__.fetchText('%selector%');
}, {
selector: selector.replace("'", "\'")
});
},
/**
* Fills a form with provided field values.
*
* @param String selector A CSS3 selector to the target form to fill
......@@ -686,6 +701,23 @@
};
/**
* Fetches innerText within the element(s) matching a given CSS3
* selector.
*
* @param String selector A CSS3 selector
* @return String
*/
this.fetchText = function(selector) {
var text = '', elements = this.findAll(selector);
if (elements && elements.length) {
Array.prototype.forEach.call(elements, function(element) {
text += element.innerText;
});
}
return text;
};
/**
* Fills a form with provided field values, and optionnaly submits it.
*
* @param HTMLElement|String form A form element, or a CSS3 selector to a form element
......
......@@ -38,6 +38,8 @@ casper.start('tests/site/index.html', function(self) {
self.test.assertEval(function() {
return typeof(__utils__) === "object";
}, 'start() injects ClientUtils instance within remote DOM');
self.test.comment('fetching')
self.test.assertEquals(self.fetchText('ul li'), 'onetwothree', 'fetchText() can retrieves text contents');
self.test.comment('encoding');
var image = self.base64encode('file://' + phantom.libraryPath + '/site/images/phantom.png');
self.test.assertEquals(image.length, 6160, 'base64encode() can retrieve base64 contents');
......
......@@ -8,5 +8,10 @@
<img src="images/phantom.png"/>
<a href="test.html">test</a>
<a href="form.html">form</a>
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
</body>
</html>
\ No newline at end of file
......