Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Update capybara dependency #416

Merged
merged 4 commits into from

3 participants

Pedro Carriço Carlos Antonio da Silva Dmitry Vorotilin
Pedro Carriço

Update to the latest capybara version.
Been using it in with a cucumber test suite and it works great.

Cheers

Carlos Antonio da Silva

It seems there are a couple issues with the specs that need to be addressed before bumping, other than that, I'll be happy to test poltergeist with capybara 2.2 :+1:

Pedro Carriço

@carlosantoniodasilva Agreed :+1:
Also added the go_back and go_forward methods in the poltergeist driver which make the capybara gem specs pass.

Cheers

Dmitry Vorotilin
Owner

I'm curios does it compatible with 2.1?

Pedro Carriço

go_back and go_forward were implemented in the last capybara version (2.2.0)

https://github.com/jnicklas/capybara/blob/master/History.md

Dmitry Vorotilin
Owner

We have to bump it to ~> 2.1 then

Dmitry Vorotilin
Owner

@pedrocarrico I mean if it's back compatible we'd bump it to ~> 2.1 rather then ~> 2.2.0

Dmitry Vorotilin
Owner

I've rerun build because of errors.

Pedro Carriço

@route Yes, It's backwards compatible.

Dmitry Vorotilin
Owner

I've fixed some tests in master, except warnings for new jruby, I'll rerun this build too

Dmitry Vorotilin
Owner

Please rebase against master, those failing tests also should be fixed and then we'll be ready ;)

Pedro Carriço

@route Rebased! Still there are two tests (from the capybara suite) that are failing related to editing contenteditable nodes.
I'm looking at it but when I set the node with the value it does not set it, is this something that PhantomJS must support or should poltergeist do it through Javascript?

Failing specs are:
rspec /Users/pecarrico/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/capybara-2.2.0/lib/capybara/spec/session/node_spec.rb:107 # Capybara::Session Poltergeist node #set should allow me to change the contents of a contenteditable element
rspec /Users/pecarrico/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/capybara-2.2.0/lib/capybara/spec/session/node_spec.rb:113 # Capybara::Session Poltergeist node #set should allow me to set the contents of a contenteditable element

Dmitry Vorotilin
Owner

I'll take a look

Pedro Carriço

@route I've managed to change it through javascript and the tests pass, but still I'm really not sure if it's the best way to do it.
Though I'm sure it may work for the majority of cases.
Want me to push it to the repo so you can review it?

Dmitry Vorotilin
Owner

@pedrocarrico Would be glad to do it, please go ahead

lib/capybara/poltergeist/driver.rb
@@ -262,5 +262,13 @@ def wait?
def invalid_element_errors
[Capybara::Poltergeist::ObsoleteNode, Capybara::Poltergeist::MouseEventFailed]
end
+
+ def go_back
+ browser.evaluate("history.go(-1)")
Dmitry Vorotilin Owner
route added a note

PhantomJS has own methods http://phantomjs.org/api/webpage/method/go-back.html let's use them in consistency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
poltergeist.gemspec
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 1.9.3'
- s.add_dependency 'capybara', '~> 2.1.0'
+ s.add_dependency 'capybara', '~> 2.2.0'
Dmitry Vorotilin Owner
route added a note

We support 2.2 as well as 2.1, it should be ~> 2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Pedro Carriço

@route Thanks! :+1:
Already rebased and tests are green.

lib/capybara/poltergeist/node.rb
@@ -69,6 +69,8 @@ def set(value)
end
elsif tag_name == 'textarea'
command :set, value.to_s
+ elsif self[:contenteditable] == 'true'
+ browser.evaluate("document.getElementById('#{self[:id]}').innerHTML = '#{value.to_s}'")
Dmitry Vorotilin Owner
route added a note

Let me think about it...

Sure, that's the part that I'm really not sure if it's the best way to do it.

Dmitry Vorotilin Owner
route added a note

Let's try to use send_keys(see the latest commit on master) in here with the same logic as jnicklas/capybara#911

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Dmitry Vorotilin
Owner

@pedrocarrico I don't see those errors that you was talking about by email, I just see that content isn't replaced by our method in one of the capybara tests

lib/capybara/poltergeist/node.rb
@@ -69,6 +69,14 @@ def set(value)
end
elsif tag_name == 'textarea'
command :set, value.to_s
+ elsif self[:contenteditable] == 'true'
+ script = <<-JS
+ var range = document.createRange();
+ range.selectNodeContents(document.getElementById('#{self[:id]}'));
+ window.getSelection().addRange(range);
Dmitry Vorotilin Owner
route added a note

I've added window.getSelection().deleteFromDocument(); after this line to clear the selection because send_keys uses mouse click to focus on an element so the selection will be missed and everything worked just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/capybara/poltergeist/node.rb
@@ -69,6 +69,14 @@ def set(value)
end
elsif tag_name == 'textarea'
command :set, value.to_s
+ elsif self[:contenteditable] == 'true'
+ script = <<-JS
+ var range = document.createRange();
+ range.selectNodeContents(document.getElementById('#{self[:id]}'));
Dmitry Vorotilin Owner
route added a note

I have my doubts about this self[:id] either what if an element doesn't have an id?

Dmitry Vorotilin Owner
route added a note

Ok, let's use

command :delete_text
send_keys(value.to_s)

and implement this method on agent.coffee where we can put all this js logic, also we have to remove the text before sending keys with deleteFromDocument

Sure! I'll update the pull request ASAP.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Pedro Carriço

@route All done, also added a changelog entry hope you don't mind.

Dmitry Vorotilin
Owner

Of course I don't mind, it's even requirement! Great work, thank you a lot!

Dmitry Vorotilin route merged commit 3a676d6 into from
Pedro Carriço

Thank you! :+1:

Dmitry Vorotilin
Owner

:heart:

Carlos Antonio da Silva

@route I'm going to test capybara 2.2 and poltergeist master here, but I was just wondering if you have any idea about a new release including this?

Dmitry Vorotilin
Owner

@carlosantoniodasilva Since the last release I've fixed the issue on jruby but looks like it came back on new jruby 1.7.8 and it's pretty annoying see the build https://travis-ci.org/jonleighton/poltergeist/jobs/14858232. It drives me crazy but I have to fix it somehow again and then I suppose we're ready... I would appreciate if you test poltergeist master :+1:

Carlos Antonio da Silva

@route I see, alright then, no hurries :). Just tested capybara 2.2 with poltergeist master, all :green_heart: here. Thanks!

Dmitry Vorotilin
Owner

Good to hear! Will release as soon as I can

Carlos Antonio da Silva

:+1: I'll let you know if we find anything, thanks again.

Dmitry Vorotilin
Owner

Just released 1.5.0, thanks guys.

Pedro Carriço

Great! :+1:

Carlos Antonio da Silva

Thanks @route. All green over here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 2, 2013
  1. Pedro Carriço

    Update capybara dependency

    pedrocarrico authored pedrocarrico committed
  2. Pedro Carriço

    Add go_back and go_forward implementation in poltergeist capybara driver

    pedrocarrico authored pedrocarrico committed
    Added in capybara 2.2.0
Commits on Dec 3, 2013
  1. Pedro Carriço
  2. Pedro Carriço

    Add CHANGELOG entry

    pedrocarrico authored
This page is out of date. Refresh to see the latest.
1  CHANGELOG.md
View
@@ -5,6 +5,7 @@
* Added ability to set paper_size via a driver setter (Philippe Lehoux)
* Can support Basic HTTP authentication
* Added basic implementation of `send_keys`
+* Added ability to go_back, go_forward, set the contents of a contenteditable element and Capybara 2.2 support (Pedro Carriço)
#### Bug fixes ####
* Use `Capybara::Helpers.normalize_whitespace` in filter_text to strip unicode
12 lib/capybara/poltergeist/browser.rb
View
@@ -66,6 +66,10 @@ def visible_text(page_id, id)
command 'visible_text', page_id, id
end
+ def delete_text(page_id, id)
+ command 'delete_text', page_id, id
+ end
+
def attribute(page_id, id, name)
command 'attribute', page_id, id, name.to_s
end
@@ -277,6 +281,14 @@ def command(name, *args)
raise
end
+ def go_back
+ command 'go_back'
+ end
+
+ def go_forward
+ command 'go_forward'
+ end
+
private
def log(message)
6 lib/capybara/poltergeist/client/agent.coffee
View
@@ -141,6 +141,12 @@ class PoltergeistAgent.Node
else
@element.innerText
+ deleteText: ->
+ range = document.createRange()
+ range.selectNodeContents(@element)
+ window.getSelection().addRange(range)
+ window.getSelection().deleteFromDocument()
+
getAttribute: (name) ->
if name == 'checked' || name == 'selected'
@element[name]
11 lib/capybara/poltergeist/client/browser.coffee
View
@@ -121,6 +121,9 @@ class Poltergeist.Browser
visible_text: (page_id, id) ->
this.sendResponse this.node(page_id, id).visibleText()
+ delete_text: (page_id, id) ->
+ this.sendResponse this.node(page_id, id).deleteText()
+
attribute: (page_id, id, name) ->
this.sendResponse this.node(page_id, id).getAttribute(name)
@@ -361,3 +364,11 @@ class Poltergeist.Browser
# This command is purely for testing error handling
browser_error: ->
throw new Error('zomg')
+
+ go_back: ->
+ this.page.goBack() if this.page.canGoBack
+ this.sendResponse(true)
+
+ go_forward: ->
+ this.page.goForward() if this.page.canGoForward
+ this.sendResponse(true)
8 lib/capybara/poltergeist/client/compiled/agent.js
View
@@ -233,6 +233,14 @@ PoltergeistAgent.Node = (function() {
}
};
+ Node.prototype.deleteText = function() {
+ var range;
+ range = document.createRange();
+ range.selectNodeContents(this.element);
+ window.getSelection().addRange(range);
+ return window.getSelection().deleteFromDocument();
+ };
+
Node.prototype.getAttribute = function(name) {
if (name === 'checked' || name === 'selected') {
return this.element[name];
18 lib/capybara/poltergeist/client/compiled/browser.js
View
@@ -153,6 +153,10 @@ Poltergeist.Browser = (function() {
return this.sendResponse(this.node(page_id, id).visibleText());
};
+ Browser.prototype.delete_text = function(page_id, id) {
+ return this.sendResponse(this.node(page_id, id).deleteText());
+ };
+
Browser.prototype.attribute = function(page_id, id, name) {
return this.sendResponse(this.node(page_id, id).getAttribute(name));
};
@@ -481,6 +485,20 @@ Poltergeist.Browser = (function() {
throw new Error('zomg');
};
+ Browser.prototype.go_back = function() {
+ if (this.page.canGoBack) {
+ this.page.goBack();
+ }
+ return this.sendResponse(true);
+ };
+
+ Browser.prototype.go_forward = function() {
+ if (this.page.canGoForward) {
+ this.page.goForward();
+ }
+ return this.sendResponse(true);
+ };
+
return Browser;
})();
2  lib/capybara/poltergeist/client/compiled/node.js
View
@@ -4,7 +4,7 @@ Poltergeist.Node = (function() {
var name, _fn, _i, _len, _ref,
_this = this;
- Node.DELEGATES = ['allText', 'visibleText', 'getAttribute', 'value', 'set', 'setAttribute', 'isObsolete', 'removeAttribute', 'isMultiple', 'select', 'tagName', 'find', 'isVisible', 'position', 'trigger', 'parentId', 'mouseEventTest', 'scrollIntoView', 'isDOMEqual', 'isDisabled'];
+ Node.DELEGATES = ['allText', 'visibleText', 'getAttribute', 'value', 'set', 'setAttribute', 'isObsolete', 'removeAttribute', 'isMultiple', 'select', 'tagName', 'find', 'isVisible', 'position', 'trigger', 'parentId', 'mouseEventTest', 'scrollIntoView', 'isDOMEqual', 'isDisabled', 'deleteText'];
function Node(page, id) {
this.page = page;
10 lib/capybara/poltergeist/client/compiled/web_page.js
View
@@ -6,7 +6,7 @@ Poltergeist.WebPage = (function() {
WebPage.CALLBACKS = ['onAlert', 'onConsoleMessage', 'onLoadFinished', 'onInitialized', 'onLoadStarted', 'onResourceRequested', 'onResourceReceived', 'onError', 'onNavigationRequested', 'onUrlChanged', 'onPageCreated'];
- WebPage.DELEGATES = ['open', 'sendEvent', 'uploadFile', 'release', 'render', 'renderBase64'];
+ WebPage.DELEGATES = ['open', 'sendEvent', 'uploadFile', 'release', 'render', 'renderBase64', 'goBack', 'goForward'];
WebPage.COMMANDS = ['currentUrl', 'find', 'nodeCall', 'documentSize', 'beforeUpload', 'afterUpload'];
@@ -391,6 +391,14 @@ Poltergeist.WebPage = (function() {
}
};
+ WebPage.prototype.canGoBack = function() {
+ return this["native"].canGoBack;
+ };
+
+ WebPage.prototype.canGoForward = function() {
+ return this["native"].canGoForward;
+ };
+
return WebPage;
}).call(this);
2  lib/capybara/poltergeist/client/node.coffee
View
@@ -4,7 +4,7 @@ class Poltergeist.Node
@DELEGATES = ['allText', 'visibleText', 'getAttribute', 'value', 'set', 'setAttribute', 'isObsolete',
'removeAttribute', 'isMultiple', 'select', 'tagName', 'find',
'isVisible', 'position', 'trigger', 'parentId', 'mouseEventTest',
- 'scrollIntoView', 'isDOMEqual', 'isDisabled']
+ 'scrollIntoView', 'isDOMEqual', 'isDisabled', 'deleteText']
constructor: (@page, @id) ->
8 lib/capybara/poltergeist/client/web_page.coffee
View
@@ -3,7 +3,7 @@ class Poltergeist.WebPage
'onLoadStarted', 'onResourceRequested', 'onResourceReceived',
'onError', 'onNavigationRequested', 'onUrlChanged', 'onPageCreated']
- @DELEGATES = ['open', 'sendEvent', 'uploadFile', 'release', 'render', 'renderBase64']
+ @DELEGATES = ['open', 'sendEvent', 'uploadFile', 'release', 'render', 'renderBase64', 'goBack', 'goForward']
@COMMANDS = ['currentUrl', 'find', 'nodeCall', 'documentSize', 'beforeUpload', 'afterUpload']
@@ -278,3 +278,9 @@ class Poltergeist.WebPage
throw new Poltergeist.BrowserError(result.error.message, result.error.stack)
else
result.value
+
+ canGoBack: ->
+ @native.canGoBack
+
+ canGoForward: ->
+ @native.canGoForward
8 lib/capybara/poltergeist/driver.rb
View
@@ -262,5 +262,13 @@ def wait?
def invalid_element_errors
[Capybara::Poltergeist::ObsoleteNode, Capybara::Poltergeist::MouseEventFailed]
end
+
+ def go_back
+ browser.go_back
+ end
+
+ def go_forward
+ browser.go_forward
+ end
end
end
3  lib/capybara/poltergeist/node.rb
View
@@ -69,6 +69,9 @@ def set(value)
end
elsif tag_name == 'textarea'
command :set, value.to_s
+ elsif self[:contenteditable] == 'true'
+ command :delete_text
+ send_keys(value.to_s)
end
end
2  poltergeist.gemspec
View
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 1.9.3'
- s.add_dependency 'capybara', '~> 2.1.0'
+ s.add_dependency 'capybara', '~> 2.1'
s.add_dependency 'websocket-driver', '>= 0.2.0'
s.add_dependency 'multi_json', '~> 1.0'
s.add_dependency 'cliver', '~> 0.3.1'
Something went wrong with that request. Please try again.