Is it possible to run capybara-webkit (i.e. forked webkit_server) on Heroku Cedar?
I spoke to Heroku support about this and their answer was that this is basically a) unsupported; b) very difficult, including (among other things) a statically built version of QtWebKit.
My own investigation into this on Amazon EC2 also made me realize that QtWebKit requires a running instance of Xvfb. I highly doubt this would be available on Heroku, and I suspect it would be extremely difficult to make it work.
My own approach has been to put this functionality on an EC2 instance. After making some attempts with Amazon's standard AMIs (their build and RHEL), I found that the packages available through Ubuntu's package management systems made it MUCH easier to get up an running.
Long story short: Heroku is a non-starter, Amazon EC2 with Ubuntu is the best way to go.
How to get a DOM elements click handler using capybara-webkit or native QtWebKit?
You can execute arbitrary Javascript and return the result using page.execute_script
. If the event handlers in question are bound using jQuery, this will list them:
page.execute_script(<<-JAVASCRIPT)
var handlers = $('.some-selector').data("events").click;
jQuery.each(handlers, function(key, handler) {
console.log(handler);
});
JAVASCRIPT
There's a complete answer on introspecting on event handlers here: How to find event listeners on a DOM node when debugging or from the JavaScript code? How to run rails request specs on a cloud deployment?
You can use Capybara with Selenium driver, and set Capybara.app_host
to specify the IP of you staging app server. While doing so you can turn off Capybara local rack with Capybara.run_server = false
Remote testing will allow you only to perform human kind of action and test the returned generated HTML/JS/Json etc .. but no access to controller, view, or any other app internal objects.
On thing you could do (I never tried, but I don't see why it wouldn't work) is to set-up your database.yml test configuration to remotely access you staging database, allowing you to control the database during your tests. It's not really secure so you may want to do that over a SSH tunnel , or a similar solution.
Automating browser actions on a headless server
I would suggest mechanize. I'm not sure that you need something like selenium
for a task like this.
This gem should be able to accomplish what your looking for.
Access all loaded resources with Capybara or similar
As mentioned in an update, there seems to be a way to do this with Poltergeist (a Capybara driver). Here’s a quick and very “hackish” experiment:
require 'rubygems'
require 'capybara'
require 'capybara/poltergeist'
driver = Capybara::Poltergeist::Driver.new({})
port = Capybara::Poltergeist::Util.find_available_port
server = Capybara::Poltergeist::Server.new(port, 30)
client = Capybara::Poltergeist::Client.start(port,
:path => driver.options[:phantomjs],
:window_size => driver.options[:window_size],
:phantomjs_options => driver.phantomjs_options
)
browser = Capybara::Poltergeist::Browser.new(server, client, nil)
browser.visit('http://www.google.com/')
browser.network_traffic.each do |request|
# sorry, quick and dirty to see what we get:
request.response_parts.uniq(&:url).each do |response|
puts "#{response.url}: #{response.status}"
end
end
=>
http://www.google.com/: 200
http://ssl.gstatic.com/gb/images/b_8d5afc09.png: 200
http://www.google.com/images/srpr/logo1w.png: 200
http://www.google.com/images/srpr/nav_logo80.png: 200
http://www.google.com/xjs/_/js/hp/sb_he,pcc/rt=j/ver=FaiMBboaDLc.en_US./d=1/sv=1/rs=AItRSTMKxoHomLOW7ITf6OnfIEr5jQCEtA: 200
This however is very slow and of course far from anything usable. I’m planning on digging deeper into Poltergeist to maybe do the same on a lower level. Capybara vs Page Object
You cannot use Cheezy's page-object gem with Capybara.
The page-object gem only supports Watir-Webdriver and Selenium-WebDriver. It does not support Capybara.
Capybara, Watir and Selenium are for driving browsers while page-object is for modelling your pages. If you switch to Capybara, you would need to pick a different page-object library such as SitePrism. Switching would mean you either need to support two completely separate stacks or re-write your existing tests.
Related Topics
Why Should @@Class_Variables Be Avoided in Ruby
How to Avoid Circular Creation of Associated Models in Factory_Girl
Change Time Zone in Pure Ruby (Not Rails)
Ruby Class#New - Why Is 'New' a Private Method
How to Test If a Value Is a Prime Number in Ruby? Both The Easy and The Hard Way
Rvm Can No Longer Install 1.8.7-P352 on MAC Os X Mountain Lion
Recommended Way to Generate a Presigned Url to S3 Bucket in Ruby
Using Elasticsearch to Filter Through Tags with Whitespace
Warning While Installing The Rails Plugin
I Am Getting This Gem Install Error for Kgio Gem When I Do a Bundle Install
Undefined Method 'Merge' for '####':String <%= Form_For %> Helper
Modifying Text Inside HTML Nodes - Nokogiri
Best/Most Elegant Way to Share Objects Between a Stack of Rack Mounted Apps/Middlewares