lib/capybara/poltergeist/client/compiled/agent.js in poltergeist-1.6.0 vs lib/capybara/poltergeist/client/compiled/agent.js in poltergeist-1.7.0

- old
+ new

@@ -42,11 +42,11 @@ } } }; PoltergeistAgent.prototype.currentUrl = function() { - return encodeURI(decodeURI(window.location.href)); + return window.location.href.replace(/\ /g, '%20'); }; PoltergeistAgent.prototype.find = function(method, selector, within) { var el, error, i, results, xpath, _i, _len, _results; if (within == null) { @@ -193,14 +193,19 @@ }; return obsolete(this.element); }; Node.prototype.changed = function() { - var event; + var element, event; event = document.createEvent('HTMLEvents'); event.initEvent('change', true, false); - return this.element.dispatchEvent(event); + if (this.element.nodeName === 'OPTION') { + element = this.element.parentNode; + } else { + element = this.element; + } + return element.dispatchEvent(event); }; Node.prototype.input = function() { var event; event = document.createEvent('HTMLEvents'); @@ -244,11 +249,11 @@ Node.prototype.visibleText = function() { if (this.isVisible()) { if (this.element.nodeName === "TEXTAREA") { return this.element.textContent; } else { - return this.element.innerText; + return this.element.innerText || this.element.textContent; } } }; Node.prototype.deleteText = function() { @@ -338,15 +343,19 @@ Node.prototype.removeAttribute = function(name) { return this.element.removeAttribute(name); }; Node.prototype.select = function(value) { - if (value === false && !this.element.parentNode.multiple) { + if (this.isDisabled()) { return false; + } else if (value === false && !this.element.parentNode.multiple) { + return false; } else { + this.trigger('focus', this.element.parentNode); this.element.selected = value; this.changed(); + this.trigger('blur', this.element.parentNode); return true; } }; Node.prototype.tagName = function() { @@ -368,10 +377,25 @@ Node.prototype.isDisabled = function() { return this.element.disabled || this.element.tagName === 'OPTION' && this.element.parentNode.disabled; }; + Node.prototype.path = function() { + var elements, selectors, + _this = this; + elements = this.parentIds().reverse().map(function(id) { + return _this.agent.get(id); + }); + elements.push(this); + selectors = elements.map(function(el) { + var prev_siblings; + prev_siblings = el.find('xpath', "./preceding-sibling::" + (el.tagName())); + return "" + (el.tagName()) + "[" + (prev_siblings.length + 1) + "]"; + }); + return "//" + selectors.join('/'); + }; + Node.prototype.containsSelection = function() { var selectedNode; selectedNode = document.getSelection().focusNode; if (!selectedNode) { return false; @@ -415,23 +439,26 @@ height: rect.height }; return pos; }; - Node.prototype.trigger = function(name) { + Node.prototype.trigger = function(name, element) { var event; + if (element == null) { + element = this.element; + } if (Node.EVENTS.MOUSE.indexOf(name) !== -1) { event = document.createEvent('MouseEvent'); event.initMouseEvent(name, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); } else if (Node.EVENTS.FOCUS.indexOf(name) !== -1) { event = this.obtainEvent(name); } else if (Node.EVENTS.FORM.indexOf(name) !== -1) { event = this.obtainEvent(name); } else { throw "Unknown event"; } - return this.element.dispatchEvent(event); + return element.dispatchEvent(event); }; Node.prototype.obtainEvent = function(name) { var event; event = document.createEvent('HTMLEvents'); @@ -527,13 +554,5 @@ window.__poltergeist = new PoltergeistAgent; document.addEventListener('DOMContentLoaded', function() { return console.log('__DOMContentLoaded'); }); - -window.confirm = function(message) { - return true; -}; - -window.prompt = function(message, _default) { - return _default || null; -};