注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

星期五

明天不上班

 
 
 

日志

 
 
关于我

一个特立独行的Java程序员,比较宅,上上网,写博客,听音乐,看电影。

网易考拉推荐

使用Ruby进行自动化测试(2)  

2012-01-07 18:22:27|  分类: Ruby |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
这几天,一直在学习ruby 和 watir,虽然还不是很熟,但是我已经很强烈的感觉到ruby这门语言的简洁,高效和强大。
因为,我们公司的前端开发,是我们自己写的框架,产品Web结构基本固定,所以可以使用watir,写一些固定的函数去处理,页面测试。
今天没事写了一些,因为初学ruby,所以只是一些简单的函数(但是对于我们产品, 都是可以重用的)

# This file funtions for GUI Page Test
# encoding: UTF-8

# watir just support IE , watir-webdriver support FireFox 3.6 or low version , IE , Chrome
require 'rubygems'

# get Browser Obj
# browserName firefox, ie
def getBrowserByName(browserName)
if(browserName == 'firefox') then
require 'watir-webdriver'
firefox = Watir::Browser.new :firefox
return firefox
else
require 'watir'
ie = Watir::IE.new
ie.maximize
return ie
end
end

#login PMC GUI
def loginPMCGUI(broswer, username, password)
broswer.text_field(:name => "j_username").set password
broswer.text_field(:name => "j_password").set username
broswer.link(:id => "startBut").click
sleep(3)
end


#click tree node
#example : Resources , Devices
def clickTreeNode(broswer, nodeText)
broswer.span(:text => nodeText).click
sleep(1)
end

#click action button
def clickActionButton(broswer, buttonId)
broswer.link(:id => buttonId)
end


#get iframe
def getIframe(broswer, iframeId)
return broswer.frame(:id, iframeId)
end

#get data table Object
def getDataTableObject(broswer, tableId)
tableId = "datatablebody" + tableId
return broswer.div(:id => tableId)
end

def getDataTablePagingObject(broswer, tableId)
tableId = "pagingheader" + tableId
return broswer.div(:id => tableId)
end

def getDataTableOptionObject(broswer, tableId)
tableId = "pageTopHeaderSettingDiv_" + tableId
return broswer.div(:id => tableId)
end

#check paging
def checkPaging(pagingObj)
pagingObj.span(:title, /^Next/).click
sleep(2)
pagingObj.span(:title, /^Previous/).click
sleep(2)
pagingObj.span(:title, /^Last/).click
sleep(2)
pagingObj.span(:title, /^First/).click
sleep(2)
end

#check options

def checkFilterOptions(optionObj, tableId)
optionObj.span(:text => "Options").click
optionObj.link(:id => "pageTopHeaderSettingDiv_A_"+ tableId +"_0").click
end

def findSomething(broswer, id, value, tableId)
dialog = broswer.div(:id => "filterDiv_" + tableId)
dialog.text_field(:id => id).set value
dialog.span(:text => "Find").click
end

def filterSomething(broswer, id, value, tableId)
dialog = broswer.div(:id => "filterDiv_" + tableId)
dialog.text_field(:id => id).set value
dialog.span(:text => "Filter").click
end

def checkPreferenceOptions(optionObj, tableId)
optionObj.span(:text => "Options").click
optionObj.link(:id => "pageTopHeaderSettingDiv_A_"+ tableId +"_1").click
end

def getPreferenceDialog(broswer)
return broswer.div(:id => "dialogBoxPanle_dataTablePreference")
end

def updatePageSize(dialog, num)
dialog.text_field(:id => "pagePerRowSize").set num
end
#column not value is text
def updateSort(dialog, column, dir)
dialog.select_list(:id => "sortBy").set column
dialog.select_list(:id => "orderBy").set dir
end

def closePreferenceDialog(dialog)
dialog.span(:text => "Close").click
end
#
def applyPreferenceDialog(dialog)
dialog.span(:text => "Apply").click
sleep(1)
end

#select list table row
def selectRowByID(table, id)
table.div(:text => id ).click
end

#get Tab view
def getTabObject(broswer, id)
return broswer.div(:id => id)
end
#select tab by tabId is li id
def selectTabById(tabObj, id)
tabObj.li(:id => id).click
end

使用这些函数,便可以处理一些自己的页面

# encoding: UTF-8

require './hpc_gui.rb'
# log
require 'log4r'
include Log4r

# create a logger named 'GUILog' that logs to stdout
GUILog = Logger.new 'GUILog'
GUILog.outputters = Outputter.stdout

browser = getBrowserByName 'ie'

browser.goto("http://172.17.9.161:8080/")

loginPMCGUI(browser, 'admin', 'admin')
GUILog.info "Login Success"

clickTreeNode(browser, 'Devices')
clickTreeNode(browser, 'phone')

listIframe = getIframe(browser, 'center_generalTableLayout_contentDivSpace_iframe')

paging = getDataTablePagingObject(listIframe, 'phone_table')

checkPaging(paging)

options = getDataTableOptionObject(listIframe, 'phone_table')

checkFilterOptions(options, 'phone_table')

findSomething(browser, 'find_name_filterDiv_phone_table','HTC001', 'phone_table')

checkPreferenceOptions(options, 'phone_table')

preDialog = getPreferenceDialog(browser)

updatePageSize(preDialog, '20')

updateSort(preDialog, 'Model', 'Ascending')

applyPreferenceDialog(preDialog)

closePreferenceDialog(preDialog)

tableObj = getDataTableObject(listIframe, "phone_table")

selectRowByID(tableObj, "1")

sleep(2)

tabObj = getTabObject(browser, "bottom_generalTableLayout_contentDivSpace_tabview")
selectTabById(tabObj, "PLATFORM_widget_TabView_bottom_generalTableLayout_contentDivSpace_tabview_tabTargetIdgeneralTableAlert")

代码还需要重构,但是已经可以对产品,进行一个初步测试。

参考资料:1.http://wiki.openqa.org/display/WTR/Selection+Boxes
                  2.http://qa.taobao.com/?p=2933
  评论这张
 
阅读(891)| 评论(0)
推荐

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017