cucumber javascript enabled features inside vagrant - ruby-on-rails

i am a big fan of both cucumber and vagrant. i am using cucumber to drive development with a BDD style and have configured and setup my dev environment once in a vagrant vm so it can be easily distributed to other developers.
i've hit a snag when it comes to testing js on the vagrant vm. i'm using capybara alongside cucumber and have tried both selenium and capybara-webkit as js drivers.
selenium wanted me to install firefox. so i packaged up the vagrantbox fully expecting it not to work and installed firefox on the vm.. after that it complained about being unable to get a stable connection with firefox. exact error message: 'unable to obtain stable firefox connection in 60 seconds'
webkit complained about 'webkit_server: cannot connect to X server'.. i installed xserver-org and still no dice.
would much prefer if i didn't have to install my whole environment on my host in order to do testing as that would kind of defeat the purpose of having a distributable vagrant vm that has everything a dev needs to work on the app.
any ideas? i've encountered a similar problem with the notifications from guard, but that seems like not nearly as big a deal as this issue.

I think that all drivers require X, to be installed.
So on linux server I do not have how do it.
Other way it using Firefox from host machine via selenium remote.
It mean javascript will be run on remote Firefox on any machine.
Remote Selenium WebDriver not responding to Cucumber tests
http://code.google.com/p/selenium/wiki/RubyBindings
It work.
Run selenium server on host
java -jar selenium-server-standalone.jar
Changes in spec_helper.rb
require "selenium-webdriver"
profile = Selenium::WebDriver::Firefox::Profile.new
profile["network.http.use-cache"] = false
Capybara.register_driver :firefox_host do |app|
Capybara::Selenium::Driver.new(app,
:browser => :remote,
:url => 'http://10.0.2.2:4444/wd/hub',
:desired_capabilities => Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)
)
end
Capybara.server_port = 9300
Capybara.app_host = 'http://localhost:9300'
Capybara.javascript_driver = :firefox_host
Changes in Vagrantfile
config.vm.forward_port 9300, 9300

You may want to try running firefox headless.
http://www.alittlemadness.com/2008/03/05/running-selenium-headless/
This way, you can run tests without seeing them as well.

I ran into a similar issue. Try ssh'ing into your VM and executing xhost + from the command line. This disables access control and allows clients to connect from any host to access your display.
Also, you might need to export DISPLAY=:0 as well, because the webdriver will default to using this display when it launches Firefox.

Related

Rails headless browser testing without installing browser

We're doing some testing in Rails using a headless browser for our feature tests using RSpec and the web drivers gem: https://github.com/titusfortner/webdrivers to get the Chrome driver.
However we've had some issues whereby some developers don't have Chrome installed (and don't intend to) and also we have our app running on a Jenkins pipeline and we want to avoid having to install Chrome on the server for the tests...
Is it possible to run a headless browser without installing the actual browser as well as a hard dependancy on the system that the tests run on?
I've read conflicting articles that state headless allows you to still do your testing either when the system doesn't have the browser installed... but at the same time the documentation for Chrome and Firefox state the browser also needs to be installed when using their drivers.
https://github.com/rubycdp/cuprite I also came across this which bypasses the need for WebDriver etc... but still seems to have a hard dependancy on having Chrome installed on the system the tests run on.
You have to choose a browser:
Chrome: chromedriver
Firefox: geckodriver
Edge: edgedriver
Internet Explorer: iedriver
See https://github.com/titusfortner/webdrivers

[selenoid][capybara][rails] Can we use selenoid with Rack App

In Rails when we use capybara with selenium then by default they run the rack server for our rails app and we can test it without running the actual app.
So let me explain what does it mean:
so when we configure capybara rspec and selenium for rails then don't need to run your rails server separately, when we run the spec and when we visit any URL of our app in the specs then its working. its happen because it create a rack server in the background .
Now I use Selenoid instead of selenium but the rack server not working.
so does selenoid only work with remote url and it not create any rack app?
Let me know if any other info. is required.
Thanks!
Selenoid is a replacement for the selenium grid, and manages the browser instances you're using for testing. It has nothing to do with running the application under test.
The issue you're running into is that Capybara runs the application on the machine you're running the tests on, but when using selenoid the browsers are running on other machines (containers). This means that when Capybara starts up the application and tells the browser to visit https://localhost:<some port>/some/path, the localhost reference is no longer correct for browsers running on other machines. To correct that you need to set Capybara.app_host to the url where the tests are being run as seen from the machines/containers the browser instances are being run on. Depending on exactly how your container network is configured you'll also need to either fix the port used by Capybara to run the app on or specify the Capybara.always_include_port option.
Capybara.app_host = "http://local_machine_as_seen_from_containers"
Capybara.always_include_port = true
or
Capybara.server_port = 1234 # some port number
Capybara.app_host = "http://local_machine_as_seen_from_containers:#{Capybara.server_port}"

Cucumber failing in chrome with "Retry later" message

I'm trying to run my cucumber tests and they seem to stop randomly. A new page is visited but nothing renders on the page except Retry later as in the following screenshot.
I'm on OS X 10.9.3, Chrome 35.0.1916.114, and running with bundle exec cucumber. It's happening in and Firefox also if I change the javascript driver.
The problem was not with Chrome, Cucumber, or Capybara. It was with Rack::Attack. 127.0.0.1 was whitelisted but according to this github issue
it wasn't whitelisting ipv6 and transitional loopback ip addresses
To simplify things I just moved Rack Attack to be production only.
tl;dr
Rack::Attack was to blame. Unless you need it in your test environment, just make the gem production only.

Viewing Selenium Scripts in Jenkins Server

I am using Jenking to run my selenium scripts on a remote server. My question is "Is there any way to visually see my scripts running on the server? I mean on an actual browser when scripts are running in Jenkins?"
No, you cannot visually see a browser running on ubuntu server but apart from that you can run a headless browser and log everything to see the progress of your scripts running on server.
Yes, either use a Sauce labs account, or just run tightVNC server on the remote system, which runs a vnc server in a "Java Viewer" and by setting a "readonly password" to the server, you can open a browser and using the java viewer, basically you can watch the session and you can even "scale" the size of the desktop just like Sauce Labs can do.

Remote debugging Rails application in Aptana Studio 3

My Rails development IDE is Aptana Studio 3.0.5, running on Windows.
The applications runs on Apache + ModRails (Phusion Passenger) on a separate CentOS Linux machine. I have both Rails 2.x and 3.x applications.
I would like to be able to use the debugger in Aptana Studio (connect to the running application remotely). There are apparently some provisions for this, but I was unable to figure out what I need on the server side (in my Rails application configuration)
I've tried this:
Using Rack::Debug: It creates only unix socket, cannot be connected remotely.
Using ruby-debug directly:
I added this to my /config/environments/development.rb:
if File.exists?(File.join(RAILS_ROOT,'tmp', 'debug.txt'))
require 'ruby-debug'
Debugger.wait_connection = true
Debugger.start_remote("real.hostname", 5000, 5001)
File.delete(File.join(RAILS_ROOT,'tmp', 'debug.txt'))
end
Sprinking my code with debugger statements stop the execution, but I cannot connect to this instance from Aptana, not to port 5000 and not port 5001 (and I don't understand why I need two ports there).
Also, this method would be rather slow and too convoluted even if it worked, I'd like to have a more "integrated" debugging. Is it possible at all?
The old steps for Netbeans are relatively close since Aptana/RadRails and Netbeans share the same debugger core: http://blogs.oracle.com/martink/entry/remote_debugging_debug_whatever_ruby
Basically, run the ruby app using rdebug-ide -p 7000 (or whatever port you want), then inside the IDE, go to Run > Debug configurations. On the left hand side, select "Remote Ruby Debug Session" and then add a new configuration there (the plus icon above the list). Enter the proper host IP/name and port you entered on the command line.

Resources