lib/capybara/poltergeist/client/agent.coffee in poltergeist-1.6.0 vs lib/capybara/poltergeist/client/agent.coffee in poltergeist-1.7.0
- old
+ new
@@ -22,12 +22,15 @@
if error instanceof TypeError
'"(cyclic structure)"'
else
throw error
+ # Somehow PhantomJS returns all characters(brackets, etc) properly encoded
+ # except whitespace character in pathname part of the location. This hack
+ # is intended to fix this up.
currentUrl: ->
- encodeURI(decodeURI(window.location.href))
+ window.location.href.replace(/\ /g, '%20')
find: (method, selector, within = document) ->
try
if method == "xpath"
xpath = document.evaluate(selector, within, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
@@ -110,12 +113,20 @@
obsolete @element
changed: ->
event = document.createEvent('HTMLEvents')
event.initEvent('change', true, false)
- @element.dispatchEvent(event)
+ # In the case of an OPTION tag, the change event should come
+ # from the parent SELECT
+ if @element.nodeName == 'OPTION'
+ element = @element.parentNode
+ else
+ element = @element
+
+ element.dispatchEvent(event)
+
input: ->
event = document.createEvent('HTMLEvents')
event.initEvent('input', true, false)
@element.dispatchEvent(event)
@@ -150,11 +161,11 @@
visibleText: ->
if this.isVisible()
if @element.nodeName == "TEXTAREA"
@element.textContent
else
- @element.innerText
+ @element.innerText || @element.textContent
deleteText: ->
range = document.createRange()
range.selectNodeContents(@element)
window.getSelection().removeAllRanges()
@@ -214,15 +225,21 @@
removeAttribute: (name) ->
@element.removeAttribute(name)
select: (value) ->
- if value == false && !@element.parentNode.multiple
+ if @isDisabled()
false
+ else if value == false && !@element.parentNode.multiple
+ false
else
+ this.trigger('focus', @element.parentNode)
+
@element.selected = value
this.changed()
+
+ this.trigger('blur', @element.parentNode)
true
tagName: ->
@element.tagName
@@ -237,10 +254,18 @@
true
isDisabled: ->
@element.disabled || @element.tagName == 'OPTION' && @element.parentNode.disabled
+ path: ->
+ elements = @parentIds().reverse().map((id) => @agent.get(id))
+ elements.push(this)
+ selectors = elements.map (el)->
+ prev_siblings = el.find('xpath', "./preceding-sibling::#{el.tagName()}")
+ "#{el.tagName()}[#{prev_siblings.length + 1}]"
+ "//" + selectors.join('/')
+
containsSelection: ->
selectedNode = document.getSelection().focusNode
return false if !selectedNode
@@ -255,11 +280,11 @@
while win.frameElement
rect = win.frameElement.getClientRects()[0]
style = win.getComputedStyle(win.frameElement)
win = win.parent
-
+
offset.top += rect.top + parseInt(style.getPropertyValue("padding-top"), 10)
offset.left += rect.left + parseInt(style.getPropertyValue("padding-left"), 10)
offset
@@ -277,11 +302,11 @@
height: rect.height
}
pos
- trigger: (name) ->
+ trigger: (name, element = @element) ->
if Node.EVENTS.MOUSE.indexOf(name) != -1
event = document.createEvent('MouseEvent')
event.initMouseEvent(
name, true, true, window, 0, 0, 0, 0, 0,
false, false, false, false, 0, null
@@ -291,11 +316,11 @@
else if Node.EVENTS.FORM.indexOf(name) != -1
event = this.obtainEvent(name)
else
throw "Unknown event"
- @element.dispatchEvent(event)
+ element.dispatchEvent(event)
obtainEvent: (name) ->
event = document.createEvent('HTMLEvents')
event.initEvent(name, true, true)
event
@@ -370,8 +395,5 @@
document.addEventListener(
'DOMContentLoaded',
-> console.log('__DOMContentLoaded')
)
-
-window.confirm = (message) -> true
-window.prompt = (message, _default) -> _default or null