




已阅读5页,还剩7页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
一.按钮ie.button(:id, one).clickie.button(:name, clickme).clickie.button(:value, Click Me).clickie.button(:src, /doit/).click二.复选框ie.checkbox(:id, one).setie.checkbox(:id, one).clearie.checkbox(:name, checkme).setie.checkbox(:name, checkme).clear三.链接Pickaxeie.link(:id, one).clickie.link(:name, book).clickie.link(:text, Pickaxe).clickie.link(:href, /titles/ruby/).click四.单选框ie.radio(:id, one).setie.radio(:id, one).clearie.radio(:name, clickme).setie.radio(:name, clickme).clear五.下拉框 Web Testing in Ruby is funie.select_list(:id, one).set(is fun)ie.select_list(:name, selectme).set(is fun)ie.select_list(:id, one).clearSelectioncontents = ie.select_list(:id, one).getAllContents六.选择列表 Web Testing in Ruby is funie.select_list(:id, one).set(Web Testing)ie.select_list(:id, one).set(in Ruby)ie.select_list(:id, one).set(is fun)ie.select_list(:id, one).clearSelection七.输入框ie.text_field(:id, one).set(Watir World)ie.text_field(:id, one).clearie.text_field(:name, typeinme).set(Watir World)ie.text_field(:name, typeinme).clear八.表单1) 按钮提交表单 ie.button(:id, one).click2) 无按钮提交表单 ie.form(:id, one).submitie.form(:name, loginform).submitie.form(:action, login).submitie.form(:method, get).submit3) 多重框架 ie.show_framesie.frame(:name, menu)Click Menu Itemie.frame(:name, menu).link(:text, Click Menu Item).clickie.frame(:name, frame).frame(:name, nested_frame)ie.logger.level = Logger:ERROR #关闭浏览器错误警告九.索引ie.radio(:index, 1).setie.radio(:index, 2).clear十.RRBie = Watir:IE.start /ie = Watir:IE.find(:title, Google) #通过窗口标题查找ie = Watir:IE.find(:url, ) #find by urlie = Watir:IE.find(:title,/REGEX/) #find by title matching REGEXie = Watir:IE.find(:title,/) #attach to any current IE instanceie.show_all_objectsie.titleie.text_field(:name, test_text).flash#闪动十次所选元素十一.多样属性ie.link(:text = Employees, :index = 2).click十二.正则表达式ie.link(:url, /shtml/).clickie.link(:url, javascript:PC_7_0_G7_selectTerritory(0,%20amend).click=ie.link(:url, /selectTerritory(0,%20amend)/).click=ie.link(:url, /javascript.*selectTerritory(0,%20amend)/).click十三. XPath1) 表格 First Image Second Image Third Image ie.tables.each do |t| # since you dont have IDs, look at every table for i in 1.t.row_count # for every row in this table ti.each do |cell| # for every column in this row, look at its contents if cell.image(:src, /3.jpg/).exists? # if true, this is your cell puts cell.text end end endend2) 链接click meie.link(:xpath,/ahref=test.htm/).text # = click me3) Map # get the underlying object and execute click methodie.element_by_xpath(/areacontains(href , PieChart.html)/).click4) Code Designa) rexml_document_object函数返回了一个REXML文档对象.b) create_rexml_document_objectThis is a private function and is called only if REXML document is not created before for that HTML page. This function is called internally by rexml_document_object by checking the variable rexmlDomobject which gets set to nil when new page is rendered in the browser. If you execute multiple XPath queries on the same source page, then the object is created once on first request and reused hence forth. c) elements_by_xpath(XPath)This function resolves the XPath query, provided by the user and returns all qualified elements. The XPath query should be compatible with REXML i.e. it should contain only those attributes or functions that are supported by REXML. The function gets the complete path from the root element for all qualified elements locally using REXML. Now this path is passed to elements_by_absolute_xpath and finally qualified elements are returned back to the caller.d) element_by_absolute_xpath(XPath)This is the private function that maps the elements complete path (passed XPath) to actual element in IE DOM tree. It traverses over the IE DOM starting from the tag following the passed complete path. We call IHtmlElement:getChildNodes function to get all the child nodes and select the one of our interest as indicated by the complete path. We loop till we have traversed the complete path and finally desired element is returned back.e) html_source(element, htmlString, spaceString)This function traverses the IE DOM model and creates a string that contains the HTML displayed on the browser. Same as you see with view source option when you right click on the browser. This function is initially called with element as body. During processing the function gets all the attributes of the element using IHtmlElement:outerHtml. Then the attributes of element are cleaned. If element cant have child nodes then the tag is made as self closing tag, else we just close the tag. Then this function is called recursively on the child nodes of this element. While unwinding the stack created during recursion we again check if element can have child nodes if yes then we place a closing tag that was left opened else we simple return. Script and comments tags are not taken into consideration.f) tokenize_tagline(outerHtml)This function scans the outer HTML of the element and returns an array of tokens. Token could be either tagName or = or attribute name or attribute value. Attribute value could be either quoted string or single word.Input:Output: An array with values.input, type, =, radio, name, =, WATiR, checkedg) all_tag_attributes(outerHtml)This function is called by HTML source function to get all the attributes of the tag. This function calls tokenize_tagline to separate attributes name and value. Now this function cleans the outer HTML by placing quote around the attribute values. If only attribute name is present then it attribute value is set to same as attribute name.Input:Output:h) xml_escapeThis function is used to escape the characters that are not considered as valid data in XML. For eg: &, , , etc.i) More information on REXMLThe XPath that is returned by REXML is of the format:/html/body/table/tbody/tr2/td2/div/table/tbody/tr3/td1/a2The XPath string returned by REXML provides information about the location of the element from the root element for which XPath query is given.For e.g.:If the above provided string is returned as a result then it means that the element resides inside HTML (root element), body tag inside html (element1 inside element2: this means element2 tag inside element1 tag obtained in previous step), table tag inside body, tbody tag inside table, second tr tag inside tbody, second td tag inside row, div tag inside td, table tag inside div, tbody tag inside table, third tr tag inside tbody, first td tag inside tr, second a tag inside td.十四. Validating Test Results1) 验证对象是否存在if ie.contains_text(Reached test verification point.) puts: Test passed. Page contains the text: Reached test verification point.else puts: Test failed! Page didnt contain text: Reached test verification point.End2) 双击Fire_event(DOUBLE)十五. Test Unit1) Using Test:Unit Assertionsrequire test/unit1.新建类class TC_myTest Test:Unit:TestCase # fill in Test Case methods hereend2.新建方法def test_myTestCase # fill in method body with Watir code and assertion hereend这个用例定义看起来像这样:class TC_myTest Test:Unit:TestCase def test_ myTestCase # Watir code and assertion here end def test_anotherTestCase # Watir code and assertion here end def test_aTestCase # Watir code and assertion here endend3.使用assert断言assert(ie.contains_text(Reached test verification point.)water能测试许多对象的状态.我们能使用断言去检查对象是否存在,是可用还是不可用,又或者DOM告诉浏览器的对象任何其他状态,如果你想在Test:Unit类中约束用例,使用IE实体类,必须使用另外一个类变量ie,或者一个全局变量$ie,它允许测试脚本在整个测试用例中使用IE实体类4.设置和分解这两个方法名是为 Test:Unit而保留的. 它们分别对应在类的开始和结尾执行def setup # fill in code that will run before every test case hereenddef teardown # fill in code that will run after every test case hereend5.为什么我的脚本运行错误class SampleTest Test:Unit:TestCase def test_login # login test code, etc end def test_account # account test code, etc endend第二个方法 test_account将会在test_login之前执行.class SampleTest Watir:TestCase def test_login # login test code, etc end def test_account # account test c
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 儿童演讲美术课件
- 城市公共车位规划方案
- 房屋浴室改造方案(3篇)
- 塔吊基础焊接加固方案
- 儿童洗牙知识培训课件
- 仓库物资调度方案
- 世界卒中日健康宣教核心要点
- 2025版碧桂园:新型城镇化工程合同体系及合约规划手册
- 二零二五年度车辆租赁抵押借款合同模板
- 二零二五年爆破拆除与城市景观修复合同
- MT/T 1222-2024液压支架再制造工程设计指南
- GB/T 30134-2025冷库管理规范
- 2025年7月浙江省普通高中学业水平考试历史仿真模拟卷01(含答案)
- 2024-2025学年人教版PEP六年级下学期期末试卷(含答案含听力原文无音频)
- 2025-2030年中国聚脲涂料行业市场现状供需分析及投资评估规划分析研究报告
- 一级建造师考试安全管理试题及答案
- 《成人糖尿病患者的高血糖危象:共识报告》-学习与应用
- 遵义社工面试真题及答案
- 金属材料的断裂和断裂韧性
- 镀锌板知识课件
- 2025-2030偏光成像相机行业市场现状供需分析及重点企业投资评估规划分析研究报告
评论
0/150
提交评论