A Page Object Model DSL for Capybara 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.
在 cucumber 中使用 SitePrism 需要加入依赖
1
2
3
4
require 'capybara'
require 'capybara/cucumber'
require 'selenium-webdriver'
require 'site_prism'
其实只要在 Gemfile 中加入以下 gem 即可:
1
2
3
gem "cucumber-rails"
gem "capybara"
gem "site_prism", "~> 2.4"
使用同样非常简单:
login_page.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
classLoginPage < SitePrism::Page
set_url "/login"
element :username_input_field, "input[name='username']"
element :password_input_field, "input[name='password']"
element :login_button, "button[name='login']"
deflogin_withusername, password
username_input_element.type username
password_input_element.type username
login_button.click
end
end
login_stepdef.rb
1
2
3
4
5
6
7
8
Given /^I am in the home page$/ do
@login_page = LoginPage.new # 不用传 driver 哦~
@login_page.load
end
When /^I login with usernmae "test"and password "test"$/ do|name, password|