保持黄瓜常见步骤的最佳做法 [英] Best practice to keep common steps of cucumber
问题描述
出于自动化目的,我正在使用cuminga-watir-webdriver.我具有以下目录结构:
I'm using cucumber-watir-webdriver with for automation purposes. I have the following directory structure:
|features
-|feature1
--|1.feature
--|step_definitions
---|1.rb
-feature2
--|2.feature
--|step_definitions
---|2.rb
,依此类推.我需要知道什么是减少1.rb
和2.rb
中冗余的最佳实践.
feature1
和feature2
完全不同,因此我无法将两者合并在一个目录中.
还有一些地方,要素线相同,但步骤执行不同,因此如果将它们放在一起会产生歧义.
and so on. I need to know what is best practice to reduce redundancy in 1.rb
and 2.rb
.
feature1
and feature2
are completely different so I cannot combine both in one directory.
Also there is some part where feature line is same but execution in steps is different so it will create ambiguity if they are together.
我需要知道1.rb
和2.rb
中是否存在某些通用的地方,应该放在哪里,这是保留通用步骤定义的最佳实践.
I need to know if there is some part common in 1.rb
and 2.rb
where should I put it is there best practice to keep common step definitions.
推荐答案
黄瓜仅在当前目录或后续目录中搜索步骤定义. 因此,我们不能在两个要素目录下建立通用的步骤定义目录或文件, 我找到了一个解决方案,
Cucumber only searches for step definitions in current or following directories. So we can not have common step definitions directory or file below two feature directories, I found one solution to this as
|features
-|feature1
--|1.feature
--|step_definitions
---1.rb
-feature2
--|2.feature
--|step_definitions
---2.rb
-|common_steps.rb <-- keep common steps in here
现在要加载此步骤定义添加
now to load this step definition add
require "#{File.dirname(__FILE__)}/../../common_steps.rb"
在您的1.rbs中. 您也可以使用更长的目录结构,然后可以将common_steps.rb文件保留在每个包含以下功能常规步骤的目录中,并且可以要求以前的common_steps.rb文件带有-
in your 1.rbs. also you can have longer directory structure then you can keep common_steps.rb file in every such directory containing common steps of following features and you can require previous common_steps.rb file with--
require "#{File.dirname(__FILE__)}/../common_steps.rb"
此代码. 这将使您的目录结构和step_definition文件保持干净
this code. This will keep your directory structure and step_definition files clean
这篇关于保持黄瓜常见步骤的最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!