undefined method using Capybara drag_to method - capybara

I wish to use the capybara method drag_to in order to manually sort items on a page. Below is my code:
pos2 = find('#first_element')
target = find(#second_element)
pos2.drag_to(target)
However I get the error message:
undefined method `drag_to' for nil:NilClass (NoMethodError)
Am I invoking the method incorrectly? I am attempting to implement as defined here: http://rubydoc.info/gems/capybara/0.4.0/Capybara/Element#drag_to-instance_method
Please note I am able to use other capybara methods fill_in, visit etc without any problems...
Any help would be greatly appreciated!

#drag_to actually won't move sortable elements, since you're not moving it "to" anywhere as much as a set distance in a certain direction. Selenium implements #drag_by but it is not yet supported by Capybara.
See also:
https://github.com/jnicklas/capybara/issues/222
https://github.com/jnicklas/capybara/issues/119

Related

Accessing rails model through rails console

I was looking to test a method I had created in my "Herd" model. The methods called "safely_assign_herd_usages". I understand how to instantiate a herd e.g. H = Herd.last However, I'm struggling to gain access to the method to test the lines of code within it. Any pointers or help would be greatly appreciated. Thanks.
Use a debugger in the method you want to test.
debug is the standard option.
require 'debug'
def safely_assign_herd_usages
...
binding.break # will interrupt here
...
end
Then in your Rails console, trigger the method to get to the breakpoint:
$ Herd.first.safely_assign_herd_usages
Now the console will load up the method in question and give you an interactive console at that specific spot.

XPath count not converting to Ruby number

I'm trying to introduce XPath to my Ruby on Rails, Cucumber and Capybara setup for the first time. My code
row_count_on_page = page.find(:xpath, "count(//table[#id='foo']/tbody/tr)")
is resulting in error
undefined method `map' for 10.0:Float
Did you mean? tap (NoMethodError)
The actual XPath part of the code seems to be working correctly because there are exactly ten rows in the body of the table. I don't get how the code can't convert that 10.0 into a Ruby 10 though. What am I doing wrong?
You should do the count outside the method.
row_count_on_page.count
As you are currently using, after the second member of find is evaluated you will have something like:
row_count_on_page = page.find(:xpath, "10.0")
which is not a valid xpath.

Capybara + Sorcery helpers

I'm currently working on a project using Sorcery to authenticate users and I have some integration tests done with capybara. When I call current_user or logged_in? sorcery helpers I get this error:
ArgumentError Exception: wrong number of arguments calling `page` (0 for 1)
but when I call them in development mode, it doesn't happen.
After some research I found out that the problem comes from find_by_id method. So if I call Model.find_by_id(1), I get this error. I am very confused because I cannot understand why page method is called and where.
I fixed it by overriding the find_by_id method of my model, but I completely disagree doing this way, so...
Does anybody know what's going on?
Thank you in advance guys
I finally fixed it. The problem was that I included Capybara in my env.rb so my ActiveRecord class were inheriting Capybara methods and find_by_id method for finding elements in a webpage was run instead of ActiveRecord find_by_id.
After deleting "include Capybara" line everything works fine.

undefined method `response_body=' for #<Grape::API:0x007fd8c71f17b8>

I'm writing testing code for api created by grape in rails. There's an error: undefined method `response_body=' for #
does anyone knows the reason and how to fix this? I'll be very thankful for that.
It looks like your code is trying to set the value of response_body, which does not seem like what you want to do. The error is telling you that there is no setter for the attribute...

Strange undefined method `right_click' error

I use RoR with cucumber and capybara for tests.
I get strange error whent trying to make right click with capybara:
undefined method `right_click' for #<Capybara::Node::Element:0x0000000930c628> (NoMethodError)
But that class simply should have right_click method, see http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Element#right_click-instance_method
This is the source code
find('a', :text => #name).right_click
If I do some mistake, how to simulate right mouse click properly?
This method is in master only. Neither of released Capybara versions support it.

Resources