簡體   English   中英

在ruby siteprism中重用步驟定義的最佳方法是什么

[英]What's the best way to reuse your step definition in ruby siteprism

即時通訊在嘗試使用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是動態的,此邏輯將檢查其是否為true

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"

我的問題是這個期望(@common_page。 @ref .text) .to eq(arg1)

映射錯誤@ref需要使用它獲得的數據(例如“ stackover”,“ ask”和“ question”)並在CommonLib頁面def中進行映射

調用#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實例變量,它們似乎應該只是在測試結束時超出范圍的常規變量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM