Hi list, I might have not asked this correctly in previous post.. and most definitely weren?t clear! let?s try again :) I can?t seem to find any examples of using a rake variable in the Cucumber task. What I want to do is run my cucumber test using cruisecontrol and setting a variable in script to either to start Firefox or Internet Explorer with selenium. Which leads me to the question, how do I access this browser_type variable in my_steps.rb file? ## Rakefile Cucumber::Rake::Task.new do |t| profile = ENV[''PROFILE''] || ''default'' browser_type = ENV[''BROWSER''] || ''*chrome'' t.cucumber_opts = "--profile #{profile}" end ## my_steps.rb Before do browser = Selenium::SeleniumDriver.new(server_host, server_port, browser_type, root_url, time_out) end Let me guess, it?s very easy... but I am still new to the Ruby World :clap: -- View this message in context: http://www.nabble.com/-Cucumber--and-rake-pass-command-line-params-tp21789574p21789574.html Sent from the rspec-users mailing list archive at Nabble.com.
aslak hellesoy
2009-Feb-02 13:58 UTC
[rspec-users] [Cucumber] and rake pass command-line params
On Mon, Feb 2, 2009 at 2:24 PM, AndreXP <andre.x.pretorius at gmail.com> wrote:> > Hi list, > > I might have not asked this correctly in previous post.. and most definitely > weren''t clear! let''s try again :) > > I can''t seem to find any examples of using a rake variable in the Cucumber > task. What I want to do is run my cucumber test using cruisecontrol and > setting a variable in script to either to start Firefox or Internet Explorer > with selenium. Which leads me to the question, how do I access this > browser_type variable in my_steps.rb file? >I suggest you look up ENV[''BROWSER''] (and anything else you might need to configure Selenium) directly in your my_steps.rb file (I also suggest you move Before blocks to features/support/env.rb) # Rakefile Cucumber::Rake::Task.new do |t| profile = ENV[''PROFILE''] || ''default'' t.cucumber_opts = "--profile #{profile}" end # features/support/env.rb Before do browser_type = ENV[''BROWSER''] || ''*chrome'' browser = Selenium::SeleniumDriver.new(server_host, server_port, browser_type, root_url, time_out) end If you want to rely less on environment variables, you can make yourself a YAML file with settings (e.g. selenium.yml) consisting of a Hash of Hash: chrome: server_host: foo browser: *chrome timeout: 2 ie: server_host: bar browser: *ie timeout: 9 And do something like this in your env.rb: profile = ENV[''PROFILE''] c = YAML.read_file(''features/selenium.yml'')[profile] browser = Selenium::SeleniumDriver.new(c[''server_host''], ...) -and be done with one single env var - PROFILE HTH, Aslak> ## Rakefile > Cucumber::Rake::Task.new do |t| > profile = ENV[''PROFILE''] || ''default'' > browser_type = ENV[''BROWSER''] || ''*chrome'' > t.cucumber_opts = "--profile #{profile}" > end > > ## my_steps.rb > Before do > browser = Selenium::SeleniumDriver.new(server_host, server_port, > browser_type, root_url, time_out) > end > > Let me guess, it''s very easy... but I am still new to the Ruby World :clap: > > -- > View this message in context: http://www.nabble.com/-Cucumber--and-rake-pass-command-line-params-tp21789574p21789574.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users-- Aslak (::)
Andre Pretorius
2009-Feb-02 15:53 UTC
[rspec-users] [Cucumber] and rake pass command-line params
Great advice, I did all the suggestions you made, and... it is GOOD and CLEAN:) Thanks Aslak On Mon, Feb 2, 2009 at 1:58 PM, aslak hellesoy <aslak.hellesoy at gmail.com>wrote:> On Mon, Feb 2, 2009 at 2:24 PM, AndreXP <andre.x.pretorius at gmail.com> > wrote: > > > > Hi list, > > > > I might have not asked this correctly in previous post.. and most > definitely > > weren''t clear! let''s try again :) > > > > I can''t seem to find any examples of using a rake variable in the > Cucumber > > task. What I want to do is run my cucumber test using cruisecontrol and > > setting a variable in script to either to start Firefox or Internet > Explorer > > with selenium. Which leads me to the question, how do I access this > > browser_type variable in my_steps.rb file? > > > > I suggest you look up ENV[''BROWSER''] (and anything else you might need > to configure Selenium) directly in your my_steps.rb file > (I also suggest you move Before blocks to features/support/env.rb) > > # Rakefile > Cucumber::Rake::Task.new do |t| > profile = ENV[''PROFILE''] || ''default'' > t.cucumber_opts = "--profile #{profile}" > end > > # features/support/env.rb > Before do > browser_type = ENV[''BROWSER''] || ''*chrome'' > browser = Selenium::SeleniumDriver.new(server_host, server_port, > browser_type, root_url, time_out) > end > > If you want to rely less on environment variables, you can make > yourself a YAML file with settings (e.g. selenium.yml) consisting of a > Hash of Hash: > > chrome: > server_host: foo > browser: *chrome > timeout: 2 > ie: > server_host: bar > browser: *ie > timeout: 9 > > And do something like this in your env.rb: > > profile = ENV[''PROFILE''] > c = YAML.read_file(''features/selenium.yml'')[profile] > browser = Selenium::SeleniumDriver.new(c[''server_host''], ...) > > -and be done with one single env var - PROFILE > > HTH, > Aslak > > > ## Rakefile > > Cucumber::Rake::Task.new do |t| > > profile = ENV[''PROFILE''] || ''default'' > > browser_type = ENV[''BROWSER''] || ''*chrome'' > > t.cucumber_opts = "--profile #{profile}" > > end > > > > ## my_steps.rb > > Before do > > browser = Selenium::SeleniumDriver.new(server_host, server_port, > > browser_type, root_url, time_out) > > end > > > > Let me guess, it''s very easy... but I am still new to the Ruby World > :clap: > > > > -- > > View this message in context: > http://www.nabble.com/-Cucumber--and-rake-pass-command-line-params-tp21789574p21789574.html > > Sent from the rspec-users mailing list archive at Nabble.com. > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > Aslak (::) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090202/4cddf156/attachment.html>