该自动化测试框架分三个模块:Test用例、Control控制层、Tools工具类、model总控。
① [Info]:代表该用例执行成功![error]代表失败![warn]代表警告!
② TiStone:代表执行用例名称
③ Login successful!:描述或捕获的value值,以“!”结尾
④ 001011:返回码
4.统一用例名称,应与输出②保持一致
涉及依赖:
require 'watir-webdriver' require 'watir-webdriver-performance'
页面加载性能监控
1.times do b.goto("https://192.168.10.1/web") load_secs = b.performance.summary[:response_time]/1000 puts "Load Time: #{load_secs} seconds." End
功能成败判别
if b.text.include? 'T_100M' #捕获web属性value值 #后续操作 puts "①[info]②TiStone ③Login successful!000000" else #后续操作 #输出错误码 puts "①[error]②TiStone ③Login failed!001011" end
参数化提取
class BasicNumber def initialize(number,name) @number = number @name = name end def add(x) @number + x end end
涉及依赖:
load 'Linux.rb' load 'MySql.rb'
具体实现与Tools通信,做一个信息传输的枢纽。
涉及依赖:
require 'net/ssh' require 'scp/ssh' require "test/unit"
关联Linux
#ip/用户名/密码 host = "192.168.48.233" username = "root" password = "root" #调用linux命令 server_cmd1 = 'tail -1000 /home/log/web.log | grep ERROR' server_shell= 'sh /home/wyong/w.sh'
关联MySql
具体实现略…
单元测试
class TC_MyTest < Test::Unit::TestCase def test_add n=BasicNumber.new(10) assert_equal(134,n.add(4),"This test about add is failure!") end end
涉及依赖:
load Control_用例名称.rb'
统一调用
t = Control_用例名称.new test_methods = t.public_methods.grep(/^test_/) test_methods.each do |test| t.send(test) end