Added screenshot support.

This commit is contained in:
Martin Edenhofer 2015-05-04 08:13:14 +02:00
parent 7ecb82c324
commit 7863118515

View file

@ -69,10 +69,19 @@ class TestCase < Test::Unit::TestCase
def teardown
return if !@browsers
@browsers.each { |hash, local_browser|
screenshot( :browser => local_browser, :comment => 'teardown' )
browser_instance_close(local_browser)
}
end
def screenshot(params)
instance = params[:browser] || @browser
comment = params[:comment] || ''
filename = "tmp/#{Time.zone.now.strftime("screenshot_%Y_%m_%d__%H_%M_%S")}_#{comment}_#{instance.hash}.png"
log('screenshot', {:filename => filename})
instance.save_screenshot(filename)
end
=begin
username = login(
@ -95,8 +104,12 @@ class TestCase < Test::Unit::TestCase
element = instance.find_elements( { css: '#login input[name="username"]' } )[0]
if !element
screenshot( :browser => instance, :comment => 'login_failed' )
raise 'No login box found'
end
screenshot( :browser => instance, :comment => 'login' )
element.clear
element.send_keys( params[:username] )
@ -112,8 +125,10 @@ class TestCase < Test::Unit::TestCase
sleep 4
login = instance.find_elements( { css: '.user-menu .user a' } )[0].attribute('title')
if login != params[:username]
screenshot( :browser => instance, :comment => 'login_failed' )
raise 'login failed'
end
screenshot( :browser => instance, :comment => 'login_ok' )
assert( true, 'login ok' )
login
end
@ -138,10 +153,12 @@ class TestCase < Test::Unit::TestCase
sleep 1
login = instance.find_elements( { css: '#login' } )[0]
if login
screenshot( :browser => instance, :comment => 'logout_ok' )
assert( true, 'logout ok' )
return
end
}
screenshot( :browser => instance, :comment => 'logout_failed' )
raise 'no login box found, seems logout was not successfully!'
end
@ -159,6 +176,7 @@ class TestCase < Test::Unit::TestCase
instance = params[:browser] || @browser
instance.get( params[:url] )
screenshot( :browser => instance, :comment => 'location' )
end
=begin
@ -175,6 +193,7 @@ class TestCase < Test::Unit::TestCase
instance = params[:browser] || @browser
if instance.current_url !~ /#{Regexp.quote(params[:url])}/
screenshot( :browser => instance, :comment => 'location_check_failed' )
raise "url #{instance.current_url} is not matching #{params[:url]}"
end
assert( true, "url #{instance.current_url} is matching #{params[:url]}" )
@ -192,7 +211,9 @@ class TestCase < Test::Unit::TestCase
log('reload', params)
instance = params[:browser] || @browser
screenshot( :browser => instance, :comment => 'reload_before' )
instance.navigate.refresh
screenshot( :browser => instance, :comment => 'reload_after' )
end
=begin
@ -237,6 +258,7 @@ class TestCase < Test::Unit::TestCase
instance = params[:browser] || @browser
if !instance.find_elements( { css: params[:css] } )[0]
screenshot( :browser => instance, :comment => 'exists_failed' )
raise "#{params[:css]} dosn't exist, but should"
end
true
@ -256,6 +278,7 @@ class TestCase < Test::Unit::TestCase
instance = params[:browser] || @browser
if instance.find_elements( { css: params[:css] } )[0]
screenshot( :browser => instance, :comment => 'exists_not_failed' )
raise "#{params[:css]} exists but should not"
end
true
@ -681,6 +704,7 @@ class TestCase < Test::Unit::TestCase
element = instance.find_elements( { partial_link_text: data[:title] } )[0]
if !element
screenshot( :browser => instance, :comment => 'open_task_failed' )
raise "no task with title '#{data[:title]}' found"
end
element.click
@ -760,6 +784,7 @@ class TestCase < Test::Unit::TestCase
end
sleep 0.5
}
screenshot( :browser => instance, :comment => 'watch_for_failed' )
raise "'#{params[:value]}' found in '#{text}'"
end
@ -816,6 +841,7 @@ wait untill text in selector disabppears
end
sleep 1
}
screenshot( :browser => instance, :comment => 'disappear_failed' )
raise "#{params[:css]}) still exsists"
end
@ -928,6 +954,7 @@ wait untill text in selector disabppears
end
sleep 1
}
screenshot( :browser => instance, :comment => 'overview_create_failed' )
raise 'overview creation failed'
end
@ -962,6 +989,7 @@ wait untill text in selector disabppears
instance.find_elements( { css: 'a[href="#ticket/create"]' } )[0].click
element = instance.find_elements( { css: '.active .newTicket' } )[0]
if !element
screenshot( :browser => instance, :comment => 'ticket_create_failed' )
raise 'no ticket create screen found!'
end
sleep 1
@ -1051,11 +1079,13 @@ wait untill text in selector disabppears
number: number,
}
sleep 3 # wait until notify is gone
screenshot( :browser => instance, :comment => 'ticket_create_ok' )
return ticket
end
end
sleep 1
}
screenshot( :browser => instance, :comment => 'ticket_create_failed' )
raise "ticket creation failed, can't get zoom url (current url is '#{ instance.current_url }')"
end
@ -1204,6 +1234,7 @@ wait untill text in selector disabppears
end
}
if !found
screenshot( :browser => instance, :comment => 'ticket_update_discard_message_failed' )
raise 'no discard message found'
end
end
@ -1219,6 +1250,7 @@ wait untill text in selector disabppears
begin
text = instance.find_elements( { css: '.content.active .js-reset' } )[0].text
if !text || text.empty?
screenshot( :browser => instance, :comment => 'ticket_update_ok' )
return true
end
rescue
@ -1226,6 +1258,7 @@ wait untill text in selector disabppears
end
sleep 1
}
screenshot( :browser => instance, :comment => 'ticket_update_failed' )
raise 'unable to update ticket'
end
@ -1292,6 +1325,7 @@ wait untill text in selector disabppears
sleep 1
number = instance.find_elements( { css: '.active .page-header .ticket-number' } )[0].text
if number !~ /#{params[:number]}/
screenshot( :browser => instance, :comment => 'ticket_open_by_overview_failed' )
raise "unable to search/find ticket #{params[:number]}!"
end
sleep 1
@ -1339,6 +1373,7 @@ wait untill text in selector disabppears
instance.find_element( { partial_link_text: params[:number] } ).click
number = instance.find_elements( { css: '.active .page-header .ticket-number' } )[0].text
if number !~ /#{params[:number]}/
screenshot( :browser => instance, :comment => 'ticket_open_by_search_failed' )
raise "unable to search/find ticket #{params[:number]}!"
end
sleep 1
@ -1414,6 +1449,7 @@ wait untill text in selector disabppears
instance.find_element( { partial_link_text: params[:value] } ).click
name = instance.find_elements( { css: '.active h1' } )[0].text
if name !~ /#{params[:value]}/
screenshot( :browser => instance, :comment => 'organization_open_by_search_failed' )
raise "unable to search/find org #{params[:value]}!"
end
assert( true, "org #{params[:value]} found" )
@ -1443,6 +1479,7 @@ wait untill text in selector disabppears
instance.find_element( { partial_link_text: params[:value] } ).click
name = instance.find_elements( { css: '.active h1' } )[0].text
if name !~ /#{params[:value]}/
screenshot( :browser => instance, :comment => 'user_open_by_search_failed' )
raise "unable to search/find user #{params[:value]}!"
end
assert( true, "user #{params[:term]} found" )
@ -1548,6 +1585,7 @@ wait untill text in selector disabppears
end
sleep 1
}
screenshot( :browser => instance, :comment => 'sla_create_failed' )
raise 'sla creation failed'
end
@ -1594,6 +1632,7 @@ wait untill text in selector disabppears
end
sleep 1
}
screenshot( :browser => instance, :comment => 'text_module_create_failed' )
raise 'text module creation failed'
end
@ -1637,6 +1676,7 @@ wait untill text in selector disabppears
end
sleep 1
}
screenshot( :browser => instance, :comment => 'signature_create_failed' )
raise 'signature creation failed'
end
@ -1707,6 +1747,7 @@ wait untill text in selector disabppears
sleep 1
return true
}
screenshot( :browser => instance, :comment => 'group_create_failed' )
raise 'group creation failed'
end