Class: Actir::TestCase

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/actir.rb

Overview

测试用例基础类,读取配置文件定义常量

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.startupObject

$testsuites = []



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/actir.rb', line 22

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

Instance Method Details

#screenshot_if_failed(browser) ⇒ Object

若用例执行失败则进行截图,在每个用例的teardown方法中直接调用,传入浏览器对象实例



48
49
50
51
52
53
54
55
56
# File 'lib/actir.rb', line 48

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