Ruby selenium test with CircleCI - ruby-on-rails

I am facing a problem running selenium tests with CircleCI service. If I try to test my ruby application's login functionality:
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "http://0.0.0.0:3000"
driver.find_element(:name, 'user[email]').send_keys('eser#email.com')
driver.find_element(:name, 'user[password]').send_keys('password')
driver.find_element(:name, 'commit').click
On local machine it works perfectly, but with CircleCI test fails. To be more specific, looks like on CircleCI my tests cannot access localhost (tried curl localhost:3000 in CircleCI test box - nothing found). I also tried changing 0.0.0.0 to localhost as well as to 127.0.0.1 - still same result. If I try very similar test for testing google's search (driver.navigate.to "http://www.google.com", etc.) it works with no problem. Tried to contact CircleCI - no response so far. Any ideas how to get my test pass, or at least how to get my application address when it is on CircleCI server?

In order to run tests, you need to have a selenium grid up and running. It works locally, because your box can run selenium tests.. CircleCI cannot run tests, it's just a CI.
What you need to do, is in your project, have your selenium tests point at a grid.
http://somegrid:4444/wd/register

Related

server is undefined in ember cli acceptance test

I am trying to set up an acceptance test for an ember application that is using ember-cli-mirage
The doc says that server is supposed to be a global if you are in an acceptance test, but that is not working for me.
You can see the test/code here https://github.com/chrisortman/ember-cms-frontend/blob/master/tests/acceptance/consent-document-test.js#L7
I managed to make it start working.
I had to qualify my usage of server with window.server
https://github.com/chrisortman/ember-cms-frontend/commit/548189a18e472402def2b69881219e7c2519e0e5
EDIT
It works when I run the tests in browser with the /tests url, but not when using ember test or ember test --server
EDIT2
Seems due to a bug, but if you specify something for your host values it works
https://github.com/chrisortman/ember-cms-frontend/commit/745e28c3feafeee8b5f7f0faa7a554b0a364fd52

Rails rspec+capybara test on staging server?

So I do testing rspec+capybara on localhost, but if I wanted to test on staging server(linux), is it possible to use capybara?
I'm guessing testing with selenium will not work on staging server.
I would like to test frontend(mostly js stuff) on staging, any recommendation would be great.
I use Rails 3.
Checkout the headless gem - From the author
I created it so I can run Selenium tests in Cucumber without any shell scripting. Even more, you can go headless only when you run tests against Selenium.
I'd imagine it would would with rspec as well.

Can selenium test cases be run without setting up the rails environment?

We have a few test cases automated with selenium & capybara during the application development. They all works well when we run it from within the application using rake spec command.
Now in order for the QA team to run these, we don't want to setup the rails environment in their computer. Is there a solution for this?
I am using the following gems,
capybara
selenium
rspec
Any input or suggestion will be really helpful.
Thanks in advance....

Run selenium on a remote server

I am writing integration test for one of my project, using the following gems for the same, rspec, capybara and selenium.
I face the following challenges in the same,
I want to run the test on an existing database, i don't want to clear the existing data before or after executing the test.
We have a remote server for integration testing. Is it possible to run the test on a remove server? The way i would like to go is after updating the build on integration server, i would like to go for a integration test using selenium.
Any help is highly appreciated.
Sorry, but selenium tests cannot be run in a transaction. You have to (for example) dump database and load previously prepared database after executing each test.
Yes, it is possible. What solution you're using for continuous integration and build management? What's the problem you're encountering? Can you describe it?
Got the solution, we need to do as follows,
Capybara.current_driver = :selenium
Capybara.app_host = 'http://www.google.com'
...
visit('/')
Reference: capybara gem

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