Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage when submitting forms #51

Closed
andyw8 opened this issue Oct 11, 2013 · 7 comments
Closed

Usage when submitting forms #51

andyw8 opened this issue Oct 11, 2013 · 7 comments

Comments

@andyw8
Copy link
Contributor

andyw8 commented Oct 11, 2013

Hi Nat!

I have a usage question that I couldn't see covered by the README.

Say you have a form, which redirects on a successful post, so there are two page object classes, NewWidget and ShowWidget.

Is the intention that site_prism automatically knows which page object class to use, based on the URL? Or do you need to be explicit? For example, is this the intended approach:

@new_widget_page = Pages::NewWidget.new
@new_widget_page.load
@new_widget_page.name = "foo"
@new_widget_page.submit

@show_widget_page = Pages::ShowWidget.new
@show_widget_page.load
expect(@show_widget_page).to be_displayed # verify the URL is correct
expect(@show_widget_page.message).to eq 'Widget created!'
@andyw8
Copy link
Contributor Author

andyw8 commented Oct 11, 2013

(edited the original post to correct a few things)

@tmertens
Copy link
Contributor

@andyw8 Your implementation looks correct. You must explicitly specify which page you are interacting with.

@andyw8
Copy link
Contributor Author

andyw8 commented Oct 11, 2013

Ok. So how do I avoid using a page model which potentially doesn't correspond to the page that was actually rendered? Should I be checking displayed? before calling load in each place where I expect to be redirected?

@tmertens
Copy link
Contributor

Can you give me an example? I'm not sure I understand how you could
'potentially' use a page model different than the page expected. If you are
writing tests, you should know in advance what page you will be landing on
after performing some action.

e.g. If I click the 'Login' link on the home page, I expect to be
redirected to the login page and hence I know to a LoginPage object for
interactions corresponding to the Login page.

Can you provide a simple example of where this fails for you?

On Fri, Oct 11, 2013 at 3:18 PM, Andy Waite notifications@github.comwrote:

Ok. So how do you avoid using a page model which potentially doesn't
correspond to the actual page being rendered? Should I be checking
displayed? before calling load in each place where I expect to be
redirected?


Reply to this email directly or view it on GitHubhttps://github.com//issues/51#issuecomment-26168973
.

@tmertens
Copy link
Contributor

I should add that if you are expecting to be redirected by some action
(e.g. home_page.login_link.click ), you shouldn't be calling
'LoginPage#load' at all as it will override the login_link click redirect
action and simply tell Capybara to load the login page's URL as specified
in the LoginPage class rather than following the actual redirect from the
click.

e.g. assuming we have HomePage and LoginPage classes:

let(:home_page) { HomePage.new }
let(:login_page) { LoginPage.new }

context "Login Link"
  scenario "redirects to the login page"
    home_page.load
    expect(home_page).to be_displayed
    home_page.login_link.click
    expect(login_page).to be_displayed
  end
end

On Fri, Oct 11, 2013 at 3:25 PM, Tim M tim@filmchicago.org wrote:

Can you give me an example? I'm not sure I understand how you could
'potentially' use a page model different than the page expected. If you are
writing tests, you should know in advance what page you will be landing on
after performing some action.

e.g. If I click the 'Login' link on the home page, I expect to be
redirected to the login page and hence I know to a LoginPage object for
interactions corresponding to the Login page.

Can you provide a simple example of where this fails for you?

On Fri, Oct 11, 2013 at 3:18 PM, Andy Waite notifications@github.comwrote:

Ok. So how do you avoid using a page model which potentially doesn't
correspond to the actual page being rendered? Should I be checking
displayed? before calling load in each place where I expect to be
redirected?


Reply to this email directly or view it on GitHubhttps://github.com//issues/51#issuecomment-26168973
.

@andyw8
Copy link
Contributor Author

andyw8 commented Oct 11, 2013

Got it! Wasn't obvious from the README, I'll send a PR to add that info if I have a chance.

@natritmeyer
Copy link
Owner

@andyw8 happy for me to close this? Good to hear from you again :)

@andyw8 andyw8 closed this as completed Oct 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants