lib/capybara/poltergeist/client/browser.coffee in poltergeist-1.14.0 vs lib/capybara/poltergeist/client/browser.coffee in poltergeist-1.15.0

- old
+ new

@@ -115,10 +115,12 @@ command.sendResponse(status: @status) , max_wait, -> resources = @openResourceRequests() msg = if resources.length "Timed out with the following resources still waiting #{resources.join(',')}" + else + "Timed out with no open resource requests" command.sendError(new Poltergeist.StatusFailError(url,msg)) return current_url: -> @current_command.sendResponse @currentPage.currentUrl() @@ -354,23 +356,28 @@ @_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 + if sequence.key? + if !(key=@currentPage.keyCode(sequence.key)) + @current_command.sendError(new Poltergeist.KeyError("Unknown key: #{sequence.key}")) + return + else if sequence.keys? + key=sequence.keys else - sequence + key=sequence if sequence.modifier? modifier_keys = @currentPage.keyModifierKeys(sequence.modifier) modifier_code = @currentPage.keyModifierCode(sequence.modifier) | current_modifier_code @currentPage.sendEvent('keydown', modifier_key) for modifier_key in modifier_keys @_send_keys_with_modifiers([].concat(key), modifier_code) @currentPage.sendEvent('keyup', modifier_key) for modifier_key in modifier_keys else @currentPage.sendEvent('keypress', key, null, null, current_modifier_code) + return 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) @@ -496,28 +503,24 @@ # This command is purely for testing error handling browser_error: -> throw new Error('zomg') go_back: -> - command = @current_command if @currentPage.canGoBack - @currentPage.state = 'loading' + @currentPage.state = 'wait_for_loading' @currentPage.goBack() - @currentPage.waitState 'default', -> - command.sendResponse(true) + @_waitForHistoryChange() else - command.sendResponse(false) + @current_command.sendResponse(false) go_forward: -> - command = @current_command if @currentPage.canGoForward - @currentPage.state = 'loading' + @currentPage.state = 'wait_for_loading' @currentPage.goForward() - @currentPage.waitState 'default', -> - command.sendResponse(true) + @_waitForHistoryChange() else - command.sendResponse(false) + @current_command.sendResponse(false) set_url_whitelist: (wildcards...)-> @currentPage.urlWhitelist = (@_wildcardToRegexp(wc) for wc in wildcards) @current_command.sendResponse(true) @@ -537,9 +540,24 @@ @current_command.sendResponse(@processed_modal_messages.shift()) clear_memory_cache: -> @currentPage.clearMemoryCache() @current_command.sendResponse(true) + + _waitForHistoryChange: -> + command = @current_command + @currentPage.waitState ['loading','default'], (cur_state) -> + if cur_state == 'loading' + # loading has started, wait for completion + @waitState 'default', -> + command.sendResponse(true) + else + # page has loaded + command.sendResponse(true) + , 0.5, -> + # if haven't moved to loading/default in time assume history API state change + @state = 'default' + command.sendResponse(true) _wildcardToRegexp: (wildcard)-> wildcard = wildcard.replace(/[\-\[\]\/\{\}\(\)\+\.\\\^\$\|]/g, "\\$&") wildcard = wildcard.replace(/\*/g, ".*") wildcard = wildcard.replace(/\?/g, ".")