Cucumber + webrat + selenium File upload issue

28 views
Skip to first unread message

Stefan

unread,
Jul 27, 2009, 3:50:02 PM7/27/09
to webrat
Hi,

I have a cucumber + webrat + selenium installation (latest versions)
on a Windows XP machine + Firefox 3.5, Rails 2.1.
I applied all the patches and configurations needed for testing the
file uploading. Right now the file input is updated by attach_file
(using selenium), but the parameter for the input file is empty :

Parameters: {"action"=>"create", "controller"=>"docfiles",
"host"=>"localhost", "docfile"=>""}

The cucumber step code is :

When /^I upload a file from "([^\"]*)"$/ do |path|
click_link 'Add file'

# file_attach is just updating the input but the parameter is
empty
# attach_file( 'docfile', File.join(Rails.root, assets_path,
path) )
simulate do
click_link 'Upload' # manual upload
end
selenium.wait_for_page_to_load
end

my cucumber env.rb file is :

ENV["RAILS_ENV"] ||= "test"
require File.expand_path(File.dirname(__FILE__) + '/../../config/
environment')

require 'cucumber/rails/world'
require 'cucumber/formatter/unicode'
require 'cucumber/rails/rspec'
require 'webrat'
require 'factory_girl'
require File.join(Rails.root, 'spec/factories')

Webrat.configure do |config|
config.mode = :selenium
config.application_environment = :test
config.application_framework = :rails
config.application_port = 3000
config.selenium_server_port = 4444
config.selenium_browser_key = "*chrome D:/Program Files/Mozilla
Firefox 3/firefox.exe"
end

World(Webrat::Selenium::Matchers)


The form is having only the input file :

<% form_tag(docfiles_action_url(:create), { :name =>
"form_file", :multipart => true } ) do %>
<%= file_field_tag :docfile %>
<%= link_to "<span>Upload</span>", "#", :onclick => "toggleVisibility
('buttons');toggleVisibility('spinner');document.form_file.submit
();return false" %>

And I launch the test like this:

1. ...>ruby script/server -e test
2. ...>cucumber features

I checked with 3 different configurations : cucumber + webrat,
cucumber + selenium, cucumber + selenium + webrat, I downgraded
Firefox to 3.0, I checked that hidden input values are transmitted
into the parameters, I also tested the form as a standalone html page.

If someone can help me I would appreciate very much.

JDS

unread,
Jul 30, 2009, 4:33:17 AM7/30/09
to webrat
Well I can't help you with this problem but I'm impressed that you can
actually get cucumber + webrat + selenium to work.

A lot of people here are having problems with that combination but so
far no one has stepped in to say "ok you need to do xyz"

The problem we have is that while cucumber + webrat works fine, and
webrat +selenium works fine (well sort of), the three together don't.
What happens is that when cucumber + webrat + selenium are used
together then it sends the browser off to http://www.example.com which
of course doesn't have the same app (or indeed any app) as http://localhost:3001.

Please, please, please will someone tell us how to get round that
problem.

Clearly you've managed to get past that hurdle. How did you do it?

Thanks

John Small

Stefan

unread,
Jul 30, 2009, 7:30:24 AM7/30/09
to webrat
Hi,

This is what I did, not necessary being correct, also the comments may
be erroneous :

Patches for Windows XP + Firefox 3.5

1. Go to ruby/lib/ruby/gems/1.8/gems/webrat-0.4.4/vendor
2. Backup the selenium-server.jar
3. Rename selenium-server.jar to selenium-server.rar
4. Open selenium-server.rar
5. Go to customProfileDirCUSTFF/extensions/{538F0036-F358-4f84-
A764-89FB437166B4}, edit install.rdf and change to
<em:maxVersion>4.0.*</em:maxVersion>
6. Go to customProfileDirCUSTFF\extensions\ready...@openqa.org, edit
install.rdf and change to <em:maxVersion>4.0.*</em:maxVersion>
7. Go to customProfileDirCUSTFFCHROME\extensions\{503A0CD4-
EDC8-489b-853B-19E0BAA8F0A4}, edit install.rdf and change to
<em:maxVersion>4.0.*</em:maxVersion>
8. Go to customProfileDirCUSTFFCHROME\extensions\{538F0036-F358-4f84-
A764-89FB437166B4}, edit install.rdf and change to
<em:maxVersion>4.0.*</em:maxVersion>
9. Go to customProfileDirCUSTFFCHROME\extensions
\ready...@openqa.org, edit install.rdf and change to
<em:maxVersion>4.0.*</em:maxVersion>
10. Save selenium-server.rar and rename to selenium-server.jar

11. Edit ruby/lib/ruby/gems/1.8/gems/webrat-0.4.4/lib/webrat/selenium/
selenium_rc_server.rb and change to :
@remote_control = ::Selenium::RemoteControl::RemoteControl.new
("127.0.0.1", Webrat.configuration.selenium_server_port, :timeout =>
60) in def remote_control
:host => (Webrat.configuration.selenium_server_address ||
"127.0.0.1"),
in def wait_for_socket
::Selenium::RemoteControl::RemoteControl.new("127.0.0.1",
Webrat.configuration.selenium_server_port, :timeout =>
60).stop in def stop

In Windows 0.0.0.0 host is already used (and tested in Ununtu and also
had problems with 0.0.0.0) and timeout was increased in order to give
us time to tell Firefox to trust the site (on localhost the SSL
Certificate may not be a trusted one)

12. Edit ruby/lib/ruby/gems/1.8/gems/webrat-0.4.4/lib/webrat/selenium/
selenium_session.rb and add

def attach_file(field_locator, path, content_type = nil)
fill_in(field_locator, :with => path)
end

after webrat_deprecate :fills_in, :fill_in (or elsewhere)

Webrat 0.4.4 forgot to add this method to it's selenium
implementation.


Run the tests

First start the application in test environment
>ruby script/server -e test
Then run the tests in a separate command line
>cucumber features


cucumber/support/env.rb is :


# Sets up the Rails environment for Cucumber
ENV["RAILS_ENV"] ||= "cucumber"
require File.expand_path(File.dirname(__FILE__) + '/../../config/
environment')

require 'cucumber/rails/world'
require 'cucumber/formatter/unicode'

# Comment out the next line if you want Rails' own error handling
# (e.g. rescue_action_in_public / rescue_responses / rescue_from)
Cucumber::Rails.bypass_rescue

# When using webrat/selenium we can't use transactional fixtures
#Cucumber::Rails::World.use_transactional_fixtures

require 'webrat'

Webrat.configure do |config|
config.mode = :selenium
config.application_environment = :test # Selenium runs in it's own
ENV['Selenium'], ensure we keep the ENV['test']
config.application_framework = :rails # Inform cucumber we use
Rails Framework (could be Merb, etc)
config.application_port = 3000 # By default this should be
3001, but we want 3000
config.selenium_server_port = 4444 # By default this is 4444
config.selenium_browser_key = "*chrome D:/Program Files/Mozilla
Firefox 3/firefox.exe" # Because of cross site scripting issue with
file input we use the Chrome profile of Firefox which leverage the
security
end

require 'cucumber/rails/rspec'
require 'webrat/core/matchers'
require 'database_cleaner'
require 'database_cleaner/cucumber'
#require 'factory_girl'
#require File.join(Rails.root, 'spec/factories')

# Ensure that the steps of the feature have access to selenium
matchers
World(Webrat::Selenium::Matchers)

# selenium can't handle database transactions, we need to truncate the
test database after each run of a feature
DatabaseCleaner.strategy = :truncation, {:except => %w[plans
roles ...]}




That input file I could not solve. And I also tested on an Ubuntu
machine and it's worse, selenium is requesting not the Test
environment started application but the Staging environment (it's a
staging server). And I could not started Selenium and application with
the same cuumber features command (same as locally).
Reply all
Reply to author
Forward
0 new messages