Ruby-based watir-webdriver Automated Testing Solution and Implementation (4), watirwebdriver

Source: Internet
Author: User

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

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.