Dynamic Page URL

I have a page with a dynamic URL. Let him view the message page. The URL for post is 1 - site.com/post/1, and for post 2 - site.com/post/2.

This is what I am doing at the moment to check if I am on the correct page.

Page:

class ViewPostPage
  include PageObject

  def self.url
    "site.com/post/"
  end
end

Cucumber pitch:

on(ViewPostPage) do |page|
  @browser.url.should == "#{page.class.url}#{@id}"
end

Is there a better way? Are you even trying to check the whole url or only part site.com/post/?

I am using the latest page-object gem (0.6.6).

Update

An even bigger problem goes directly to the page with a dynamic URL.

Page:

class ViewPostPage
  include PageObject

  def self.url
    "site.com/post/"
  end
  page_url url
end

Cucumber pitch:

visit ViewPostPage

Now I have to change the Cucumber step to:

@browser.goto "#{ViewPostPage.url}#{@id}"

It would be great if the page knew this identifier, but I still did not understand how to do this.

+3
source share
3

URL- , current_url. , ? , "" - expected_title expected_element.

page_url , URL-. , - :

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

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

, .

+4

URL- Object Object.

:

ViewPostPage

  include PageObject

      expected_url  "The expected URL"

  def initialize

     has_expected_url?

   end

+1

As far as I know, it is #page_urlintended to open the corresponding page along with the initialization of the page object. To make sure you are on the right page, you can try using the method #expected_title.

In addition, it may be useful to you. When a character is passed on #page_url, it calls the appropriate method, so it is best to use it. I have not tried, but here are some links for you.

0
source

All Articles