您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
ruby+selenium-webdriver自動化測試系列
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2013/4/11 14:06:04 ] 推薦標簽:

邏輯與數(shù)據(jù)分離

方法:運用yaml,讀取配置文件中測試數(shù)據(jù)

1.D盤新建文件夾test004,test004文件夾下創(chuàng)建文件夾action、config、spec、tool。

action文件夾中新建文件login_main_page.rb

config文件夾中新建文件login_data.yml

spec文件夾中新建文件login_spec.rb

tool文件夾中新建文件login_dialog.rb

2.login_dialog.rb文件內(nèi)容與上一篇“面向?qū)ο缶幊?rdquo;中l(wèi)ogin_dialog.rb內(nèi)容一致

3.login_main_page.rb文件內(nèi)容與上一篇“面向?qū)ο缶幊?rdquo;中l(wèi)ogin_main_page.rb內(nèi)容一致

4.login_data.yml文件中編寫如下內(nèi)容:
 
data:
  mainPage:
    url: http://www.soso.com
    title: 搜搜更懂你
 
  login:
    wrong:
      username: test
      password: test
      message: 您輸入的帳號或密碼不正確,請重新輸入。意見反饋

5.login_spec.rb文件中編寫如下內(nèi)容:
 
#encoding: utf-8
require "rspec"
require 'yaml'
require 'selenium-webdriver'
 
require File.dirname(__FILE__)+'/../action/login_main_page'
require File.dirname(__FILE__)+'/../tool/login_dialog'
 
describe "soso login" do
  include LoginDialog
  before(:all) do
    @problem=YAML.load(File.open(File.dirname(__FILE__)+'/../config/login_data.yml'))
    @dr=Selenium::WebDriver.for :firefox
    @url=@problem["data"]["mainPage"]["url"]
    #@url='http://www.soso.com'
    @dr.get @url
  end
  before(:each) do
    @login_element=LoginMainPage.new(@dr)
  end
  after(:each) do
      close_browser
  end
 
  it "should return username and password is wrong" do
    @login_element.login(@problem["data"]["login"]["wrong"]["username"],@problem["data"]["login"]["wrong"]["password"])
    err_message.should eql (@problem["data"]["login"]["wrong"]["message"])
  end
end

6.命令行運行命令:

cd d: est004

rspec -f doc

得到如下結(jié)果:
?
soso login
  should return username and password is wrong
 
Finished in 9.23 seconds
1 example, 0 failures

  運行通過

上一頁1234567下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd