Rails testing with Selenium and everybody has a wrong password - ruby-on-rails

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.

Related

Rails test unit access denied rename

I'm new here. I search everywhere and I haven't found anything. I'm using rails on windows 10. I'm following the basic tutorial of a sample app. When I execute "rails test" command in the console I get the following errors. I checked the permissions of each file and directory and all have the permissions needed. Can someone help me ?
I'm using rails 6.0.2.2 version.
Hope I'll get answer here.
Solution : I installed ubuntu on windows 10.
Stop your rails server before executing your tests: the server is keeping cache files locked and the testing framework is trying to alter them.
I encountered the same issue (while following what's probably the same tutorial you were following) on Rails 6.0.3.4 on Windows 10 and doing so solved it. (launching the server again before executing tests reproduced it again)
Update: I thought this was a complete solution, but it's more complex than that. Here's my experience:
running rails test while rails server is running results in the error;
running rails test when rails server is not running sometimes results in the error.
I haven't encountered this error on Linux so far, so my guess is that the implementation of Rails of Windows is unstable and sometimes gets stuck locking its own files.
You can check if you can reproduce the same behaviour, but I would report it as a bug.

CI won't execute properly for Rails project after switching to selenium

I'm switching from capybara-webkit to the webdrivers gem and it's all running fine locally for me, get on my CI on Gitlab I'm getting this error bin/rails: No such file or directory - --product-version I've updated my gitlab-ci.yml to include the selenium/standalone-chrome:latest service yet it's still failing and I can't seem to find anything on the issue. Any thoughts?
It sounds to me like it's not finding the Chrome binary for some reason... I had this exact error on my new laptop just now, and it went away when I installed Chrome. Is there another route you can take to getting Chrome in place, other than adding the service you mentioned?

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.

Race condition in Rails 2.3 and phantomJS

I have a rails 2.3 application running on REE. I am using capybara 1.1.2, cucumber 1.1.0, poltergeist (used both 0.6.0 and lastest from github) and phantomJS 1.5.0. My problem is that I believe I have a race condition in phantomJS that is causing my cucumber tests to randomly fail. The cucumber test work perfectly when I run them in Chrome so I am pretty sure the problem is in poltergeist or phantomJS. When I run the cucumber tests in PhantomJS (so that I can run them on the CI server) I will randomly get errors like this:
One or more errors were raised in the Javascript code on the page:
TypeError: 'undefined' is not a function
http://static.ak.fbcdn.net/rsrc.php/v2/yd/r/c9z-2BUoufJ.js:75
http://static.ak.fbcdn.net/rsrc.php/v2/yd/r/c9z-2BUoufJ.js:75
http://static.ak.fbcdn.net/rsrc.php/v2/yd/r/c9z-2BUoufJ.js:9 in bound:(?) (Capybara::Poltergeist::JavascriptError)
./features/step_definitions/site_steps.rb:8:in `/I am on the home page/'
features/account_creation.feature:89:in `Given I am on the home page'
Failing Scenarios:
cucumber features/account_creation.feature:5 # Scenario: I should be able to start creating a resume without signing up
cucumber features/account_creation.feature:79 # Scenario: I should be able to log in with an old username and password
cucumber features/account_creation.feature:88 # Scenario: I should be able to remember my login so that when the browser is closed I am automatically logged in
Based off of the Github page for poltergeist I have added this to my env.rb to solve the rack pre version 1.3 race condition problems:
Capybara.server do |app, port|
require 'rack/handler/thin'
Thin::Logging.silent = true
Thin::Server.new('0.0.0.0', port, app).start
end
But this has not made any difference that I can tell. Any thoughts would be appreciated even if it is just a suggesting that this is a poltergeist problem or a phantomJS problem so I know how I should ask about it next.

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

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

Resources