记录阿里巴巴QA架构组成长点滴。2008年关键词为效率,技术,影响力!QA/测试架构师定义:开发和设计测试框架测试库;纵横全局的考虑产品的功能,设计复杂的测试系统;负责研发某一项特定的测试技术;为公司考虑如何提高测试效率。领导公司测试技术的发展和测试策略上的方向,关注整个公司的测试部门的问题,前瞻性的考虑未来的版本的测试策略和技术。测试架构师计划/设计测试平台,关注着产品的测试过程,提供咨询服务,影响到公司内的测试机构测试社区,以及开发机构等,对产品各个方面施加深远而正确的影响,最终提高整体软件质量。

快速生成页面对象,高效开发watir脚本

上一篇 / 下一篇  2008-10-28 19:57:18 / 个人分类:开源工具与新技术研究

By Wiston Li

在watir对象识别时,需要借助第三方工具来进行页面对象识别,下面的方法类似QTP描述性编程

生成某类型的对象集合,因而从控制台上可以批量获得对象属性。

实际上在watir中已经给出部分show_object的方法,下面代码主要给出watir暂且不提供对

input tag的对象解析的解决方案。

=begin rdoc
      功能目的:计算某对象的xpath
      输入参数及描述:object
      返回参数及描述:
      调用方法:               
=end
    def calculate_xpath(object)
      s = ""
      curr = object
      s = "/#{curr.invoke("tagName")}[#{get_index(curr)}]" + s
      par = curr.invoke("parentElement")
      while par.invoke("tagName").downcase != "body"
        s = "/#{par.invoke("tagName")}[#{get_index(par)}]" + s
        par = par.invoke("parentElement")
      end
      return s.gsub(/\[1\]/, "").downcase
    end

=begin rdoc
      功能目的:计算某对象的xpath tag中索引
      输入参数及描述:object
      返回参数及描述:
      调用方法:               
=end

    def get_index(currObj)
      par = currObj.invoke("parentElement")
      valuecurr =  currObj.invoke("uniqueID")
      valuepar = par.invoke("uniqueID")
      currtagname = currObj.invoke('tagName').downcase
      count = 0
      par.invoke("children").each { |i|
        val = i.invoke('tagName').downcase
        if val.eql?(currtagname)
          count += 1
          return count if valuecurr.eql?("#{i.invoke("uniqueID")}")
        end
      }
    end

   
=begin rdoc
   
      功能目的:生成当前document中对象集合
      输入参数及描述:objecttype生成指定的对象类型, props=nil 属性名称
      返回参数及描述:
      调用方法:
               
=end
   
    def show_inputs( objecttype, props=nil )
    
      props = ["type","id","name","value","tabIndex","readonly"] unless props
  
  
      divs = document.getElementsByTagName("INPUT")
      puts "Found #{divs.length} Input tags"
      s = ""
      index = 0
      divs.each do |d|
        val = d.invoke('type').downcase
        case  objecttype
        when "edit"
          result=val.eql?("text") || val.eql?("password")
        when "button"
          result=val.eql?("submit")|| val.eql?("button")
        when "checkbox"
          result=val.eql?("checkbox")
        when "radio"
          result=val.eql?("radio")
        end
      
        if result
          index += 1
          s = "#{index} "
          props.each_with_index { |prop,i|
            begin
              s += prop +":" + d.invoke(prop) + " | "
            rescue
              #puts "got error - #{prop}"
            end
          }
          s = s + "Xpath: " + calculate_xpath(d)
          puts s
        end
      end
    end

  end
end


TAG: 开源工具与新技术研究

 

评分:0

我来说两句

日历

« 2024-03-26  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 153174
  • 日志数: 163
  • 文件数: 1
  • 建立时间: 2008-02-26
  • 更新时间: 2008-12-10

RSS订阅

Open Toolbar