Dynamic page URL

page-object-gem, pageobjects, ruby, watir-webdriver

Solution

You can get the url for the page using the method current_url. On your test above are you trying to determine if you are on the correct page? If that is the case I might suggest using one of the two "expected" methods - expected_title and expected_element.

The page_url method is more than likely not the choice for you if you need to navigate to a url dynamically. What you might try instead is add a method to your page that does something like this:

class ViewPostPage
  include PageObject

  URL = "site.com/post/"

  expected_title  "The expected title"

  def navigate_to_post_with_id(id)
    navigate_to "#{URL}/#{id}"
  end

end

And in your test

on_page(ViewPostPage) do |page|
  page.navigate_to_post_with_id @id
  page.should have_expected_title
end

Let me know if this helps.

Problem

I have a page with URL that is dynamic. Let's call it view post page. URL for post 1 is `site.com/post/1` and for post 2 is `site.com/post/2`. This is what I do at the moment to check if I am at the right page. The page: ``` class ViewPostPage include PageObject def self.url "site.com/post/" end end ``` Cucumber step: ``` on(ViewPostPage) do |page| @browser.url.should == "#{page.class.url}#{@id}" end ``` Is there a better way? Do you even bother checking the entire URL, or just the `site.com/post/` part? I am using the latest page-object gem (0.6.6). Update Even bigger problem is going directly to the page that has dynamic URL. The page: ``` class ViewPostPage include PageObject def self.url "site.com/post/" end page_url url end ``` Cucumber step: ``` visit ViewPostPage ``` What I do now is to change the Cucumber step to: ``` @browser.goto "#{ViewPostPage.url}#{@id}" ``` It would be great if there was a way for the page to know it's ID, but I have not figured out yet how to do it.

Original source