Ruby-based watir-webdriver Automated Testing Solution and Implementation (4), watirwebdriver
Subsequent Ruby-based watir-webdriver Automated Testing Solution and implementation (3)Http://www.cnblogs.com/javame/p/4259468.htmlto continue... first, let's recall our system architecture and then talk about the specific implementation.
The automated testing framework consists of three modules: Test cases, Control layer, Tools, and model Master Control.
Test Case
① [Info]: indicates that the use case is successfully executed! [Error] indicates an error! [Warn] indicates a warning!
② TiStone: name of the execution case
③ Login successful! : Description or captured value, with "!" End
④ 001011: return code
4. Unified Use Case name, which should be consistent with output ②
Control layer Tools class Index general Control solution design Test case
Dependencies involved:
require 'watir-webdriver'
require 'watir-webdriver-performance'
Page loading performance monitoring
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
Function success/failure identification
if b.text.include? 'T_100M'
#Capture web property value
#Next operation
puts "① [info] ②TiStone ③Login successful! 000000"
else
# Follow-up
#Output error code
puts "① [error] ②TiStone ③Login failed! 001011"
end
Parameterized Extraction
class BasicNumber
def initialize(number,name)
@number = number
@name = name
end
def add(x)
@number + x
end
end
Control Layer
Dependencies involved:
load 'Linux.rb'
load 'MySql.rb'
Specifically, communication with Tools is a hub for information transmission.
Tools
Dependencies involved:
require 'net/ssh'
require 'scp/ssh'
require "test/unit"
Associate with Linux
# ip / username / password
host = "192.168.48.233"
username = "root"
password = "root"
#Call linux command
server_cmd1 = 'tail -1000 /home/log/web.log | grep ERROR'
server_shell = 'sh /home/wyong/w.sh'
Associate MySql
Specific implementation...
Unit Test
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
Model General Control
Dependencies involved:
Load Control _ Use Case name. rb'
Unified Call
t = Control_instance name.new
test_methods = t.public_methods.grep(/^test_/)
test_methods.each do |test|
t.send(test)
end