Socket
Socket
Sign inDemoInstall

casperjs

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

casperjs - npm Package Compare versions

Comparing version 1.1.0-beta5 to 1.1.0

docs/cookbook.rst

12

bin/bootstrap.js

@@ -176,3 +176,5 @@ /*!

fs.pathJoin = function pathJoin() {
return Array.prototype.join.call(arguments, '/');
return Array.prototype.filter.call(arguments,function(elm){
return typeof elm !== "undefined" && elm !== null;
}).join('/');
};

@@ -283,3 +285,3 @@ }

baseDir = fs.absolute(fs.pathJoin(prevBaseDir, '..'));
} while (!resolved && baseDir !== '/' && baseDir !== prevBaseDir);
} while (!resolved && baseDir !== '/' && prevBaseDir !== '/' && baseDir !== prevBaseDir);
return resolved;

@@ -427,2 +429,8 @@ }

phantom.casperLoaded = true;
if (phantom.version.major === 2
&& phantom.casperScript
&& phantom.casperScript.split('.').pop() === 'coffee'
) {
return __terminate('CoffeeScript is not supported by PhantomJS > 2.');
}

@@ -429,0 +437,0 @@ // passed casperjs script execution

184

modules/clientutils.js

@@ -47,3 +47,3 @@ /*!

var BASE64_ENCODE_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var BASE64_DECODE_CHARS = new Array(
var BASE64_DECODE_CHARS = [
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,

@@ -57,3 +57,3 @@ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,

41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1
);
];
var SUPPORTED_SELECTOR_TYPES = ['css', 'xpath'];

@@ -88,6 +88,8 @@

* @param String selector A CSS3 selector to the element to click
* @param {Number} x X position
* @param {Number} y Y position
* @return Boolean
*/
this.click = function click(selector) {
return this.mouseEvent('click', selector);
this.click = function click(selector, x, y) {
return this.mouseEvent('click', selector, x, y);
};

@@ -117,7 +119,8 @@

}
out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
out += String.fromCharCode(c1 << 2 | (c2 & 0x30) >> 4);
do {
c3 = str.charCodeAt(i++) & 0xff;
if (c3 === 61)
return out;
if (c3 === 61) {
return out;
}
c3 = BASE64_DECODE_CHARS[c3];

@@ -128,3 +131,3 @@ } while (i < len && c3 === -1);

}
out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
out += String.fromCharCode((c2 & 0XF) << 4 | (c3 & 0x3C) >> 2);
do {

@@ -140,3 +143,3 @@ c4 = str.charCodeAt(i++) & 0xff;

}
out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
out += String.fromCharCode((c3 & 0x03) << 6 | c4);
}

@@ -200,3 +203,3 @@ return out;

out += BASE64_ENCODE_CHARS.charAt(c1 >> 2);
out += BASE64_ENCODE_CHARS.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
out += BASE64_ENCODE_CHARS.charAt((c1 & 0x3) << 4 | (c2 & 0xF0) >> 4);
out += BASE64_ENCODE_CHARS.charAt((c2 & 0xF) << 2);

@@ -208,4 +211,4 @@ out += "=";

out += BASE64_ENCODE_CHARS.charAt(c1 >> 2);
out += BASE64_ENCODE_CHARS.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
out += BASE64_ENCODE_CHARS.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
out += BASE64_ENCODE_CHARS.charAt((c1 & 0x3) << 4 | (c2 & 0xF0) >> 4);
out += BASE64_ENCODE_CHARS.charAt((c2 & 0xF) << 2 | (c3 & 0xC0) >> 6);
out += BASE64_ENCODE_CHARS.charAt(c3 & 0x3F);

@@ -253,3 +256,4 @@ }

* @param Function findType Element finder type (css, names, xpath)
* @return Object An object containing setting result for each field, including file uploads
* @return Object An object containing setting result for each field,
* including file uploads
*/

@@ -261,3 +265,3 @@ this.fill = function fill(form, vals, findType) {

fields: [],
files: []
files: []
};

@@ -283,15 +287,16 @@

var finders = {
css: function(inputSelector, formSelector) {
css: function(inputSelector) {
return this.findAll(inputSelector, form);
},
labels: function(labelText, formSelector, value) {
var label = this.findOne({type: "xpath", path: '//label[text()="' + labelText + '"]'}, form);
if(label && label.htmlFor) {
labels: function(labelText) {
var label = this.findOne({type: "xpath", path: '//label[text()="' +
labelText + '"]'}, form);
if (label && label.htmlFor) {
return this.findAll('#' + label.htmlFor, form);
}
},
names: function(elementName, formSelector) {
names: function(elementName) {
return this.findAll('[name="' + elementName + '"]', form);
},
xpath: function(xpath, formSelector) {
xpath: function(xpath) {
return this.findAll({type: "xpath", path: xpath}, form);

@@ -308,3 +313,4 @@ }

if (!field || field.length === 0) {
out.errors.push('no field matching ' + findType + ' selector "' + fieldSelector + '" in form');
out.errors.push('no field matching ' + findType + ' selector "' +
fieldSelector + '" in form');
continue;

@@ -317,3 +323,3 @@ }

var selector;
if(findType === "labels") {
if (findType === "labels") {
selector = '#' + field[0].id;

@@ -381,2 +387,21 @@ } else {

/**
* Force target on <FORM> and <A> tag.
*
* @param String selector CSS3 selector
* @param String A HTML target '_blank','_self','_parent','_top','framename'
* @return Boolean
*/
this.forceTarget = function forceTarget(selector, target) {
var elem = this.findOne(selector);
while (!!elem && elem.tagName !== 'A' && elem.tagName !== 'FORM' && elem.tagName !== 'BODY'){
elem = elem.parentNode;
}
if (elem === 'A' || elem === 'FORM') {
elem.setAttribute('target', target);
return true;
}
return false;
};
/**
* Downloads a resource behind an url and returns its base64-encoded

@@ -410,3 +435,4 @@ * contents.

if (e.name === "NETWORK_ERR" && e.code === 101) {
this.log("getBinary(): Unfortunately, casperjs cannot make cross domain ajax requests", "warning");
this.log("getBinary(): Unfortunately, casperjs cannot make"
+ " cross domain ajax requests", "warning");
}

@@ -433,2 +459,16 @@ this.log("getBinary(): Error while fetching " + url + ": " + e, "error");

/**
* Retrieves total document width.
* http://james.padolsey.com/javascript/get-document-width-cross-browser/
*
* @return {Number}
*/
this.getDocumentWidth = function getDocumentWidth() {
return Math.max(
Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
Math.max(document.body.offsetWidth, document.documentElement.offsetWidth),
Math.max(document.body.clientWidth, document.documentElement.clientWidth)
);
};
/**
* Retrieves bounding rect coordinates of the HTML element matching the

@@ -446,5 +486,5 @@ * provided CSS3 selector in the following form:

return {
top: clipRect.top,
left: clipRect.left,
width: clipRect.width,
top: clipRect.top,
left: clipRect.left,
width: clipRect.width,
height: clipRect.height

@@ -470,3 +510,2 @@ };

var elements = this.findAll(selector);
var self = this;
try {

@@ -476,5 +515,5 @@ return Array.prototype.map.call(elements, function(element) {

return {
top: clipRect.top,
left: clipRect.left,
width: clipRect.width,
top: clipRect.top,
left: clipRect.left,
width: clipRect.width,
height: clipRect.height

@@ -583,5 +622,5 @@ };

*/
this.getFieldValue = function getFieldValue(inputName, options) {
options = options || {};
function getSingleValue(input) {
this.getFieldValue = function getFieldValue(inputName, _options) {
_options = _options || {};
var getSingleValue = function getSingleValue(input) {
var type;

@@ -610,4 +649,4 @@ try {

return input.checked;
}
function getMultipleValues(inputs) {
};
var getMultipleValues = function getMultipleValues(inputs) {
var type;

@@ -630,20 +669,20 @@ type = inputs[0].getAttribute('type').toLowerCase();

}
}
};
var formSelector = '';
if (options.formSelector) {
formSelector = options.formSelector + ' ';
if (_options.formSelector) {
formSelector = _options.formSelector + ' ';
}
var inputs = this.findAll(formSelector + '[name="' + inputName + '"]');
if (options.inputSelector) {
inputs = inputs.concat(this.findAll(options.inputSelector));
if (_options.inputSelector) {
inputs = inputs.concat(this.findAll(_options.inputSelector));
}
if (options.inputXPath) {
inputs = inputs.concat(this.getElementsByXPath(options.inputXPath));
if (_options.inputXPath) {
inputs = inputs.concat(this.getElementsByXPath(_options.inputXPath));
}
switch (inputs.length) {
case 0: return undefined;
case 1: return getSingleValue(inputs[0]);
case 0: return undefined;
case 1: return getSingleValue(inputs[0]);
default: return getMultipleValues(inputs);

@@ -686,21 +725,35 @@ }

*
* @param String type Type of event to dispatch
* @param String selector A CSS3 selector to the element to click
* @param String type Type of event to dispatch
* @param String selector A CSS3 selector to the element to click
* @param {Number} x X position
* @param {Number} y Y position
* @return Boolean
*/
this.mouseEvent = function mouseEvent(type, selector) {
this.mouseEvent = function mouseEvent(type, selector, x, y) {
var elem = this.findOne(selector);
if (!elem) {
this.log("mouseEvent(): Couldn't find any element matching '" + selector + "' selector", "error");
this.log("mouseEvent(): Couldn't find any element matching '" +
selector + "' selector", "error");
return false;
}
var convertNumberToIntAndPercentToFloat = function (a, def){
return !!a && !isNaN(a) && parseInt(a, 10) ||
!!a && !isNaN(parseFloat(a)) && parseFloat(a) >= 0 &&
parseFloat(a) <= 100 && parseFloat(a) / 100 ||
def;
};
try {
var evt = document.createEvent("MouseEvents");
var center_x = 1, center_y = 1;
var px = convertNumberToIntAndPercentToFloat(x, 0.5),
py = convertNumberToIntAndPercentToFloat(y, 0.5);
try {
var pos = elem.getBoundingClientRect();
center_x = Math.floor((pos.left + pos.right) / 2);
center_y = Math.floor((pos.top + pos.bottom) / 2);
} catch(e) {}
evt.initMouseEvent(type, true, true, window, 1, 1, 1, center_x, center_y, false, false, false, false, 0, elem);
var bounds = elem.getBoundingClientRect();
px = Math.floor(bounds.width * (px - (px ^ 0)).toFixed(10)) + (px ^ 0) + bounds.left;
py = Math.floor(bounds.height * (py - (py ^ 0)).toFixed(10)) + (py ^ 0) + bounds.top;
} catch (e) {
px = 1; py = 1;
}
evt.initMouseEvent(type, true, true, window, 1, 1, 1, px, py, false, false, false, false,
type !== "contextmenu" ? 0 : 2, elem);
// dispatchEvent return value is false if at least one of the event

@@ -766,3 +819,4 @@ // handlers which handled this event called preventDefault;

this.removeElementsByXPath = function removeElementsByXPath(expression) {
var a = document.evaluate(expression, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var a = document.evaluate(expression, document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < a.snapshotLength; i++) {

@@ -814,3 +868,6 @@ a.snapshotItem(i).parentNode.removeChild(a.snapshotItem(i));

for (var k in data) {
dataList.push(encodeURIComponent(k) + "=" + encodeURIComponent(data[k].toString()));
if (data.hasOwnProperty(k)) {
dataList.push(encodeURIComponent(k) + "=" +
encodeURIComponent(data[k].toString()));
}
}

@@ -838,3 +895,3 @@ dataString = dataList.join('&');

var logValue, fields, out;
value = logValue = (value || "");
value = logValue = value || "";

@@ -854,3 +911,3 @@ if (field instanceof NodeList || field instanceof Array) {

// obfuscate password value
logValue = new Array((''+value).length + 1).join("*");
logValue = new Array(('' + value).length + 1).join("*");
}

@@ -887,5 +944,5 @@

throw {
name: "FileUploadError",
name: "FileUploadError",
message: "File field must be filled using page.uploadFile",
path: value
path: value
};

@@ -896,3 +953,3 @@ case "radio":

Array.prototype.forEach.call(fields, function _forEach(e) {
e.checked = (e.value === value);
e.checked = e.value === value;
});

@@ -924,3 +981,3 @@ } else {

// PhantomJS 1.x.x can't handle setting value to ''
if ('' === value) {
if (value === "") {
field.selectedIndex = -1;

@@ -959,3 +1016,4 @@ } else {

} catch (err) {
this.log("Unable to blur() input field " + field.getAttribute('name') + ": " + err, "warning");
this.log("Unable to blur() input field " + field.getAttribute('name') +
": " + err, "warning");
}

@@ -962,0 +1020,0 @@ return out;

@@ -36,7 +36,2 @@ /*!

exports.create = function create(casper) {
"use strict";
return new Mouse(casper);
};
var Mouse = function Mouse(casper) {

@@ -49,19 +44,60 @@ "use strict";

var slice = Array.prototype.slice,
nativeEvents = ['mouseup', 'mousedown', 'click', 'mousemove'];
nativeEvents = ['mouseup', 'mousedown', 'click', 'mousemove'],
nativeButtons = ['left', 'middle', 'right'];
if (utils.gteVersion(phantom.version, '1.8.0')) {
nativeEvents.push('doubleclick');
}
var emulatedEvents = ['mouseover', 'mouseout'],
if (utils.gteVersion(phantom.version, '2.1.0')) {
nativeEvents.push('contextmenu');
}
var emulatedEvents = ['mouseover', 'mouseout', 'mouseenter', 'mouseleave'],
supportedEvents = nativeEvents.concat(emulatedEvents);
function computeCenter(selector) {
var computeCenter = function computeCenter(selector) {
var bounds = casper.getElementBounds(selector);
if (utils.isClipRect(bounds)) {
var x = Math.round(bounds.left + bounds.width / 2);
var y = Math.round(bounds.top + bounds.height / 2);
var x = Math.round(bounds.left + bounds.width / 2),
y = Math.round(bounds.top + bounds.height / 2);
return [x, y];
}
}
return [0, 0];
};
function processEvent(type, args) {
var getPointFromViewPort = function getPointFromViewPort(page, x, y){
var px = x - x % page.viewportSize.width;
var py = y - y % page.viewportSize.height;
var max = casper.evaluate(function() {
return [__utils__.getDocumentWidth(), __utils__.getDocumentHeight()];
});
if (py > max[0] - page.viewportSize.width && max[0] > page.viewportSize.width){
px = max[0] - page.viewportSize.width;
}
if (py > max[1] - page.viewportSize.height && max[1] > page.viewportSize.height){
py = max[1] - page.viewportSize.height;
}
page.scrollPosition = { 'left': px, 'top': py };
return [ x - px, y - py ];
};
var getPointFromSelectorCoords = function getPointFromSelectorCoords(selector, clientX, clientY){
var convertNumberToIntAndPercentToFloat = function convertNumberToIntAndPercentToFloat(a, def){
return !!a && !isNaN(a) && parseInt(a, 10) ||
!!a && !isNaN(parseFloat(a)) && parseFloat(a) >= 0 &&
parseFloat(a) <= 100 && parseFloat(a) / 100 ||
def;
};
var bounds = casper.getElementBounds(selector),
px = convertNumberToIntAndPercentToFloat(clientX, 0.5),
py = convertNumberToIntAndPercentToFloat(clientY, 0.5);
if (utils.isClipRect(bounds)) {
return [ bounds.left + (px ^ 0) + Math.round(bounds.width * (px - (px ^ 0)).toFixed(10)),
bounds.top + (py ^ 0) + Math.round(bounds.height * (py - (py ^ 0)).toFixed(10)) ];
}
return [1, 1];
};
var processEvent = function processEvent(type, args) {
var button = nativeButtons[0], selector = 'html', index = 0, point,
scroll = casper.page.scrollPosition;
if (!utils.isString(type) || supportedEvents.indexOf(type) === -1) {

@@ -73,25 +109,23 @@ throw new CasperError('Mouse.processEvent(): Unsupported mouse event type: ' + type);

}
args = slice.call(args); // cast Arguments -> Array
args = [].slice.call(args); // cast Arguments -> Array
if (args.length === 0) {
throw new CasperError('Mouse.processEvent(): Too few arguments');
}
if (isNaN(parseInt(args[0], 10)) && casper.exists(args[0])) {
selector = args[0];
index++;
}
if (args.length >= index + 2) {
point = getPointFromSelectorCoords(selector, args[index], args[index + 1]);
} else {
point = computeCenter(selector);
}
index = nativeButtons.indexOf(args[args.length - 1]);
if (index > -1) {
button = nativeButtons[index];
}
casper.emit('mouse.' + type.replace('mouse', ''), args);
switch (args.length) {
case 0:
throw new CasperError('Mouse.processEvent(): Too few arguments');
case 1:
// selector
casper.page.sendEvent.apply(casper.page, [type].concat(computeCenter(args[0])));
break;
case 2:
// coordinates
if (!utils.isNumber(args[0]) || !utils.isNumber(args[1])) {
throw new CasperError('Mouse.processEvent(): No valid coordinates passed: ' + args);
}
casper.page.sendEvent(type, args[0], args[1]);
break;
default:
throw new CasperError('Mouse.processEvent(): Too many arguments');
}
}
this.processEvent = function() {
processEvent(arguments[0], slice.call(arguments, 1));
point = getPointFromViewPort(casper.page, point[0], point[1]);
casper.page.sendEvent.apply(casper.page, [type].concat(point).concat([button]));
casper.page.scrollPosition = scroll;
};

@@ -103,30 +137,2 @@

this.rightclick = function rightclick() {
var array = [];
switch (arguments.length) {
case 0:
throw new CasperError('Mouse.rightclick(): Too few arguments');
case 1:
array = computeCenter(arguments[0]);
break;
case 2:
array = arguments;
break;
default:
throw new CasperError('Mouse.rightclick(): Too many arguments');
}
casper.page.evaluate(function (clientX, clientY) {
var element = document.elementFromPoint(clientX, clientY);
raiseEvent('contextmenu');
function raiseEvent(eventType) {
var event = document.createEvent('MouseEvent');
event.initMouseEvent(eventType, true, true, window, 1, clientX, clientY, clientX, clientY, false, false, false, false, 2, null);
element.dispatchEvent(event);
}
}, array[0], array[1]);
};
this.doubleclick = function doubleclick() {

@@ -144,2 +150,56 @@ processEvent('doubleclick', arguments);

this.processEvent = function() {
processEvent(arguments[0], [].slice.call(arguments, 1));
};
this.rightclick = function rightclick() {
try {
processEvent('contextmenu', arguments);
} catch (e) {
var args = slice.call(arguments);
switch (args.length) {
case 0:
throw new CasperError('Mouse.rightclick(): Too few arguments');
case 1:
casper.mouseEvent('contextmenu', args[0]);
break;
case 2:
if (!utils.isNumber(args[0]) || !utils.isNumber(args[1])) {
throw new CasperError('Mouse.rightclick(): No valid coordinates passed: ' + args);
}
var struct = casper.page.evaluate(function (clientX, clientY) {
var xpath = function xpath(el) {
if (typeof el === "string") {
return document.evaluate(el, document, null, 0, null);
}
if (!el || el.nodeType !== 1) {
return '';
}
if (el.id) {
return "//*[@id='" + el.id + "']";
}
var sames = [].filter.call(el.parentNode.children, function (x) {
return x.tagName === el.tagName;
});
return xpath(el.parentNode) + '/' + el.tagName.toLowerCase() +
(sames.length > 1 ? '[' + ([].indexOf.call(sames, el) + 1) + ']' : '');
};
try {
var elem = document.elementFromPoint(clientX, clientY);
var rec = elem.getBoundingClientRect();
return { "selector": {"type": "xpath", "path": xpath(elem)},
"relX": clientX - rec.left, "relY": clientY - rec.top };
} catch (ex) {
return { "selector": {"type": "xpath", "path": "//html"},
"relX": clientX, "relY": clientY };
}
}, args[0], args[1]);
casper.mouseEvent('contextmenu', struct.selector, struct.relX, struct.relY);
break;
default:
throw new CasperError('Mouse.rightclick(): Too many arguments');
}
}
};
this.up = function up() {

@@ -149,2 +209,8 @@ processEvent('mouseup', arguments);

};
exports.create = function create(casper) {
"use strict";
return new Mouse(casper);
};
exports.Mouse = Mouse;

@@ -53,18 +53,16 @@ /*!

/**
* Cleans the stack from closed popup.
* Cleans the stack from any closed popups.
*
* @param WebPage closed Closed popup page instance
* @return Number New stack length
*/
Stack.prototype.clean = function clean(closed) {
Stack.prototype.clean = function clean() {
"use strict";
var closedIndex = -1;
var self = this;
this.forEach(function(popup, index) {
if (closed === popup) {
closedIndex = index;
// window references lose the parent attribute when they are no longer valid
if (popup.parent === null || typeof popup.parent === "undefined") {
self.splice(index, 1);
}
});
if (closedIndex > -1) {
this.splice(closedIndex, 1);
}
return this.length;

@@ -71,0 +69,0 @@ };

@@ -1551,3 +1551,3 @@ /*!

style = 'WARN_BAR';
result = f("%s Looks like you didn't run any test.", statusText);
result = f("%s Looks like you didn't run any tests.", statusText);
} else {

@@ -1554,0 +1554,0 @@ if (this.suiteResults.isFailed()) {

@@ -729,3 +729,3 @@ /*!

"use strict";
var _node = document.createElement(name);
var _node = document.createElementNS('', name);
for (var attrName in attributes) {

@@ -732,0 +732,0 @@ var value = attributes[attrName];

@@ -83,4 +83,11 @@ /*!

"use strict";
// Since we are outputting XML, let's do our own document type
var documentType = document.implementation.createDocumentType("casperjs", "-//CasperJS//XUnit Test Results", "testsuites");
this._xmlDocument = document.implementation.createDocument("", "", documentType);
this._xml = this._xmlDocument.appendChild(this._xmlDocument.createElement("testsuites"));
// Initialize everything else
this.results = undefined;
this._xml = utils.node('testsuites');
}

@@ -96,2 +103,5 @@ exports.XUnitExporter = XUnitExporter;

"use strict";
var self = this;
if (!(this.results instanceof TestSuiteResult)) {

@@ -110,3 +120,3 @@ throw new CasperError('Results not set, cannot get XML.');

});
// succesful test cases
// successful test cases
result.passes.forEach(function(success) {

@@ -130,3 +140,3 @@ var testCase = utils.node('testcase', {

});
failureNode.appendChild(document.createTextNode(failure.message || "no message left"));
failureNode.appendChild(self._xmlDocument.createCDATASection(failure.message || "no message left"));
if (failure.values && failure.values.error instanceof Error) {

@@ -136,3 +146,3 @@ var errorNode = utils.node('error', {

});
errorNode.appendChild(document.createTextNode(failure.values.error.stack));
errorNode.appendChild(self._xmlDocument.createCDATASection(failure.values.error.stack));
testCase.appendChild(errorNode);

@@ -148,3 +158,3 @@ }

});
errorNode.appendChild(document.createTextNode(error.stack ? error.stack : error.message));
errorNode.appendChild(self._xmlDocument.createCDATASection(error.stack ? error.stack : error.message));
suiteNode.appendChild(errorNode);

@@ -154,8 +164,9 @@ });

var warningNode = utils.node('system-out');
warningNode.appendChild(document.createTextNode(result.warnings.join('\n')));
warningNode.appendChild(self._xmlDocument.createCDATASection(result.warnings.join('\n')));
suiteNode.appendChild(warningNode);
this._xml.appendChild(suiteNode);
}.bind(this));
this._xml.setAttribute('time', utils.ms2seconds(this.results.calculateDuration()));
return this._xml;
return this._xmlDocument;
};

@@ -168,6 +179,6 @@

*/
XUnitExporter.prototype.getSerializedXML = function getSerializedXML(xml) {
XUnitExporter.prototype.getSerializedXML = function getSerializedXML() {
"use strict";
var serializer = new XMLSerializer();
return '<?xml version="1.0" encoding="UTF-8"?>' + serializer.serializeToString(this.getXML());
return '<?xml version="1.0" encoding="UTF-8"?>' + serializer.serializeToString(this._xmlDocument);
};

@@ -174,0 +185,0 @@

{
"name": "casperjs",
"description": "A navigation scripting & testing utility for PhantomJS and SlimerJS",
"version": "1.1.0-beta5",
"version": "1.1.0",
"keywords": [

@@ -6,0 +6,0 @@ "phantomjs",

@@ -20,3 +20,3 @@ # CasperJS

It eases the process of defining a full navigation
scenario and provides useful high-level functions, methods & syntaxic sugar for doing common
scenario and provides useful high-level functions, methods & syntactic sugar for doing common
tasks such as:

@@ -98,2 +98,3 @@

- Matt DuVall ([@mduvall](https://github.com/mduvall))
- Ryan Null ([@BIGjuevos](https://github.com/BIGjuevos))

@@ -100,0 +101,0 @@ ## License

@@ -157,1 +157,113 @@ /*global casper*/

});
casper.test.begin('click() on coordinates in selector', 6, function(test) {
var zone;
casper.start('tests/site/area.html', function() {
zone = this.getElementBounds("#contentContainer");
this.click("#contentContainer",10,20);
}).then(function() {
var results = this.getElementBounds("#thing");
test.assertEquals(results.left, Math.floor(10-(results.width)/2)+zone.left,
'click() on specific X position 1');
test.assertEquals(results.top, Math.floor(20-(results.height)/2)+zone.top,
'click() on specific Y position 1');
}).then(function() {
this.click("#contentContainer",100,200);
}).then(function() {
var results = this.getElementBounds("#thing");
test.assertEquals(results.left, Math.floor(100-(results.width)/2)+zone.left,
'click() on specific X position 2');
test.assertEquals(results.top, Math.floor(200-(results.height)/2)+zone.top,
'click() on specific Y position 2 ');
}).then(function() {
this.click("#contentContainer","80%","60%");
}).then(function() {
var results = this.getElementBounds("#thing");
test.assertEquals(results.left, Math.floor((zone.width*0.8)-(results.width)/2)+zone.left,
'click() on specific X position with percent');
test.assertEquals(results.top, Math.floor((zone.height*0.6)-(results.height)/2)+zone.top,
'click() on specific Y position with percent');
}).run(function() {
test.done();
});
});
casper.test.begin('click() on scroll in selector', 4, function(test) {
var zone;
casper.start('tests/site/area.html', function() {
zone = this.getElementBounds("#out");
this.click("#out");
}).then(function() {
var results = this.getElementBounds("#thinga");
test.assertEquals(results.left, Math.floor((zone.width-results.width)/2)+zone.left,
'Mouse.click() on default X position 50%');
test.assertEquals(results.top, Math.floor((zone.height-results.height)/2)+zone.top,
'Mouse.click() on default Y position 50%');
}).then(function() {
this.click("#out",10,20);
}).then(function() {
var results = this.getElementBounds("#thinga");
test.assertEquals(results.left, Math.floor(10-(results.width)/2)+zone.left,
'Mouse.click() on specific X position');
test.assertEquals(results.top, Math.floor(20-(results.height)/2)+zone.top,
'Mouse.move() on specific Y position');
}).run(function() {
test.done();
});
});
casper.test.begin('casper.mouse() on coordinates in selector', 6, function(test) {
var zone;
casper.start('tests/site/area.html', function() {
zone = this.getElementBounds("#contentContainer");
this.mouse.click("#contentContainer");
}).then(function() {
var results = this.getElementBounds("#thing");
test.assertEquals(results.left, Math.floor((zone.width-results.width)/2)+zone.left,
'Mouse.click() on default X position 50%');
test.assertEquals(results.top, Math.floor((zone.height-results.height)/2)+zone.top,
'Mouse.click() on default Y position 50%');
}).then(function() {
this.mouse.click("#contentContainer",10,20);
}).then(function() {
var results = this.getElementBounds("#thing");
test.assertEquals(results.left, Math.floor(10-(results.width)/2)+zone.left,
'Mouse.click() on specific X position');
test.assertEquals(results.top, Math.floor(20-(results.height)/2)+zone.top,
'Mouse.move() on specific Y position');
}).then(function() {
this.mouse.click("#contentContainer","80%","60%");
}).then(function() {
var results = this.getElementBounds("#thing");
test.assertEquals(results.left, Math.floor((zone.width*0.8)-(results.width)/2)+zone.left,
'Mouse.click() on specific X position with percent');
test.assertEquals(results.top, Math.floor((zone.height*0.6)-(results.height)/2)+zone.top,
'Mouse.click() on specific Y position with percent');
}).run(function() {
test.done();
});
});
casper.test.begin('casper.mouse() on scroll in selector', 4, function(test) {
var zone;
casper.start('tests/site/area.html', function() {
zone = this.getElementBounds("#out");
this.mouse.click("#out");
}).then(function() {
var results = this.getElementBounds("#thinga");
test.assertEquals(results.left, Math.floor((zone.width-results.width)/2)+zone.left,
'Mouse.click() on default X position 50%');
test.assertEquals(results.top, Math.floor((zone.height-results.height)/2)+zone.top,
'Mouse.click() on default Y position 50%');
}).then(function() {
this.mouse.click("#out",10,20);
}).then(function() {
var results = this.getElementBounds("#thinga");
test.assertEquals(results.left, Math.floor(10-(results.width)/2)+zone.left,
'Mouse.click() on specific X position');
test.assertEquals(results.top, Math.floor(20-(results.height)/2)+zone.top,
'Mouse.move() on specific Y position');
}).run(function() {
test.done();
});
});

@@ -204,2 +204,21 @@ /*eslint strict:0*/

casper.test.begin('file multiple', 1, function(test) {
var fpaths = [fs.pathJoin(phantom.casperPath, 'README.md'),
fs.pathJoin(phantom.casperPath, 'LICENSE.md')
];
casper.start('tests/site/field-file-multiple.html', function() {
this.fillSelectors('form[action="result.html"]', {
'input[name="files[]"]': fpaths
});
if (!skipPhantom200(test, 1)) {
test.assertEval(function() {
return __utils__.findOne('input[type="file"]').files.length === 2;
});
}
}).run(function() {
test.done();
});
});
casper.test.begin('field array', 1, function(test) {

@@ -206,0 +225,0 @@ // issue #267: array syntax field names

@@ -346,1 +346,38 @@ /*eslint strict:0*/

});
casper.test.begin('open() POST json object with utf8 content', 2, {
setUp: setUp,
tearDown: tearDown,
test: function(test) {
casper.open('tests/site/index.html', {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
encoding: 'utf8',
data: {
plop: 42,
chuck: 'nórrïs',
john: {'Doe': 'ïs here™€'}
}
}).then(function() {
test.pass("Casper.open() can POST a JSON object");
test.assertEquals(usedSettings, {
method: "POST",
encoding: 'utf8',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
data: '{"plop":42,"chuck":"nórrïs","john":{"Doe":"ïs here™€"}}'
}, "Casper.open() used the expected POST settings");
});
casper.run(function() {
test.done();
});
}
});

@@ -21,3 +21,8 @@ /*eslint strict:0*/

this.setContent(utils.format('<img src="data:image/png;base64,%s">',
this.captureBase64('png')));
this.captureBase64('png',{
top: 0,
left: 0,
width: 800,
height: 600
})));
});

@@ -24,0 +29,0 @@

@@ -26,3 +26,3 @@ /*eslint strict:0, max-statements:0*/

test.assertEquals(stack.clean(page1), 1);
test.assertEquals(stack.clean(), 1);
test.assertEquals(stack[0], page2);

@@ -29,0 +29,0 @@ test.assertEquals(stack.list().length, 1);

/*eslint strict:0*/
casper.test.begin('Skip tests', 4, function(test) {
casper.test.begin('Skip tests after', 4, function(test) {
test.assert(true, 'First test executed');

@@ -9,3 +9,3 @@ test.assert(true, 'Second test executed');

casper.test.begin('Skip tests after', 4, function(test) {
casper.test.begin('Skip tests before', 4, function(test) {
test.skip(2, 'Two tests skipped');

@@ -12,0 +12,0 @@ test.assert(true, 'Third test executed');

/*eslint strict:0*/
var tester = require('tester');
var testpage = require('webpage').create();

@@ -9,3 +8,3 @@ casper.test.begin('XUnitReporter() initialization', 1, function suite(test) {

xunit.setResults(results);
test.assertTruthy(xunit.getSerializedXML());
test.assertTruthy(xunit.getSerializedXML(), "XML can be generated");
test.done();

@@ -16,2 +15,3 @@ });

var xunit = require('xunit').create();
var xmlDocument;
var results = new tester.TestSuiteResult();

@@ -29,14 +29,16 @@ var suite1 = new tester.TestCaseResult({

xunit.setResults(results);
casper.start().setContent(xunit.getSerializedXML());
test.assertEvalEquals(function() {
return __utils__.findAll('testsuite').length;
}, 2);
test.assertExists('testsuites[time]');
test.assertExists('testsuite[name="foo"][package="foo"]');
test.assertExists('testsuite[name="bar"][package="bar"]');
xmlDocument = xunit.getXML();
casper.start();
test.assertEquals(xmlDocument.querySelectorAll('testsuite').length, 2, "2 test suites exist");
test.assertTruthy(xmlDocument.querySelector('testsuites[time]'), "Element 'testsuites' has time attribute");
test.assertTruthy(xmlDocument.querySelector('testsuite[name="foo"][package="foo"]'), "Package foo exists");
test.assertTruthy(xmlDocument.querySelector('testsuite[name="bar"][package="bar"]'), "Package bar exists");
test.done();
});
casper.test.begin('XUnitReporter() can hold a suite with a succesful test', 1, function suite(test) {
casper.test.begin('XUnitReporter() can hold a suite with a successful test', 1, function suite(test) {
var xunit = require('xunit').create();
var xmlDocument;
var results = new tester.TestSuiteResult();

@@ -55,4 +57,6 @@ var suite1 = new tester.TestCaseResult({

xunit.setResults(results);
casper.start().setContent(xunit.getSerializedXML());
test.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="0"] testcase[name="footext"]');
xmlDocument = xunit.getXML();
casper.start();
test.assertTruthy(xmlDocument.querySelector('testsuite[name="foo"][package="foo"][tests="1"][failures="0"] testcase[name="footext"]'), "Successful test case exists");
test.done();

@@ -63,2 +67,3 @@ });

var xunit = require('xunit').create();
var xmlDocument;
var results = new tester.TestSuiteResult();

@@ -77,5 +82,9 @@ var suite1 = new tester.TestCaseResult({

xunit.setResults(results);
casper.start().setContent(xunit.getSerializedXML());
test.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="footext"] failure[type="footype"]');
test.assertEquals(casper.getElementInfo('failure[type="footype"]').text, 'footext');
xmlDocument = xunit.getXML();
casper.start();
test.assertTruthy(xmlDocument.querySelector('testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="footext"] failure[type="footype"]'), "Failure node exists");
test.assertEquals(xmlDocument.querySelector('failure[type="footype"]').textContent, 'footext');
test.done();

@@ -86,2 +95,3 @@ });

var xunit = require('xunit').create();
var xmlDocument;
var results = new tester.TestSuiteResult();

@@ -101,6 +111,59 @@ var suite1 = new tester.TestCaseResult({

xunit.setResults(results);
casper.start().setContent(xunit.getSerializedXML());
test.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="foo bar baz"] failure[type="footype"]');
test.assertEquals(casper.getElementInfo('failure[type="footype"]').text, 'footext');
xmlDocument = xunit.getXML();
casper.start();
test.assertTruthy(xmlDocument.querySelector('testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="foo bar baz"] failure[type="footype"]'), "Failure node exists");
test.assertEquals(xmlDocument.querySelector('failure[type="footype"]').textContent, 'footext');
test.done();
});
casper.test.begin('XUnitReporter() does not have default XML namespace', 1, function suite(test) {
var xunit = require('xunit').create();
var xmlDocument;
var results = new tester.TestSuiteResult();
var suite1 = new tester.TestCaseResult({
name: 'foo',
file: '/foo'
});
results.push(suite1);
xunit.setResults(results);
xmlDocument = xunit.getXML();
casper.start();
test.assertFalsy(xmlDocument.querySelector('testsuites[xmlns]'), "No default namespace");
test.done();
});
casper.test.begin('XUnitReporter() can handle markup in nodes', 4, function suite(test) {
var xunit = require('xunit').create();
var xmlDocument;
var results = new tester.TestSuiteResult();
var suite1 = new tester.TestCaseResult({
name: 'foo',
file: '/foo'
});
suite1.addFailure({
success: false,
type: "footype",
message: "<b>foo</b> <i>bar</i> and <a href=''>baz</a>",
file: "/foo",
name: "foo bar baz"
});
suite1.addError({
name: 'foo',
message: "<b>foo</b> <i>bar</i> and <a href=''>baz</a>"
});
suite1.addWarning("<b>some warning markup</b>");
results.push(suite1);
xunit.setResults(results);
xmlDocument = xunit.getXML();
casper.start();
test.assertTruthy(xmlDocument.querySelector('testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="foo bar baz"] failure[type="footype"]'), "Node exists");
test.assertEquals(xmlDocument.querySelector('failure[type="footype"]').textContent, "<b>foo</b> <i>bar</i> and <a href=''>baz</a>", "Handles markup in failure node");
test.assertEquals(xmlDocument.querySelector('error[type="foo"]').textContent, "<b>foo</b> <i>bar</i> and <a href=''>baz</a>", "Handles markup in error node");
test.assertEquals(xmlDocument.querySelector('system-out').textContent, "<b>some warning markup</b>", "Handles markup in error node")
test.done();
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc