多個測試用例
1.D盤新建文件夾test005,文件結(jié)構(gòu)與“邏輯與數(shù)據(jù)分離中一致”
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: 您輸入的帳號或密碼不正確,請重新輸入。意見反饋
allNotExist:
username:
password:
message: 您還沒有輸入帳號!意見反饋
usernameNotExist:
username:
password: test
message: 您還沒有輸入帳號!意見反饋
passwordNotExist:
username: test
password:
message: 您還沒有輸入密碼!意見反饋
5.login_spec.rb文件中編寫如下內(nèi)容:
#encoding: utf-8
require "rspec"
require 'yaml'
require 'selenium-webdriver'
require File.dirname(__FILE__)+'/../tool/login_dialog'
require File.dirname(__FILE__)+'/../action/login_main_page'
describe "soso login" do
include LoginDialog
#before(:all) do
# @problem=YAML.load(File.open(File.dirname(__FILE__)+'/http://www.cnblogs.com/sosoLogin/config/login_data.yml'))
# @dr=Selenium::WebDriver.for :firefox
# @url=@problem["data"]["mainPage"]["url"]
# @dr.get @url
#end
before(:each) do
@problem=YAML.load(File.open(File.dirname(__FILE__)+'/../config/login_data.yml'))
@dr=Selenium::WebDriver.for :firefox
@url=@problem["data"]["mainPage"]["url"]
@dr.get @url
@login_element=LoginMainPage.new(@dr)
end
after(:each) do
close_browser
end
it "should should open soso url" do
@dr.title.should eql (@problem["data"]["mainPage"]["title"])
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
it "should return username and password are not exist" do
@login_element.login(@problem["data"]["login"]["allNotExist"]["username"],@problem["data"]["login"]["allNotExist"]["password"])
err_message.should eql (@problem["data"]["login"]["allNotExist"]["message"])
end
it "should return username is not exist" do
@login_element.login(@problem["data"]["login"]["usernameNotExist"]["username"],@problem["data"]["login"]["usernameNotExist"]["password"])
err_message.should eql (@problem["data"]["login"]["usernameNotExist"]["message"])
end
it "should return password is not exist" do
@login_element.login(@problem["data"]["login"]["passwordNotExist"]["username"],@problem["data"]["login"]["passwordNotExist"]["password"])
err_message.should eql (@problem["data"]["login"]["passwordNotExist"]["message"])
end
end
6.命令行運行命令:
cd d: est005
rspec -f doc
得到如下結(jié)果:
?
soso login
should should open soso url
should return username and password is wrong
should return username and password are not exist
should return username is not exist
should return password is not exist
Finished in 49.11 seconds
5 examples, 0 failures
運行通過