Sha256: d8f810c30c012acb4bbbe308043b8f46178a38f83cf9a323a53491b8e40985b1

Contents?: true

Size: 1.84 KB

Versions: 18

Compression:

Stored size: 1.84 KB

Contents

require 'test/unit'
require 'watir-webdriver'
require 'selenium-webdriver'
lib = File.dirname(__FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'actir/config'
require 'actir/data'
require 'actir/initializer'
require 'actir/remote'
require 'actir/basic_page'
require 'actir/parallel_tests/parallel_tests'
require 'actir/webdriver/browser'
require 'actir/script/cookies_baidu'
require 'actir/version'

module Actir
  
  #测试用例基础类,读取配置文件定义常量
  class TestCase < Test::Unit::TestCase
    class << self
      # $testsuites = []
      def startup
        # 执行用例前,将测试套名字和用例名输出
        suite_name = self.to_s
        if (suite_name != "Actir::TestCase" && suite_name != "BaseTest")
          puts "[suite start]"
          puts "suitname: #{suite_name}\n"
          test_methods = instance_methods.grep(/^test_/).map {|case_name|case_name.to_s}
          test_methods.each do |testcase|
            puts "testcase: #{testcase}\n"
          end
          puts "[suite end]"
        end
      end
    end

    #IP地址的正则表达式
    num = /\d|[01]?\d\d|2[0-4]\d|25[0-5]/  
    ip = /^(#{num}\.){3}#{num}/ 
    #遍历所有的入参,取出IP作为传给测试脚本的IPAddress
    ARGV.each do |arg| 
      if arg =~ ip
        $address = arg
      end
    end

    #若用例执行失败则进行截图,在每个用例的teardown方法中直接调用,传入浏览器对象实例
    def screenshot_if_failed(browser)
        @screen_path = File.join($project_path, 'screenshots')
        unless self.passed?
            Dir::mkdir(@screen_path) if not File.directory?(@screen_path)
            #time = Time.now.strftime('%Y%m%d-%H%M%S')
            screenshot = @screen_path + "/FAILED_#{self.name}.png"
            browser.screenshot.save screenshot
      end
    end
  end
  
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
actir-1.4.3.5 lib/actir.rb
actir-1.4.3.4 lib/actir.rb
actir-1.4.3.3 lib/actir.rb
actir-1.4.3.2 lib/actir.rb
actir-1.4.3.1 lib/actir.rb
actir-1.4.3 lib/actir.rb
actir-1.4.2 lib/actir.rb
actir-1.4.1.3 lib/actir.rb
actir-1.4.1.2 lib/actir.rb
actir-1.4.1.1 lib/actir.rb
actir-1.4.1 lib/actir.rb
actir-1.4.0 lib/actir.rb
actir-1.3.1 lib/actir.rb
actir-1.3.0 lib/actir.rb
actir-1.2.8 lib/actir.rb
actir-1.2.7 lib/actir.rb
actir-1.2.6 lib/actir.rb
actir-1.2.5 lib/actir.rb