1
我使用几乎杰夫·摩根的新书“黄瓜&奶酪”的确切相同的设置,我有一个页面对象,像这样为什么这个返回“无法转换零到字符串”
class NewPublicationPage
include PageObject
include RSpec::Matchers
...
def submit_basic_message_with_tag
@tag = Time.now.to_i
...
self.tag_entry = @tag
# the tag ends up getting added later on down the road to a div container.
...
end
def verify_last_tag
done_loading
# tag_list is a div container that should contain the tag.
tag_list.should include @tag
end
end
当我运行在Cucumber步骤中执行以下命令,每个命令都带有自己的步骤,但失败的原因是cannot convert nil to string
。我知道它与实例变量@tag有关,但我不知道为什么。
When /^I submit a basic message with tags$/ do
on_page(NewPublicationPage).submit_basic_message_with_tag
end
Then /^I should see the tag under Publish History$/ do
visit_page(PublishHistoryPage) # goes to page with div container that holds tags
on_page(NewPublicationPage).verify_last_tag #this creates the error
end
你没有添加你的步骤代码,但我不确定,但我会说,如果第二步失败,这是因为@tag是零。事实上,在'submit_basic_message_with_tag'函数中,您将为其分配一个值,但不在第二个函数中。 – pjam
我认为你是对的,那么我将如何从'submit_basic_message_with_tag'方法中获取'@ tag'的值?因为这是我需要的,并且它需要在两种方法中保持相同的价值。 –
因为我不知道你的步骤是怎么做的,所以很难说你如何实现这个 – pjam