lib/capybara/poltergeist/client/browser.coffee in poltergeist-1.12.0 vs lib/capybara/poltergeist/client/browser.coffee in poltergeist-1.13.0

- old
+ new

@@ -197,15 +197,19 @@ @current_command.sendResponse this.node(page_id, id).isDisabled() path: (page_id, id) -> @current_command.sendResponse this.node(page_id, id).path() - evaluate: (script) -> - @current_command.sendResponse @currentPage.evaluate("function() { return #{script} }") + evaluate: (script, args...) -> + for arg in args when @_isElementArgument(arg) + throw new Poltergeist.ObsoleteNode if arg["ELEMENT"]["page_id"] != @currentPage.id + @current_command.sendResponse @currentPage.evaluate("function() { return #{script} }", args...) - execute: (script) -> - @currentPage.execute("function() { #{script} }") + execute: (script, args...) -> + for arg in args when @_isElementArgument(arg) + throw new Poltergeist.ObsoleteNode if arg["ELEMENT"]["page_id"] != @currentPage.id + @currentPage.execute("function() { #{script} }", args...) @current_command.sendResponse(true) frameUrl: (frame_name) -> @currentPage.frameUrl(frame_name) @@ -343,26 +347,29 @@ # Programmatically generated focus doesn't work for `sendKeys`. # That's why we need something more realistic like user behavior. if !target.containsSelection() target.mouseEvent('click') + @_send_keys_with_modifiers(keys) + @current_command.sendResponse(true) + + _send_keys_with_modifiers: (keys, current_modifier_code = 0) -> for sequence in keys key = if sequence.key? @currentPage.keyCode(sequence.key) || sequence.key else sequence + if sequence.modifier? modifier_keys = @currentPage.keyModifierKeys(sequence.modifier) - modifier_code = @currentPage.keyModifierCode(sequence.modifier) + modifier_code = @currentPage.keyModifierCode(sequence.modifier) | current_modifier_code @currentPage.sendEvent('keydown', modifier_key) for modifier_key in modifier_keys - @currentPage.sendEvent('keypress', key, null, null, modifier_code) + @_send_keys_with_modifiers([].concat(key), modifier_code) @currentPage.sendEvent('keyup', modifier_key) for modifier_key in modifier_keys else - @currentPage.sendEvent('keypress', key) + @currentPage.sendEvent('keypress', key, null, null, current_modifier_code) - @current_command.sendResponse(true) - render_base64: (format, { full = false, selector = null } = {})-> window_scroll_position = @currentPage.native().evaluate("function(){ return [window.pageXOffset, window.pageYOffset] }") dimensions = this.set_clip_rect(full, selector) encoded_image = @currentPage.renderBase64(format) @currentPage.setScrollPosition(left: dimensions.left, top: dimensions.top) @@ -533,5 +540,7 @@ wildcard = wildcard.replace(/[\-\[\]\/\{\}\(\)\+\.\\\^\$\|]/g, "\\$&") wildcard = wildcard.replace(/\*/g, ".*") wildcard = wildcard.replace(/\?/g, ".") new RegExp(wildcard, "i") + _isElementArgument: (arg)-> + typeof(arg) == "object" and typeof(arg['ELEMENT']) == "object"