我对页面对象模式 gem 'site_prism' 有以下步骤定义:
class Main < SitePrism::Page
element :login_link, "a.log-in-link"
element :login_field, "input[name='userLogin']"
element :pass_field, "input[name='userPassword']"
element :enter_button, ".button_pretty"
end
If /I'm log in as "([^"]*)" with password "([^"]*)"$/ do |login, pass|
@main = Main.new
@main.login_link.click
@main.login_field.set login
@main.pass_field.set pass
@main.enter_button.click
end
它工作正常,但看起来很重且不美观。有没有办法像 capybara 'within' 方法来写它?以下不起作用(错误:“无法将 Main 转换为字符串(TypeError)”)
within @main do
login_link.click
login_field.set login
pass_field.set pass
enter_button.click
end