How do I use ruby-debug in Capybara w/ selenium - ruby-on-rails

We have Capybara working with the selenium driver but when I try to use 'debugger' inside a step it doesn't quite work.
e.g. in the debug console entering 'page' works but entering 'page.body' hangs.
We also had weirdness when trying to use debugger with the akephalos driver. With akephalos we couldn't type in the debug prompt... well actually we could but you had to hit the key several times before a letter would randomly show up in the terminal. Doing a 'Ctrl-C' let us type but we got errors like 'DRb connection ...something' (sorry don't have the exact error anymore).
I think the problem is that drivers like selenium and akephalos run the tests and a server in the same process and it confuses ruby-debug. I'm going to try running the server separately (script/server test) and use Capybara.app_host = 'http://localhost:3000' to see if that will make a difference. I tried that with akephalos but didn't get anywhere since it just launched another in-process server anyway.
Is there anyone out there using ruby-debug with Capybara and selenium? Is this working for anyone else? Am I missing something obvious?

Setting Capybara.app_host = 'http://localhost:3000' and running script/server -e test in another process worked.

I don't have a real answer myself, but your question reminded me of this post:
Selenium doesn't work with Cucumber/Capybara (out of the box) - MacOSX
Where the questioner shows how he used ruby-debug to figure out why a missing dependency was helping selenium fail to open the browser.
Hope this helps!

I found this works (in the cucumber env.rb file)
Capybara.default_wait_time = 2000 #default: 2

Related

Getting Capybara::DriverNotFoundError when trying to run Cucumber tests

I'm getting this error when I run the cucumber tests. Everything seemed to be working fine the previous day but I can't figure out why it stopped working. I was trying to get capybara webkit working and I had changed a couple of files but I don't see why it should affect my tests. Any idea on how to fix this error I'm getting while running the cucumber tests?
Capybara::DriverNotFoundError: no driver called :rack was found, available drivers: :rack_test, :selenium, :webkit, :webkit_debug
You mentioned that you edited many files. Could it be that you didn't revert all the changes you made? I think Capybara would pick the 'rack_test' driver by default, and your system could not find the 'rack' driver.
Since you're doing Cucumber testing, you must have a file called 'env.rb' under the features/support folder. Make sure you don't force 'rack' as your Capybara driver, and your tests should run fine.

Debug using Rubymine

I work on RoR application. I would like to debug my app using Rubymine debugger. But I have to run my app on specific port on server. So my question Is. Should I change default port in Rubymine configuration on which webrick run? If so how? Or run app by rubymine? I don't know that are "correct" questions (correct I mean not stupid;)) But I'm fresh in Ruby technologies. Thanks for all answers.
Edit:
dax thank you for your answer I have changed port. Now serwer run but I have in rubymine console information that:
Fast Debugger (ruby-debug-ide 0.4.22, ruby-debug-base19x 0.11.30.pre15) listens on 127.0.0.1:43588
I should change fast debugger port to make it work. Am I right? But I don't have idea how to change it.
Edit:
After a while I get something like this:
30381: Exception in DebugThread loop: wrong number of arguments (0 for 1)
Backtrace:
/home/arkency/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/gems/1.9.1/gems/debugger-1.6.2/lib/ruby-debug/interface.rb:175:in `read_command'
from: /home/arkency/.gem/ruby/1.9.1/gems/ruby-debug-ide-0.4.22/lib/ruby-debug-ide/ide_processor.rb:84:in `process_commands'
from: /home/arkency/.gem/ruby/1.9.1/gems/ruby-debug-ide-0.4.22/lib/ruby-debug-ide.rb:122:in `block in start_control'
[2014-04-13 15:18:08] ERROR SystemExit: exit
/home/arkency/.gem/ruby/1.9.1/gems/ruby-debug-ide-0.4.22/lib/ruby-debug-ide.rb:126:in `exit'
Edit:
I removed debugger gem and now all works fine. Thanks for all replies;)
From my comment: RubyMine doesn't work with debugger gem, so you have to remove it from Gemfile.
You can access/change your server port settings in the edit configurations menu.
see this question for more details

Rspec hangs after it finishes running through my tests

Has anyone seen this problem before? Sometimes when running specs for my Rails 3.2.14 project rspec seems to finish as usual:
Finished in 1.27 seconds
6 examples, 2 failures
Failed examples:
rspec ./spec/models/my_spec.rb:123 # Hello world 1
rspec ./spec/models/my_spec.rb:234 # Hello world 2
but then it just hangs there and won't let me continue working in that shell. I can kill -9 the process from another terminal tab, or just start a new shell and run the tests again there, but it makes test driven development a huge pain.
When I restart my computer, the problem goes away for a while, but it always happens again eventually. After it hangs once, it keeps hanging every time I run rspec, even if I run different tests in a different project. The same tests in the same projects pass just fine on my coworkers' computers every time.
I'm not sure what information would help to answer this question so let me know if there is something I should add to this post. I'm running ruby 2.0.0p195 and rails 3.2.14. I've got Mac OS 10.7.5. I use zsh and rbenv.
Thanks for reading!
I had the same issue and solved it by adding the following to my spec_helper.rb:
SimpleCov.start do
use_merging false
end
Note that I'm running on a virtual box vm with a synched directory.
Here's the explanation I found as to why this works:
"When simplecov exists, by default it will try to merge the recorded coverage with what's on disk. To avoid corruption it uses a lock file to guard this merge. Because my virtual box shared fs is not actually posix compliant, the lock file would never acquire, and silently block forever here.
Since I don't care about merging coverage results, the solution for me was to simply disable this behavior with the use_merging flag."
https://gist.github.com/k-yamada/3930916
Ok, figured it out with a friend's help. All it took was removing SimpleCov from my spec_helper. Not sure why SimpleCov was causing the issue, but I'll post an update here if I find out.

watir-webdriver phantomjs and ghostdriver

I currently have a rails app that uses rspec and watir-webdriver for my integration tests. I want to run my integration tests in a headless browser (for speed purposes). Since my development is done on a mac the headless gem won't work for me. I am looking to phantomjs as the solution. Whereas phantomjs works well with rspec/capybara (via poltergeist) and there are plenty of examples on how to make that work, I can't find much in the way of getting it to work well with watir-webdriver and ghostdriver.
I have built the "special" phantomjs that ghostdriver requires but I am lost after that. Has anyone used this setup before (rails/watir-webdriver/ghostdriver)?
My main goal is to speed up my integration tests. So if anyone has a better suggestion than what I have described here, I am flexible :)
Any help is greatly appreciated!
It is now fully supported by Watir-WebDriver and easy to get running:
Steps to get working on OSX
First make sure you have homebrew installed
brew update
brew install phantomjs
Run irb and start using GhostDriver!
require 'watir-webdriver'
b = Watir::Browser.new :phantomjs
b.goto "www.google.com"
b.url #"http://www.google.com.au/"
b.title #"Google"
See full details on this blog post: http://watirmelon.com/2013/02/05/watir-webdriver-with-ghostdriver-on-osx-headless-browser-testing/

Rails testing with Selenium and everybody has a wrong password

I have an application with a bunch of cucumber tests, and I tried using selenium with it today. It took a bit, but I got it running, it starts up selenium, uses the correct database and everything, but everybody has a wrong password.
I can see the user getting created, I can log the password and see that it's the correct password, but every test user just gets redirected back to the login page with the incorrect username/password error.
Is this a Selenium problem, or some other dependent system or am I missing something? It works fine with the standard :rails webrat mode.
I run the task as
rake features
Ubuntu 9.04
machinist 0.3.1
Selenium 1.1.14
Firefox 3.0.10
ruby 1.8.7-p160
cucumber 0.3.7
EDIT: Now, after a restart (office reorg) it won't run tests at all. Firefox just starts, and shuts down, then everything fails.
14:13:25.141 ERROR - Failed to start new browser session, shutdown browser an clear all session data
org.openqa.selenium.server.RemoteCommandException: timed out waiting for window 'null' to appear
I've tried updating the selenium-server.jar from the latest version, and no dice.
Cucumber::Rails.use_transactional_fixtures
Was the culprit. In selenium you can't have transactional fixtures, so writing cucumber steps will be a bit more fun, but whatever. Commenting out the above line fixes the password problem.

Resources