lib/capybara/poltergeist/client/browser.coffee in poltergeist-1.16.0 vs lib/capybara/poltergeist/client/browser.coffee in poltergeist-1.17.0

- old
+ new

@@ -29,35 +29,40 @@ @processed_modal_messages = [] @confirm_processes = [] @prompt_responses = [] + @setupPageHandlers(@page) - @page.native().onAlert = (msg) => + return + + setupPageHandlers: (page) -> + page.native().onAlert = (msg) => @setModalMessage msg return - @page.native().onConfirm = (msg) => + page.native().onConfirm = (msg) => process = @confirm_processes.pop() process = true if process == undefined @setModalMessage msg return process - @page.native().onPrompt = (msg, defaultVal) => + page.native().onPrompt = (msg, defaultVal) => response = @prompt_responses.pop() response = defaultVal if (response == undefined || response == false) @setModalMessage msg return response - @page.onPageCreated = (newPage) => - page = new Poltergeist.WebPage(newPage) - page.handle = "#{@_counter++}" - page.urlBlacklist = @page.urlBlacklist - page.urlWhitelist = @page.urlWhitelist - page.setViewportSize(@page.viewportSize()) - @pages.push(page) + page.onPageCreated = (newPage) => + _page = new Poltergeist.WebPage(newPage) + _page.handle = "#{@_counter++}" + _page.urlBlacklist = page.urlBlacklist + _page.urlWhitelist = page.urlWhitelist + _page.setViewportSize(page.viewportSize()) + @setupPageHandlers(_page) + @pages.push(_page) return getPageByHandle: (handle) -> @pages.filter((p) -> !p.closed && p.handle == handle)[0] @@ -205,9 +210,21 @@ 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...) + + evaluate_async: (script, max_wait, args...) -> + for arg in args when @_isElementArgument(arg) + throw new Poltergeist.ObsoleteNode if arg["ELEMENT"]["page_id"] != @currentPage.id + command = @current_command + cb = (result)=> + command.sendResponse(result) + @currentPage.evaluate_async("function() { #{script} }", cb, args...) + setTimeout(=> + command.sendError(new Poltergeist.ScriptTimeoutError) + , max_wait*1000) + 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...)