0

我在尝试使用 siteprism 创建可重用的步骤定义时遇到一些问题,比如说功能文件是

Given that im on the site
Then i should see a "stack over" text
And i should see a "ask" text
And i should see a "question" text

然后我的步骤定义将是

我想让 arg1 是动态的,这个逻辑将检查它是否为真

Then (/^i should see a "(.*?)" text$/) do |arg1|
@common_page = CommonLib.new
@ref = arg1.gsub(/\s+/,'')
expect(@common_page.*@ref*.text).to eq (arg1)
end

然后在我的页面 def 将是

class CommonLib < siteprism::page

element :stackover, "#text_header"
element :ask, "#text_ask"
element :question, "#text_question"

我遇到的问题是这个expect(@common_page. @ref .text) .to eq (arg1)

映射错误@ref 需要使用它得到的数据,如“stackover”、“ask”和“question”,并在 CommonLib 页面 def 中映射

4

1 回答 1

2

调用 #text 并使用eq匹配器通常不是一个好主意,因为它绕过 Capybaras 内置的重试行为,并且可能导致动态更改页面上的不稳定测试。相反,您应该使用 have_text 或传递给查找器的 :text 选项

expect(@common_page.send(@ref)).to have_text(arg1)

或者

expect(@common_page.send(@ref, text: arg1)).to be

此外,您制作 @common_page 和 @ref 实例变量是否有原因,它们看起来应该只是在测试结束时超出范围的常规变量。

于 2016-05-10T17:15:12.993 回答