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

- old
+ new

@@ -1,10 +1,11 @@ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; Poltergeist.Browser = (function() { function Browser(owner) { this.owner = owner; this.state = 'default'; + this.page_id = 0; this.resetPage(); } Browser.prototype.resetPage = function() { if (this.page != null) { this.page.release(); @@ -13,106 +14,132 @@ this.page.onLoadStarted = __bind(function() { if (this.state === 'clicked') { return this.state = 'loading'; } }, this); - return this.page.onLoadFinished = __bind(function(status) { + this.page.onLoadFinished = __bind(function(status) { if (this.state === 'loading') { - this.owner.sendResponse(status); + this.sendResponse(status); return this.state = 'default'; } }, this); + return this.page.onInitialized = __bind(function() { + return this.page_id += 1; + }, this); }; + Browser.prototype.sendResponse = function(response) { + var errors; + errors = this.page.errors(); + if (errors.length > 0) { + this.page.clearErrors(); + return this.owner.sendError(new Poltergeist.JavascriptError(errors)); + } else { + return this.owner.sendResponse(response); + } + }; + Browser.prototype.node = function(page_id, id) { + if (page_id === this.page_id) { + return this.page.get(id); + } else { + throw new Poltergeist.ObsoleteNode; + } + }; Browser.prototype.visit = function(url) { this.state = 'loading'; return this.page.open(url); }; Browser.prototype.current_url = function() { - return this.owner.sendResponse(this.page.currentUrl()); + return this.sendResponse(this.page.currentUrl()); }; Browser.prototype.body = function() { - return this.owner.sendResponse(this.page.content()); + return this.sendResponse(this.page.content()); }; Browser.prototype.source = function() { - return this.owner.sendResponse(this.page.source()); + return this.sendResponse(this.page.source()); }; - Browser.prototype.find = function(selector, id) { - return this.owner.sendResponse(this.page.find(selector, id)); + Browser.prototype.find = function(selector) { + return this.sendResponse({ + page_id: this.page_id, + ids: this.page.find(selector) + }); }; - Browser.prototype.text = function(id) { - return this.owner.sendResponse(this.page.get(id).text()); + Browser.prototype.find_within = function(page_id, id, selector) { + return this.sendResponse(this.node(page_id, id).find(selector)); }; - Browser.prototype.attribute = function(id, name) { - return this.owner.sendResponse(this.page.get(id).getAttribute(name)); + Browser.prototype.text = function(page_id, id) { + return this.sendResponse(this.node(page_id, id).text()); }; - Browser.prototype.value = function(id) { - return this.owner.sendResponse(this.page.get(id).value()); + Browser.prototype.attribute = function(page_id, id, name) { + return this.sendResponse(this.node(page_id, id).getAttribute(name)); }; - Browser.prototype.set = function(id, value) { - this.page.get(id).set(value); - return this.owner.sendResponse(true); + Browser.prototype.value = function(page_id, id) { + return this.sendResponse(this.node(page_id, id).value()); }; - Browser.prototype.select_file = function(id, value) { + Browser.prototype.set = function(page_id, id, value) { + this.node(page_id, id).set(value); + return this.sendResponse(true); + }; + Browser.prototype.select_file = function(page_id, id, value) { var element, multiple; - element = this.page.get(id); + element = this.node(page_id, id); multiple = element.isMultiple(); if (multiple) { element.removeAttribute('multiple'); } element.setAttribute('_poltergeist_selected', ''); this.page.uploadFile('[_poltergeist_selected]', value); element.removeAttribute('_poltergeist_selected'); if (multiple) { element.setAttribute('multiple', 'multiple'); } - return this.owner.sendResponse(true); + return this.sendResponse(true); }; - Browser.prototype.select = function(id, value) { - return this.owner.sendResponse(this.page.get(id).select(value)); + Browser.prototype.select = function(page_id, id, value) { + return this.sendResponse(this.node(page_id, id).select(value)); }; - Browser.prototype.tag_name = function(id) { - return this.owner.sendResponse(this.page.get(id).tagName()); + Browser.prototype.tag_name = function(page_id, id) { + return this.sendResponse(this.node(page_id, id).tagName()); }; - Browser.prototype.visible = function(id) { - return this.owner.sendResponse(this.page.get(id).isVisible()); + Browser.prototype.visible = function(page_id, id) { + return this.sendResponse(this.node(page_id, id).isVisible()); }; Browser.prototype.evaluate = function(script) { - return this.owner.sendResponse(JSON.parse(this.page.evaluate("function() { return JSON.stringify(" + script + ") }"))); + return this.sendResponse(JSON.parse(this.page.evaluate("function() { return JSON.stringify(" + script + ") }"))); }; Browser.prototype.execute = function(script) { this.page.execute("function() { " + script + " }"); - return this.owner.sendResponse(true); + return this.sendResponse(true); }; Browser.prototype.push_frame = function(id) { this.page.pushFrame(id); - return this.owner.sendResponse(true); + return this.sendResponse(true); }; Browser.prototype.pop_frame = function() { this.page.popFrame(); - return this.owner.sendResponse(true); + return this.sendResponse(true); }; - Browser.prototype.click = function(id) { + Browser.prototype.click = function(page_id, id) { this.state = 'clicked'; - this.page.get(id).click(); + this.node(page_id, id).click(); return setTimeout(__bind(function() { if (this.state === 'clicked') { this.state = 'default'; - return this.owner.sendResponse(true); + return this.sendResponse(true); } }, this), 10); }; - Browser.prototype.drag = function(id, other_id) { - this.page.get(id).dragTo(this.page.get(other_id)); - return this.owner.sendResponse(true); + Browser.prototype.drag = function(page_id, id, other_id) { + this.node(page_id, id).dragTo(this.page.get(other_id)); + return this.sendResponse(true); }; - Browser.prototype.trigger = function(id, event) { - this.page.get(id).trigger(event); - return this.owner.sendResponse(event); + Browser.prototype.trigger = function(page_id, id, event) { + this.node(page_id, id).trigger(event); + return this.sendResponse(event); }; Browser.prototype.reset = function() { this.resetPage(); - return this.owner.sendResponse(true); + return this.sendResponse(true); }; Browser.prototype.render = function(path, full) { var dimensions, document, viewport; dimensions = this.page.validatedDimensions(); document = dimensions.document; @@ -140,17 +167,17 @@ width: viewport.width, height: viewport.height }); this.page.render(path); } - return this.owner.sendResponse(true); + return this.sendResponse(true); }; Browser.prototype.resize = function(width, height) { this.page.setViewportSize({ width: width, height: height }); - return this.owner.sendResponse(true); + return this.sendResponse(true); }; Browser.prototype.exit = function() { return phantom.exit(); }; Browser.prototype.noop = function() {}; \ No newline at end of file