2

I have the following step definitions with Page Object Pattern 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

It works fine but looks very heavy and unbeautiful. Is there any way to write it like capybara 'within' method? The following isn't work (Error: "can't convert Main into String (TypeError)")

within @main do
    login_link.click
    login_field.set login
    pass_field.set pass
    enter_button.click
end
Nat Ritmeyer
  • 5,634
  • 8
  • 45
  • 58
mef_
  • 478
  • 1
  • 12
  • 31

2 Answers2

1

You can hack support for a with statement into Ruby:

http://www.ruby-forum.com/topic/128781#574402

(I've seen this in VBScript, not sure if any other languages support it out of the box).

Andy Waite
  • 10,785
  • 4
  • 33
  • 47
0

No, you can't use capybara's within functionality with site_prism.

Nat Ritmeyer
  • 5,634
  • 8
  • 45
  • 58