# \[Cucumber\] and rake pass command-line params

**URL:** <https://www.ruby-forum.com/t/cucumber-and-rake-pass-command-line-params/159219>\
**Category:** RSpec\
**Created:** [February 2, 2009, 2:29pm UTC](https://www.ruby-forum.com/t/cucumber-and-rake-pass-command-line-params/159219 "2009-02-02T14:29:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@aap](https://www.ruby-forum.com/u/aap)\
**Post date:** [February 2, 2009, 2:29pm UTC](https://www.ruby-forum.com/t/cucumber-and-rake-pass-command-line-params/159219/1 "2009-02-02T14:29:15Z")

</div>

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  
👏

–  
View this message in context:  
[http://www.nabble.com/-Cucumber--and-rake-pass-command-line-params-tp21789574p21789574.html](http://www.nabble.com/-Cucumber--and-rake-pass-command-line-params-tp21789574p21789574.html)  
Sent from the rspec-users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![aap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@aap](https://www.ruby-forum.com/u/aap)\
**Post date:** [February 2, 2009, 3:02pm UTC](https://www.ruby-forum.com/t/cucumber-and-rake-pass-command-line-params/159219/2 "2009-02-02T15:02:54Z")

</div>

On Mon, Feb 2, 2009 at 2:24 PM, AndreXP [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 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

---

<div class="post-metadata">

**Author:** ![aap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@aap](https://www.ruby-forum.com/u/aap)\
**Post date:** [February 2, 2009, 5:27pm UTC](https://www.ruby-forum.com/t/cucumber-and-rake-pass-command-line-params/159219/3 "2009-02-02T17:27:44Z")

</div>

Great advice, I did all the suggestions you made, and… it is GOOD and  
CLEAN:)

Thanks Aslak
