【工作经历:阿里巴巴搜索技术研发中心QA ,百度新产品测试部QA】
【领域:测试分析,自动化测试,性能测试,安全测试 】
【个人定位:高级测试工程师+培训师+领域产品专家】
发布新日志
-
2009-10-18 02:44:21
最近对DSL感兴趣,就使用ruby简单的做了一个试验。
是为了简化p4p后台测试的操作。让TC编写起来更容易些。
做了一个小小的demo。如果成型的话,测试人员就可以这样写TC了。
这是一段检查百度搜索,然后验证的小demo。(实际测试当然不会这样子了)
host "www.baidu.com"
port 80
page "s"
field "wd","美女"
field "sourceid","Mozilla-search"
get
check_content "美女"
check_content "淫秽词"
把以上内容存到文件里,系统就可以自动运行了。
登陆baidu,查询“美女”,然后检查里面是否有“淫秽词”。
DSL定义代码如下
# To change this template, choose Tools | Templates # and open the template in the editor.
require 'open-uri' class MyDSL def self.dsl_accessor(*symbols) symbols.each { |sym| class_eval %{ def #{sym}(*val) if val.empty? @#{sym} else @#{sym} = val.size == 1 ? val[0] : val end end } } end def method_missing(sym, *args) self.class.dsl_accessor sym puts "method missing #{sym}, #{args}" send(sym, *args) end attr_accessor :query dsl_accessor :test def self.load(filename) dsl = new dsl.instance_eval(File.read(filename), filename) puts File.read(filename) dsl end def self.loads(filename) dsl = new dsl.instance_eval(filename) dsl end
def field(field_string,value) puts "#{field_string}=#{value}" if ! @query @query="#{field_string}=#{value}" else @query="#{@query}&#{field_string}=#{value}" end puts @query
end def get puts 'get' @request="http://#{@host}:#{@port}/#{@page}?#{@query}" puts @request @result=open(@request) end
def check_content(s) tmp=@result.read.scan(s).uniq if tmp.length!=0 puts "found" puts tmp else puts "not found" end end
def post puts 'post'
end
end#class MyDSL
dsl=MyDSL.loads(' host "www.baidu.com" port 80 page "s" field "wd","xxxxxxx" field "sourceid","Mozilla-search" field "yy",0.222 parameter 0.55,2.1,[2,3,4],{:a=>7,:b=>8,:c=>9} get check_content "xxx" check_content "ffffffffffffff" ') p dsl p dsl.instance_variables
|
查看(1008)
评论(0)
收藏
分享
管理
-
2009-05-15 21:55:36
写出来的ruby脚本,交给别人的话,还要让别人安装ruby,就太麻烦了。
使用exerb可以轻松的把ruby代码转换为exe文件。
exerb会跟踪脚本的执行,然后把相应的需要的库集成到exe文件中。里面肯定是包含了一个小小的ruby解析器了。
用法
mkexy test.rb
exerb test.exy
就会生成exe文件了。可能还有点大,你可以使用upx,aspack等压缩工具进行压缩下就ok了。
虽然大了点,但是将就着使用了。
接触ruby的第一件头痛的事情。以后要受制于日本人了。呵呵。无奈公司选择了ruby。
$Id: README.en.txt,v 1.1 2006/06/20 01:51:20 yuya Exp $
Exerb is the software which converts scripts and extension-libraries of Ruby
into an executable file of Microsoft Windows which can execute alone and
independently.
...but, I'm sorry. The English documentation is under construction.If you want any information about Exerb, please read the following URI.
http://www.google.com/search?q=Exerb
Thanks.
查看(619)
评论(0)
收藏
分享
管理
-
2009-05-15 20:40:42
有个项目组成员,在讨论数据难以处理。
需要把一个文件中的所有与化工有关的词全部标注起来。用个中括号括起来即可。
因为数据量比较大,他们需要申请资源做一个月。
最短也需要一个星期。
我想这完全是技术问题啊。很简单的东西,于是,就私下和他联系。要了处理,使用ruby写了个小脚本。
学习ruby很久了。但是还是一直用python写东西。很少用ruby的。这是我转ruby以来的第一次写应用脚本。比较有纪念意义。呵呵。
代码如下。超级简单。
最近用shell用的太多了。本来想用python写的,结果python都忘记的差不多了。
现在,公司里用ruby比较多,而且ruby比python有不少优点,还是锻炼下ruby吧。
def kk(c,d)
f_new=File.new('new.csv', 'w')
IO.foreach(d) {
|dline|
dline.strip!
IO.foreach(c) {
|cline|
cline.strip!
dline.gsub!(cline, "["+cline+"]")
}
puts "dline= "+dline
f_new.puts(dline)
}
end
kk('D:\Work\文档\c.csv','D:\Work\文档\d.csv')
查看(481)
评论(0)
收藏
分享
管理
-
2009-02-04 17:35:07
接到了一系列的通知。
全面转向ruby。
看了一天,发现ruby的确有不少闪光点。
这下不用担心了,ruby了。不迟疑了。
以后还要研究watir。
查看(350)
评论(0)
收藏
分享
管理