44$:. unshift ( CUPRITE_ROOT + "/lib" )
55
66require "bundler/setup"
7-
87require "rspec"
8+
99require "capybara/spec/spec_helper"
1010require "capybara/cuprite"
1111
1515Capybara . register_driver ( :cuprite ) do |app |
1616 options = { }
1717 options . merge! ( inspector : true ) if ENV [ "INSPECTOR" ]
18- options . merge! ( logger : StringIO . new ) if ENV [ "TRAVIS " ]
18+ options . merge! ( logger : StringIO . new ) if ENV [ "CI " ]
1919 driver = Capybara ::Cuprite ::Driver . new ( app , options )
2020 process = driver . browser . process
2121
22+ puts ""
2223 puts "Browser: #{ process . browser_version } "
2324 puts "Protocol: #{ process . protocol_version } "
2425 puts "V8: #{ process . v8_version } "
@@ -80,17 +81,18 @@ module TestSessions
8081 end
8182
8283 config . around do |example |
83- if ENV [ "TRAVIS " ]
84+ if ENV [ "CI " ]
8485 session = @session || TestSessions ::Cuprite
8586 session . driver . browser . logger . truncate ( 0 )
8687 session . driver . browser . logger . rewind
8788 end
8889
8990 example . run
9091
91- if ENV [ "TRAVIS " ] && example . exception
92+ if ENV [ "CI " ] && example . exception
9293 session = @session || TestSessions ::Cuprite
9394 raise session . driver . browser . logger . string
95+ save_exception_aftifacts ( session . driver . browser , example . metadata )
9496 end
9597 end
9698
@@ -100,4 +102,19 @@ module TestSessions
100102 end
101103
102104 Capybara ::SpecHelper . configure ( config )
105+
106+ def save_exception_aftifacts ( browser , meta )
107+ time_now = Time . now
108+ filename = File . basename ( meta [ :file_path ] )
109+ line_number = meta [ :line_number ]
110+ timestamp = "#{ time_now . strftime ( '%Y-%m-%d-%H-%M-%S.' ) } #{ '%03d' % ( time_now . usec /1000 ) . to_i } "
111+
112+ screenshot_name = "screenshot-#{ filename } -#{ line_number } -#{ timestamp } .png"
113+ screenshot_path = "#{ ENV [ "CIRCLE_ARTIFACTS" ] } /screenshots/#{ screenshot_name } "
114+ browser . screenshot ( path : screenshot_path , full : true )
115+
116+ log_name = "ferrum-#{ filename } -#{ line_number } -#{ timestamp } .txt"
117+ log_path = "#{ ENV [ "CIRCLE_ARTIFACTS" ] } /logs/#{ log_name } "
118+ File . open ( log_path , 'wb' ) { |file | file . write ( FERRUM_LOGGER . string ) }
119+ end
103120end
0 commit comments