lib/capybara/poltergeist/client/compiled/agent.js in poltergeist-0.4.0 vs lib/capybara/poltergeist/client/compiled/agent.js in poltergeist-0.5.0

- old
+ new

@@ -5,33 +5,48 @@ this.elements = []; this.nodes = {}; this.windows = []; this.pushWindow(window); } + PoltergeistAgent.prototype.externalCall = function(name, arguments) { + try { + return { + value: this[name].apply(this, arguments) + }; + } catch (error) { + return { + error: error.toString() + }; + } + }; PoltergeistAgent.prototype.pushWindow = function(new_window) { this.windows.push(new_window); this.window = new_window; - return this.document = this.window.document; + this.document = this.window.document; + return null; }; PoltergeistAgent.prototype.popWindow = function() { this.windows.pop(); this.window = this.windows[this.windows.length - 1]; - return this.document = this.window.document; + this.document = this.window.document; + return null; }; PoltergeistAgent.prototype.pushFrame = function(id) { return this.pushWindow(this.document.getElementById(id).contentWindow); }; PoltergeistAgent.prototype.popFrame = function() { return this.popWindow(); }; PoltergeistAgent.prototype.currentUrl = function() { return window.location.toString(); }; - PoltergeistAgent.prototype.find = function(selector, id) { - var context, i, ids, results, _ref; - context = id != null ? this.elements[id] : this.document; - results = this.document.evaluate(selector, context, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); + PoltergeistAgent.prototype.find = function(selector, within) { + var i, ids, results, _ref; + if (within == null) { + within = this.document; + } + results = this.document.evaluate(selector, within, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); ids = []; for (i = 0, _ref = results.snapshotLength; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) { ids.push(this.register(results.snapshotItem(i))); } return ids; @@ -51,14 +66,24 @@ return (_base = this.nodes)[id] || (_base[id] = new PoltergeistAgent.Node(this, this.elements[id])); }; PoltergeistAgent.prototype.nodeCall = function(id, name, arguments) { var node; node = this.get(id); + if (node.isObsolete()) { + throw new PoltergeistAgent.ObsoleteNode; + } return node[name].apply(node, arguments); }; return PoltergeistAgent; })(); +PoltergeistAgent.ObsoleteNode = (function() { + function ObsoleteNode() {} + ObsoleteNode.prototype.toString = function() { + return "PoltergeistAgent.ObsoleteNode"; + }; + return ObsoleteNode; +})(); PoltergeistAgent.Node = (function() { Node.EVENTS = { FOCUS: ['blur', 'focus', 'focusin', 'focusout'], MOUSE: ['click', 'dblclick', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'mouseover', 'mouseout', 'mouseup'] }; @@ -67,10 +92,13 @@ this.element = element; } Node.prototype.parentId = function() { return this.agent.register(this.element.parentNode); }; + Node.prototype.find = function(selector) { + return this.agent.find(selector, this.element); + }; Node.prototype.isObsolete = function() { var obsolete; obsolete = __bind(function(element) { if (element.parentNode != null) { if (element.parentNode === this.agent.document) { @@ -176,14 +204,18 @@ return true; } }; Node.prototype.position = function() { var rect; - rect = this.element.getBoundingClientRect(); + rect = this.element.getClientRects()[0]; return { top: rect.top, - left: rect.left + right: rect.right, + left: rect.left, + bottom: rect.bottom, + width: rect.width, + height: rect.height }; }; Node.prototype.trigger = function(name) { var event; if (Node.EVENTS.MOUSE.indexOf(name) !== -1) { @@ -194,9 +226,40 @@ event.initEvent(name, true, true); } else { throw "Unknown event"; } return this.element.dispatchEvent(event); + }; + Node.prototype.clickTest = function(x, y) { + var el, origEl; + el = origEl = document.elementFromPoint(x, y); + while (el) { + if (el === this.element) { + return { + status: 'success' + }; + } else { + el = el.parentNode; + } + } + return { + status: 'failure', + selector: origEl && this.getSelector(origEl) + }; + }; + Node.prototype.getSelector = function(el) { + var className, selector, _i, _len, _ref; + selector = el.tagName !== 'HTML' ? this.getSelector(el.parentNode) + ' ' : ''; + selector += el.tagName.toLowerCase(); + if (el.id) { + selector += "#" + el.id; + } + _ref = el.classList; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + className = _ref[_i]; + selector += "." + className; + } + return selector; }; return Node; })(); window.__poltergeist = new PoltergeistAgent; document.addEventListener('DOMContentLoaded', function() { \ No newline at end of file