2

I have been doing selenium automation in C# for almost 1 year. I need to learn siteprism using capybara. When I was going through the documentation of siteprism i can't relate section with page objects.

I have implemented annotations and pagefactory. But i cannot relate sections in siteprism with anything in selenium.

1

Page objects and Sections do not relate to Selenium in anyway. They are building blocks for structuring your automated UI test-cases and can be combined with Selenium if that is your test-driver.

Seems the SitePrism documentation and examples are quite clear what sections are used for:

define sections used on multiple pages or multiple times on one page

They just added this section concept to the existing page-object concept, applying the DRY pattern seems logical and might be something you would do yourself one way or the other anyways.

-1
  1. SitePrism gives you a simple, clean and semantic DSL for describing your site using the Page Object Model pattern, for use with Capybara in automated acceptance testing.

  2. Before we go into SitePrism, let’s talk about page objects, because page objects are central to understanding the philosophy behind SitePrism.

A Page Objects Primer

Page Objects encapsulate the implementation details of the page (in our example, an HTML document) and expose a specific API that allows you, the tester, to test elements on the page. This encapsulation of details make page objects especially handy as a testing tool.

Let’s illustrate this with an example. Here, we have a page object that inherits from the SitePrism::Page class:

(class LoginPage < SitePrism::Page
  element :username_field, "input[name='username']"
  element :password_field, "input[name='password']"
  element :flash, "div.flash"

  def log_in(username, password)
    username_field.set(username)
    password_field.set(password)
    click_on('Log In')
  end
end

class ProfilePage < SitePrism::Page
  element :flash, "div.flash"

  def flash_message
    flash.text
  end
end)

Let’s see how we can use our example page object:

( feature 'Login' do
  let(:login_page) { LoginPage.new }

  before do
    login_page.load
  end

  scenario 'a successful login' do
    profile_page = login_page.log_in('admin', 'password')
    expect(profile_page.flash_message).to eq("Ohai! Welcome Admin.")
  end
end )

The above code snippet illustrates how we can use SitePrism’s page objects in our RSpec feature tests.

Getting Site Prism Into Your Project

Installing Site Prism is a painless affair. In your Gemfile:

( group :test do
  # ...
  gem 'rspec-rails', '~> 3.0.0'
  gem 'capybara-rails'
  gem 'site_prism'
  # ...
end )

Note that for the example project, we are going to use RSpec 3. Also, you will need Capybara in order to use SitePrism

  • I have done some R & D on siteprism and i learned section are section of pages which is repeating on multiple pages, or repeating on same pages. So, if i create a separate class for section in C# then it will be same as the working of siteprism. – Dark Matter Jan 19 '17 at 12:15
  • -1 because the answer is not about sections, which is what the original question is about. – Niels van Reijmersdal Feb 12 '17 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.