lib/capybara/poltergeist/client/browser.coffee in poltergeist-1.1.2 vs lib/capybara/poltergeist/client/browser.coffee in poltergeist-1.2.0
- old
+ new
@@ -17,14 +17,14 @@
@page = new Poltergeist.WebPage
@page.setViewportSize(width: @width, height: @height)
@page.onLoadStarted = =>
- this.setState 'loading' if @state == 'clicked'
+ this.setState 'loading' if @state == 'mouse_event'
@page.onNavigationRequested = (url, navigation) =>
- this.setState 'loading' if @state == 'clicked' && navigation == 'FormSubmitted'
+ this.setState 'loading' if @state == 'mouse_event' && navigation == 'FormSubmitted'
@page.onLoadFinished = (status) =>
if @state == 'loading'
this.sendResponse(status: status, click: @last_click)
this.setState 'default'
@@ -96,19 +96,25 @@
this.sendResponse @page.content()
source: ->
this.sendResponse @page.source()
- find: (selector) ->
- this.sendResponse(page_id: @page_id, ids: @page.find(selector))
+ title: ->
+ this.sendResponse @page.title()
- find_within: (page_id, id, selector) ->
- this.sendResponse this.node(page_id, id).find(selector)
+ find: (method, selector) ->
+ this.sendResponse(page_id: @page_id, ids: @page.find(method, selector))
- text: (page_id, id) ->
- this.sendResponse this.node(page_id, id).text()
+ find_within: (page_id, id, method, selector) ->
+ this.sendResponse this.node(page_id, id).find(method, selector)
+ all_text: (page_id, id) ->
+ this.sendResponse this.node(page_id, id).allText()
+
+ visible_text: (page_id, id) ->
+ this.sendResponse this.node(page_id, id).visibleText()
+
attribute: (page_id, id, name) ->
this.sendResponse this.node(page_id, id).getAttribute(name)
value: (page_id, id) ->
this.sendResponse this.node(page_id, id).value()
@@ -136,27 +142,31 @@
this.sendResponse this.node(page_id, id).tagName()
visible: (page_id, id) ->
this.sendResponse this.node(page_id, id).isVisible()
+ disabled: (page_id, id) ->
+ this.sendResponse this.node(page_id, id).isDisabled()
+
evaluate: (script) ->
this.sendResponse @page.evaluate("function() { return #{script} }")
execute: (script) ->
@page.execute("function() { #{script} }")
this.sendResponse(true)
- push_frame: (name) ->
+ push_frame: (name, timeout = new Date().getTime() + 2000) ->
if @page.pushFrame(name)
if @page.currentUrl() == 'about:blank'
this.setState 'awaiting_frame_load'
else
this.sendResponse(true)
else
- # There's currently no PhantomJS callback available for frame creation,
- # so we have to poll
- setTimeout((=> this.push_frame(name)), 50)
+ if new Date().getTime() < timeout
+ setTimeout((=> this.push_frame(name, timeout)), 50)
+ else
+ @owner.sendError(new Poltergeist.FrameNotFound(name))
pop_frame: ->
this.sendResponse(@page.popFrame())
push_window: (name) ->
@@ -179,27 +189,33 @@
pop_window: ->
prev_page = @page_stack.pop()
@page = prev_page if prev_page
this.sendResponse(true)
- click: (page_id, id, event = 'click') ->
+ mouse_event: (page_id, id, name) ->
# Get the node before changing state, in case there is an exception
node = this.node(page_id, id)
- # If the click event triggers onNavigationRequested, we will transition to the 'loading'
+ # If the event triggers onNavigationRequested, we will transition to the 'loading'
# state and wait for onLoadFinished before sending a response.
- this.setState 'clicked'
+ this.setState 'mouse_event'
- @last_click = node.click(event)
+ @last_mouse_event = node.mouseEvent(name)
setTimeout =>
if @state != 'loading'
this.setState 'default'
- this.sendResponse(@last_click)
+ this.sendResponse(@last_mouse_event)
, 5
+ click: (page_id, id) ->
+ this.mouse_event page_id, id, 'click'
+
double_click: (page_id, id) ->
- this.click page_id, id, 'doubleclick'
+ this.mouse_event page_id, id, 'doubleclick'
+
+ hover: (page_id, id) ->
+ this.mouse_event page_id, id, 'mousemove'
click_coordinates: (x, y) ->
@page.sendEvent('click', x, y)
this.sendResponse({ click: { x: x, y: y } })