无法使用黄瓜进行测试

时间:2013-11-27 15:06:08

标签: ruby cucumber watir watir-webdriver

我安装了:ruby,watir-webdriver,rspec,黄瓜。

我创建了名为“features”的文件夹。里面有黄瓜测试“process.feature”,其中一个特征是1个简单的场景。在“features”中还有一个名为“step_definitions”的文件夹,其中是ruby文件process.rb。 我尝试在命令行中运行测试“cucumber process.feature”,但它表示步骤未定义:1个场景(1个未定义),3个步骤(3个未定义)。

你能告诉我我错过了什么吗?

process.feature:

Feature:
‘User Login.’

Scenario:
Given I am logged in
When I open the process page
Then I see the details page

process.rb

Given /^I am logged in$/ do
b = Watir::Browser.new
b.goto 'http://star.teepub:000/star-web/'

code = '48702'
password = 'test'

b.text_field(:id => 'j_username').set code
b.text_field(:id => 'j_password').set password
b.link(:id => 'loginBtn').click
end

When /^I open the process page$/ do
pending

end

Then /^I see the details page$/ do
pending
end

1 个答案:

答案 0 :(得分:3)

您的结构如下:

--/features
    process.feature
    ---/step_definitions
         process.rb

要在命令行中运行此要素类型:

cucumber process.feature -r step_definitions

注意,要运行此命令,您必须位于功能目录中。 命令后

cucumber

您必须输入* .feature文件的路径,例如

cucumber features/process.feature

cucumber my_project/features/process.feature

您也可以使用标签,例如

@some_name
Feature:
‘User Login.’

Scenario:
Given I am logged in
When I open the process page
Then I see the details page

使用命令

cucumber --tag @some_name

在这种情况下,将执行使用@same_name标记的功能。 如果在场景之前放置标记并键入命令

cucumber --tag @some_name

再次,只会执行用@some_name标记的场景。

相关问题