For examples, you might want to run your test against a test, staging or production environments and for that you need to tell your code which url you want to test. So, here is how you write a config.yml file and how to use it.
I assume that you have the same project structure mentioned in here
1. Create a new config.yml file under features\support\config.yml
google_australia:
base_url: http://www.google.com.au
google_singpaore:
base_url: http://www.google.com.sg
2. Create a new "features\support\lib\configuration.rb" files to load the config.yml
require 'yaml'
class Configuration
def self.[] key
@@config[key]
end
def self.load name
@@config = nil
io = File.open( File.dirname(__FILE__) + "/../config.yml" )
YAML::load_documents(io) { |doc| @@config = doc[name] }
raise "Could not locate a configuration named \"#{name}\"" unless @@config
end
def self.[]= key, value
@@config[key] = value
end
end
raise "Please set the TEST_ENV environment variable" unless ENV['TEST_ENV']
Configuration.load(ENV['TEST_ENV'])
3. Add the following lines in your "features\support\env.rb" file
require File.dirname(__FILE__) + '/../lib/configuration';
BASE_URL = Configuration["base_url"]
4. Now modify "features\step_definitions\search_steps.rb"
Change
Given /^I am on the main google search$/ do
visit "http://www.google.com"
end
to
Given /^I am on the main google search$/ do
visit "#{BASE_URL}"
end
5. Now before you run the project you just need to set the TEST_ENV
set test_env=google_australia
This will run your test againts www.google.com.au. If you set the test_env=google_singapore then
your test will run againts www.google.com.sg
Did exactly as above but got the following error:
ReplyDelete"undefined local variable or method '_FILE_' for main:Object (NameError).
I am new to cucumber so please any help would be hugely appreciated.
You can run again with --guess to make Cucumber be more smart about it
ReplyDelete(Cucumber::Ambiguous)
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-2.1.0/lib/cucumber/runtime/support_code.rb:199:in `step_match_without_cache'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-2.1.0/lib/cucumber/runtime/support_code.rb:190:in `step_match'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-2.1.0/lib/cucumber/runtime/support_code.rb:140:in `find_match'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-2.1.0/lib/cucumber/filters/activate_steps.rb:28:in `attempt_to_activate'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-2.1.0/lib/cucumber/filters/activate_steps.rb:24:in `map'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-2.1.0/lib/cucumber/filters/activate_steps.rb:24:in `new_test_steps'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-2.1.0/lib/cucumber/filters/activate_steps.rb:18:in `test_case'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-2.1.0/lib/cucumber/filters/activate_steps.rb:8:in `test_case'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-core-1.3.0/lib/cucumber/core/test/case.rb:22:in `describe_to'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-2.1.0/lib/cucumber/filters/quit.rb:11:in `test_case'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-core-1.3.0/lib/cucumber/core/test/case.rb:22:in `describe_to'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-core-1.3.0/lib/cucumber/core/test/filters/locations_filter.rb:17:in `block in done'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-core-1.3.0/lib/cucumber/core/test/filters/locations_filter.rb:16:in `each'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-core-1.3.0/lib/cucumber/core/test/filters/locations_filter.rb:16:in `done'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-core-1.3.0/lib/cucumber/core/filter.rb:61:in `done'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-core-1.3.0/lib/cucumber/core/test/filters/tag_filter.rb:18:in `done'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-core-1.3.0/lib/cucumber/core/compiler.rb:23:in `done'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-core-1.3.0/lib/cucumber/core/gherkin/parser.rb:39:in `done'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-core-1.3.0/lib/cucumber/core.rb:29:in `parse'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-core-1.3.0/lib/cucumber/core.rb:18:in `compile'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-2.1.0/lib/cucumber/runtime.rb:70:in `run!'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-2.1.0/lib/cucumber/cli/main.rb:32:in `execute!'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-2.1.0/bin/cucumber:8:in `'
C:/Ruby22-x64/bin/cucumber:23:in `load'
C:/Ruby22-x64/bin/cucumber:23:in `'
I am getting those errors what does that mean???
it means that you have two or more steps definitions that are the same. You can try checking your steps definition again to make sure they are unique.
ReplyDelete