Created
March 24, 2011 06:57
-
-
Save qichunren/884682 to your computer and use it in GitHub Desktop.
这个用来测试业务流程操作,以test_开头的public方法都会执行
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require 'rubygems' | |
require 'capybara' | |
require 'capybara/dsl' | |
# require 'capybara/rspec' | |
Capybara.run_server = false | |
Capybara.current_driver = :selenium | |
Capybara.app_host = 'http://cqrorx.com:3000' | |
Capybara.default_wait_time = 4 | |
# Capybara.configure do |config| | |
# config.run_server = false | |
# config.current_driver = :selenium | |
# config.app_host = 'http://cqrorx.com:3000' | |
# end | |
module MyCapybaraTest | |
class Test | |
include Capybara | |
def login | |
page.visit('/admin_session/new') | |
page.fill_in('帐号', :with => 'admin') | |
page.fill_in('密码', :with => 'admin') | |
page.click_button('登录') | |
end | |
# 测试首页跳转到登录页面 | |
def test_root_page | |
page.visit('/') | |
puts "登录页面没有登录两个字" if not page.has_content?('登录') | |
puts "没有登录就跳转到登录页面" if page.has_css?('h2.page_title', :text => '员工登录') | |
end | |
# 测试员工登录 | |
def test_login | |
login | |
puts "登录正常" if page.has_content?('登录成功') | |
end | |
# 测试通过用户认证 | |
def test_pass_user_validation | |
login | |
page.visit('/users') | |
un_passed_element = page.find(:xpath, "//table[@class='list']/tbody/tr[@title='未通过电话认证']/td") | |
un_passed_user_id = un_passed_element.text | |
un_passed_element.click_link(un_passed_user_id) | |
page.evaluate_script('window.confirm = function() { return true; }') | |
# page.driver.browser.switch_to.alert 这个不起效果 | |
page.click_link("通过电话认证") | |
puts "认证成功" if page.has_content?("认证成功") | |
end | |
def test_create_new_contract | |
login | |
page.visit('/users') | |
un_passed_element = page.find(:xpath, "//table[@class='list']/tbody/tr[@title='未通过电话认证']/td") | |
un_passed_user_id = un_passed_element.text | |
un_passed_element.click_link(un_passed_user_id) | |
page.evaluate_script('window.confirm = function() { return true; }') | |
# page.driver.browser.switch_to.alert 这个不起效果 | |
page.click_link("通过电话认证") | |
# 现在转向合同签订页面 | |
page.visit("/contracts") | |
page.click_link("签订新合同") | |
page.fill_in('客户号', :with => "#{un_passed_user_id}") | |
page.select '竞拍', :from => '合同类型' | |
page.fill_in('拍品数量', :with => 10) | |
page.fill_in('合同备注', :with => '这是一个自动测试的合同') | |
page.click_button('保存') | |
puts "合同签订成功" if page.has_content?("合同签订成功") | |
end | |
end | |
end | |
t = MyCapybaraTest::Test.new | |
test_methods = [] | |
t.public_methods.each do |name| | |
test_methods << name if name =~ /^test_/ | |
end | |
test_methods.each do |test_method| | |
t.send(test_method) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment