您的位置:軟件測(cè)試 > 開(kāi)源軟件測(cè)試 > 開(kāi)源功能測(cè)試工具 > Watir
10分鐘學(xué)會(huì)自動(dòng)化測(cè)試框架--Cucumber + Watir
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2014/3/26 13:05:08 ] 推薦標(biāo)簽:Watir 測(cè)試框架 自動(dòng)化

   相應(yīng)的step文件需要做相應(yīng)的修改:
復(fù)制代碼

1require File.join(File.dirname(__FILE__), "google-page")
2
3Given /^I amongoogle home page$/do
4@page = GooglePage.new
5end
6
7When/^I searchfor'([^"]*)'$/ do |search_text|
8@page.search search_text
9end
10
11Then /^I should be able to view the search result of '([^"]*)'$/do|result_text|
12@page.has_text result_text
13end

復(fù)制代碼

     運(yùn)行cucumber,一個(gè)新的瀏覽器被打開(kāi),顯示結(jié)果與(三)中相同。

(六)加入角色用戶

   既然是行為驅(qū)動(dòng),既然是模擬用戶實(shí)際操作,那么直接對(duì)Page對(duì)象進(jìn)行操作也顯得不夠了,于是我們引入了角色用戶User對(duì)象,對(duì)于擁有多種用戶角色的網(wǎng)站來(lái)說(shuō)特別實(shí)用。加入U(xiǎn)ser對(duì)象之后,step文件中不再出現(xiàn)對(duì)Page對(duì)象的直接引用,而是在User對(duì)象的行為方法中進(jìn)行引用,定義User對(duì)象如下(user.rb):
復(fù)制代碼

1require File.join(File.dirname(__FILE__), "google-page")
2
3class User
4def initialize
5@browser = Watir::Browser.new :chrome
6end
7
8def visit_google
9@page = GooglePage.new(@browser)
10end
11
12def search_text text
13@page.search text
14end
15
16def assert_text_exist text
17@page.has_text text
18end

復(fù)制代碼

   feature文件保持不變,在step文件用User代替Page:
復(fù)制代碼

1require File.join(File.dirname(__FILE__), "user")
2
3Given /^I amongoogle home page$/do
4@user = User.new
5@user.visit_google
6end
7
8When/^I searchfor'([^"]*)'$/ do |search_text|
9@user.search_text search_text
10end
11
12Then /^I should be able to view the search result of '([^"]*)'$/do|result_text|
13@user.assert_text_exist result_text
14end

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