Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在我的cucumber测试中使用yml文件?_Cucumber_Yaml - Fatal编程技术网

如何在我的cucumber测试中使用yml文件?

如何在我的cucumber测试中使用yml文件?,cucumber,yaml,Cucumber,Yaml,我想在cucumber测试中使用config.yml文件。我是这样写的: 测试配置yml: group_name: animals learn_group_name: dogs card_box_name: cats require `watir-webdriver` require `yaml` def read_config config = YAML.load(File.read(`/home/profile/Desktop/cucumber/test_config.yml`))

我想在cucumber测试中使用config.yml文件。我是这样写的:

测试配置yml:

group_name: animals
learn_group_name: dogs
card_box_name: cats
require `watir-webdriver`
require `yaml`

def read_config
  config = YAML.load(File.read(`/home/profile/Desktop/cucumber/test_config.yml`))
  @group = config[`group_name`]
  @learn_group = config[`learn_group_name`]
  @card_box = config[`card_box_name`]
end

puts `Group = #{@group}`
puts `Learn group = #{@learn_group}`
puts `Card box = #{@card_box}`
...
Group = 
Learn group = 
Card box =
...
黄瓜试验。rb:

group_name: animals
learn_group_name: dogs
card_box_name: cats
require `watir-webdriver`
require `yaml`

def read_config
  config = YAML.load(File.read(`/home/profile/Desktop/cucumber/test_config.yml`))
  @group = config[`group_name`]
  @learn_group = config[`learn_group_name`]
  @card_box = config[`card_box_name`]
end

puts `Group = #{@group}`
puts `Learn group = #{@learn_group}`
puts `Card box = #{@card_box}`
...
Group = 
Learn group = 
Card box =
...
控制台(终端):

group_name: animals
learn_group_name: dogs
card_box_name: cats
require `watir-webdriver`
require `yaml`

def read_config
  config = YAML.load(File.read(`/home/profile/Desktop/cucumber/test_config.yml`))
  @group = config[`group_name`]
  @learn_group = config[`learn_group_name`]
  @card_box = config[`card_box_name`]
end

puts `Group = #{@group}`
puts `Learn group = #{@learn_group}`
puts `Card box = #{@card_box}`
...
Group = 
Learn group = 
Card box =
...

但是怎么了?

这是一个非常糟糕的代码示例

您正在使用反勾号(`)而不是引号(“)。这将导致问题。很多问题

该问题与cucumber或watir webdriver gems无关。您正在方法(
read\u config
)中定义实例变量(
@group
…),但您从未调用该方法

请用更现实的例子更新问题

Before do
  @host                         ||= YML["host"]
  @group_name_for_search        ||= YML["group_name_for_search"]
  @learn_group_name_for_search  ||= YML["learn_group_name_for_search"]
  @card_box_name_for_search     ||= YML['card_box_name_for_search']
end
我必须先定义,然后再做黄瓜步骤