我想在小黃瓜步驟中獲取頁面名稱,然后將其設定為物件參考(我認為這就是它的名稱。)然后我可以使用它與頁面元素進行互動。在紅寶石中有更簡單的方法嗎?
When(/^I am on the (.*) page$/) do |page|
case page
when "home page"
@current_page = @home_page
when "my account page"
@current_page = @my_account_page
end
end
然后
When(/^I click the (.*)$/) do |element|
@current_page.send(element).click
end
uj5u.com熱心網友回復:
您可以使用instance_variable_get:
When(/^I am on the (.*) page$/) do |page|
@current_page = instance_variable_get("@#{page}")
end
page如果值與您的實體變數完美匹配,這將起作用,例如
page = "my_account_page"
# The following two lines are equivalent
instance_variable_get("@#{page}")
@my_account_page
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/478025.html
