lib/capybara/poltergeist/client/browser.coffee in poltergeist-0.1.0 vs lib/capybara/poltergeist/client/browser.coffee in poltergeist-0.2.0

- old
+ new

@@ -74,11 +74,11 @@ evaluate: (script) -> @owner.sendResponse @page.evaluate("function() { return #{script} }") execute: (script) -> - @page.execute("function() { return #{script} }") + @page.execute("function() { #{script} }") @owner.sendResponse(true) push_frame: (id) -> @page.pushFrame(id) @owner.sendResponse(true) @@ -86,24 +86,28 @@ pop_frame: -> @page.popFrame() @owner.sendResponse(true) click: (id) -> + load_detected = false + # Detect if the click event triggers a page load. If it does, don't send # a response here, because the response will be sent once the page has loaded. - @page.onLoadStarted = => @awaiting_response = true + @page.onLoadStarted = => + @awaiting_response = true + load_detected = true @page.get(id).click() # Use a timeout in order to let the stack clear, so that the @page.onLoadStarted # callback can (possibly) fire, before we decide whether to send a response. setTimeout( => @page.onLoadStarted = null - @owner.sendResponse(true) unless @awaiting_response + @owner.sendResponse(true) unless load_detected , - 0 + 10 ) drag: (id, other_id) -> @page.get(id).dragTo(@page.get(other_id)) @owner.sendResponse(true) @@ -114,8 +118,27 @@ reset: -> this.resetPage() @owner.sendResponse(true) - render: (path) -> - @page.render(path) + render: (path, full) -> + dimensions = @page.validatedDimensions() + document = dimensions.document + viewport = dimensions.viewport + + if full + @page.setScrollPosition(left: 0, top: 0) + @page.setClipRect(left: 0, top: 0, width: document.width, height: document.height) + @page.render(path) + @page.setScrollPosition(left: dimensions.left, top: dimensions.top) + else + @page.setClipRect(left: 0, top: 0, width: viewport.width, height: viewport.height) + @page.render(path) + @owner.sendResponse(true) + + resize: (width, height) -> + @page.setViewportSize(width: width, height: height) + @owner.sendResponse(true) + + exit: -> + phantom.exit()