testability-driver-runner 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. data/bin/sierra +19 -0
  2. data/bin/tdrunner +17 -0
  3. data/lib/tdrunner.rb +208 -0
  4. data/lib/tdrunner.yml +1 -0
  5. data/lib/tdrunner_cucumber.rb +222 -0
  6. data/lib/tdrunner_cucumber_runners.rb +35 -0
  7. data/lib/tdrunner_file_finder.rb +45 -0
  8. data/lib/tdrunner_monitor.rb +473 -0
  9. data/lib/tdrunner_profile.rb +416 -0
  10. data/lib/tdrunner_test_unit.rb +433 -0
  11. data/rakefile +135 -0
  12. data/readme +186 -0
  13. data/websi/README +243 -0
  14. data/websi/Rakefile +10 -0
  15. data/websi/app/controllers/application_controller.rb +29 -0
  16. data/websi/app/controllers/report_editor/test_run/cases_controller.rb +307 -0
  17. data/websi/app/controllers/report_editor_controller.rb +25 -0
  18. data/websi/app/controllers/websi_controller.rb +478 -0
  19. data/websi/app/controllers/websi_script.rb +26 -0
  20. data/websi/app/controllers/websi_support.rb +142 -0
  21. data/websi/app/helpers/application_helper.rb +22 -0
  22. data/websi/app/helpers/report_editor/report_editor_helper.rb +26 -0
  23. data/websi/app/helpers/report_editor/test_run/cases_helper.rb +26 -0
  24. data/websi/app/helpers/websi_helper.rb +21 -0
  25. data/websi/app/views/layouts/application.rhtml +17 -0
  26. data/websi/app/views/websi/execution.html.erb +28 -0
  27. data/websi/app/views/websi/index.html.erb +23 -0
  28. data/websi/app/views/websi/profile.html.erb +30 -0
  29. data/websi/app/views/websi/results.html.erb +30 -0
  30. data/websi/app/views/websi/tests.html.erb +23 -0
  31. data/websi/app/views/websi/weights.html.erb +16 -0
  32. data/websi/config/boot.rb +129 -0
  33. data/websi/config/database.yml +22 -0
  34. data/websi/config/environment.rb +60 -0
  35. data/websi/config/environments/development.rb +36 -0
  36. data/websi/config/environments/production.rb +47 -0
  37. data/websi/config/environments/test.rb +47 -0
  38. data/websi/config/initializers/backtrace_silencers.rb +26 -0
  39. data/websi/config/initializers/inflections.rb +29 -0
  40. data/websi/config/initializers/mime_types.rb +24 -0
  41. data/websi/config/initializers/new_rails_defaults.rb +40 -0
  42. data/websi/config/initializers/session_store.rb +34 -0
  43. data/websi/config/locales/en.yml +5 -0
  44. data/websi/config/routes.rb +62 -0
  45. data/websi/db/development.sqlite3 +0 -0
  46. data/websi/db/seeds.rb +26 -0
  47. data/websi/doc/README_FOR_APP +2 -0
  48. data/websi/log/development.log +0 -0
  49. data/websi/log/production.log +0 -0
  50. data/websi/log/server.log +0 -0
  51. data/websi/log/test.log +0 -0
  52. data/websi/public/report_editor/test_run/_index.html +12 -0
  53. data/websi/public/robots.txt +5 -0
  54. data/websi/public/stylesheets/tdriver_report_style.css +220 -0
  55. data/websi/public/tests/config/web_profile.sip +0 -0
  56. data/websi/public/tests/example_profile.sip +8 -0
  57. data/websi/public/tests/tdrunner.yml +3 -0
  58. data/websi/public/tests/web_profile.sip +8 -0
  59. data/websi/public/tests/websi_parameters.xml +4 -0
  60. data/websi/script/about +4 -0
  61. data/websi/script/console +3 -0
  62. data/websi/script/dbconsole +3 -0
  63. data/websi/script/destroy +3 -0
  64. data/websi/script/generate +3 -0
  65. data/websi/script/performance/benchmarker +3 -0
  66. data/websi/script/performance/profiler +3 -0
  67. data/websi/script/plugin +3 -0
  68. data/websi/script/runner +3 -0
  69. data/websi/script/server +3 -0
  70. data/websi/test/functional/websi_controller_test.rb +27 -0
  71. data/websi/test/performance/browsing_test.rb +28 -0
  72. data/websi/test/test_helper.rb +57 -0
  73. data/websi/test/unit/helpers/websi_helper_test.rb +23 -0
  74. metadata +199 -0
data/websi/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ require 'tasks/rails'
@@ -0,0 +1,29 @@
1
+ ############################################################################
2
+ ##
3
+ ## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
+ ## All rights reserved.
5
+ ## Contact: Nokia Corporation (testabilitydriver@nokia.com)
6
+ ##
7
+ ## This file is part of Testability Driver.
8
+ ##
9
+ ## If you have questions regarding the use of this file, please contact
10
+ ## Nokia at testabilitydriver@nokia.com .
11
+ ##
12
+ ## This library is free software; you can redistribute it and/or
13
+ ## modify it under the terms of the GNU Lesser General Public
14
+ ## License version 2.1 as published by the Free Software Foundation
15
+ ## and appearing in the file LICENSE.LGPL included in the packaging
16
+ ## of this file.
17
+ ##
18
+ ############################################################################
19
+
20
+ # Filters added to this controller apply to all controllers in the application.
21
+ # Likewise, all the methods added will be available for all controllers.
22
+
23
+ class ApplicationController < ActionController::Base
24
+ helper :all # include all helpers, all the time
25
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
26
+
27
+ # Scrub sensitive parameters from your log
28
+ # filter_parameter_logging :password
29
+ end
@@ -0,0 +1,307 @@
1
+ ############################################################################
2
+ ##
3
+ ## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
+ ## All rights reserved.
5
+ ## Contact: Nokia Corporation (testabilitydriver@nokia.com)
6
+ ##
7
+ ## This file is part of Testability Driver.
8
+ ##
9
+ ## If you have questions regarding the use of this file, please contact
10
+ ## Nokia at testabilitydriver@nokia.com .
11
+ ##
12
+ ## This library is free software; you can redistribute it and/or
13
+ ## modify it under the terms of the GNU Lesser General Public
14
+ ## License version 2.1 as published by the Free Software Foundation
15
+ ## and appearing in the file LICENSE.LGPL included in the packaging
16
+ ## of this file.
17
+ ##
18
+ ############################################################################
19
+
20
+ require 'nokogiri'
21
+ require 'tdriver'
22
+ require 'zip/zip'
23
+ require 'zip/zipfilesystem'
24
+
25
+ class ReportEditor::TestRun::CasesController < ApplicationController
26
+ include TDriverReportCreator
27
+
28
+ def initialize()
29
+ @report_editor_path=Dir.getwd+'/public/report_editor/test_run'
30
+ @report_rebuilder=TestRun.new
31
+ end
32
+
33
+ def initialize_variables_for_rebuilding_report()
34
+ begin
35
+ storage_file='all_cases.xml'
36
+
37
+ file=@report_editor_path +'/'+ storage_file
38
+
39
+ if File.exist?(file)
40
+ io = File.open(file, 'r')
41
+ xml_data = Nokogiri::XML(io){ |config| config.options = Nokogiri::XML::ParseOptions::STRICT }
42
+ io.close
43
+ xml_data.root.xpath("//tests/test").each do |node|
44
+ group=node.search("group").text
45
+ @report_rebuilder.set_generic_reporting_groups('Test suite:'+group+'|')
46
+ group=''
47
+ end
48
+
49
+ xml_data=nil
50
+
51
+ end
52
+ rescue Nokogiri::XML::SyntaxError => e
53
+
54
+ puts "caught exception when reading results: #{e}"
55
+
56
+ end
57
+ end
58
+
59
+ def rebuild_html_report()
60
+ initialize_variables_for_rebuilding_report()
61
+ @report_rebuilder.set_report_folder(@report_editor_path)
62
+
63
+ @report_rebuilder.update_test_case_summary_pages('statistics')
64
+
65
+ @report_rebuilder.update_test_case_summary_pages('all',true)
66
+
67
+ @report_rebuilder.update_test_case_summary_pages('passed',true)
68
+
69
+ @report_rebuilder.update_test_case_summary_pages('failed',true)
70
+
71
+ @report_rebuilder.update_test_case_summary_pages('not run',true)
72
+
73
+ end
74
+
75
+ def write_to_result_storage(data_arr)
76
+
77
+ begin
78
+ while $result_storage_in_use==true
79
+ sleep 1
80
+ end
81
+ $result_storage_in_use=true
82
+ storage_file='all_cases.xml'
83
+
84
+ file=@report_editor_path +'/'+ storage_file
85
+
86
+ if File.exist?(file)
87
+ io = File.open(file, 'r')
88
+ xml_data = Nokogiri::XML(io){ |config| config.options = Nokogiri::XML::ParseOptions::STRICT }
89
+ io.close
90
+ xml_data.root.xpath("//tests/test").each do |node|
91
+ index=node.search("index").text
92
+ selected_data_arr=Array.new
93
+ selected_data=data_arr.assoc('status'+index)
94
+ selected_data_arr << selected_data
95
+ selected_data=data_arr.assoc('comment'+index)
96
+ selected_data_arr << selected_data
97
+ if selected_data!=nil
98
+ selected_data_arr.each do |found_data|
99
+ case found_data[1].to_s
100
+ when 'result'
101
+ status_nodes=node.search("status")
102
+ test_status = Nokogiri::XML::Node.new("status",xml_data)
103
+ test_status.content = found_data[2].to_s
104
+ status_nodes.each do |status_node|
105
+ status_node.replace(test_status)
106
+ end
107
+ when 'comment'
108
+ comment_nodes=node.search("comment")
109
+ test_comment = Nokogiri::XML::Node.new("comment",xml_data)
110
+ test_comment.content = found_data[2].to_s
111
+ comment_nodes.each do |comment_node|
112
+ comment_node.replace(test_comment)
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+ File.open(file, 'w') {|f| f.write(xml_data.to_xml) }
119
+ xml_data=nil
120
+ end
121
+ $result_storage_in_use=false
122
+ rescue Nokogiri::XML::SyntaxError => e
123
+ $result_storage_in_use=false
124
+ puts "caught exception when reading results: #{e}"
125
+
126
+ end
127
+ end
128
+
129
+ def write_data_to_storage(key_arr)
130
+ data_arr=Array.new
131
+ key_arr.each do |key_data|
132
+ if key_data[0].to_s.include?('text_area')
133
+ index_arr=key_data[0].to_s.split('_')
134
+ data_arr << ['comment'+index_arr.first,'comment',key_data[1].to_s]
135
+ elsif key_data[0].to_s.include?('status_select')
136
+ index_arr=key_data[0].to_s.split('_')
137
+ data_arr << ['status'+index_arr.first,'result',key_data[1].to_s]
138
+ end
139
+ end
140
+ write_to_result_storage(data_arr)
141
+ end
142
+
143
+ def save_total_run_results
144
+ key_arr=Array.new
145
+ params.each_key do |key|
146
+ key_arr << [key,params[key]]
147
+ end
148
+ write_data_to_storage(key_arr)
149
+ rebuild_html_report()
150
+ redirect_to :back
151
+ end
152
+
153
+ def zipped_report
154
+ filename = "#{RAILS_ROOT}/public/report_editor/test_run.zip"
155
+
156
+ if File.file?(filename)
157
+ File.delete(filename)
158
+ end
159
+ root="#{RAILS_ROOT}/public/report_editor/test_run"
160
+
161
+
162
+ Zip::ZipFile.open(filename, 'w') do |zipfile|
163
+ Dir["#{root}/**/**"].reject{|f|f==filename}.each do |file|
164
+ zipfile.add(file.sub(root+'/',''),file)
165
+ end
166
+ end
167
+
168
+ filename
169
+ end
170
+
171
+ def read_result_storage(results)
172
+ while $result_storage_in_use==true
173
+ sleep 1
174
+ end
175
+ $result_storage_in_use=true
176
+ begin
177
+ result_storage=nil
178
+ result_storage=Array.new
179
+ storage_file='all_cases.xml'
180
+
181
+ file=@report_editor_path+'/'+storage_file
182
+
183
+ if File.exist?(file)
184
+ io = File.open(file, 'r')
185
+ xml_data = Nokogiri::XML(io){ |config| config.options = Nokogiri::XML::ParseOptions::STRICT }
186
+ io.close
187
+ xml_data.root.xpath("//tests/test").each do |node|
188
+ value=node.search("name").text #0
189
+ group=node.search("group").text #1
190
+ reboots=node.search("reboots").text #2
191
+ crashes=node.search("crashes").text #3
192
+ start_time=node.search("start_time").text #4
193
+ duration=node.search("duration").text #5
194
+ memory_usage=node.search("memory_usage").text #6
195
+ status=node.search("status").text #7
196
+ index=node.search("index").text #8
197
+ log=node.search("log").text #9
198
+ comment=node.search("comment").text #10
199
+ link=node.search("link").text #11
200
+ case results
201
+ when 'passed'
202
+ if @pass_statuses.include?(status)
203
+ result_storage << [value,group,reboots,crashes,start_time,duration,memory_usage,status,index,log,comment,link]
204
+ end
205
+ when 'failed'
206
+ if @fail_statuses.include?(status)
207
+ result_storage << [value,group,reboots,crashes,start_time,duration,memory_usage,status,index,log,comment,link]
208
+ end
209
+ when 'not run'
210
+ if @not_run_statuses.include?(status)
211
+ result_storage << [value,group,reboots,crashes,start_time,duration,memory_usage,status,index,log,comment,link]
212
+ end
213
+ when 'all'
214
+ result_storage << [value,group,reboots,crashes,start_time,duration,memory_usage,status,index,log,comment,link]
215
+ end
216
+ end
217
+ xml_data=nil
218
+ $result_storage_in_use=false
219
+ result_storage
220
+ else
221
+ $result_storage_in_use=false
222
+ result_storage
223
+ end
224
+ rescue Nokogiri::XML::SyntaxError => e
225
+ $result_storage_in_use=false
226
+ puts "caught exception when reading results: #{e}"
227
+ result_storage
228
+ end
229
+ end
230
+
231
+ def test_case_comment(test_case)
232
+ pass_statuses=MobyUtil::Parameter[ :report_passed_statuses, "passed" ].split('|')
233
+ status=test_case[7].to_s
234
+ comment=nil
235
+ if pass_statuses.include?(status)==false
236
+ comment="1) #{test_case[4].to_s} \n \n2) #{test_case[10].to_s}"
237
+ end
238
+ comment
239
+ end
240
+
241
+ def excel_report
242
+ result_data=read_result_storage('all')
243
+ filename = "#{RAILS_ROOT}/public/report_editor/test_run.xls"
244
+ if File.file?(filename)
245
+ File.delete(filename)
246
+ end
247
+ #write data to excel
248
+ #File.open(filename, 'a') do |f|
249
+ # f.puts "Name\tIteration\tIteration Status\tComment"
250
+ # result_data.each do |test_case|
251
+ # f.puts "#{test_case[0].to_s}\t#{test_case[8].to_s}\t#{test_case[7].to_s}\t#{test_case_status(test_case)}"
252
+ # end
253
+ #end
254
+
255
+ require 'win32ole'
256
+ xl = WIN32OLE.new("Excel.Application")
257
+
258
+ xl.Visible = false
259
+
260
+ workbook = xl.Workbooks.Add
261
+ sheet = workbook.Worksheets(1)
262
+ sheet.Range("A1").Select
263
+ xl.ActiveCell.Formula = "Name"
264
+ sheet.Range("B1").Select
265
+ xl.ActiveCell.Formula = "Iteration"
266
+ sheet.Range("C1").Select
267
+ xl.ActiveCell.Formula = "Iteration status"
268
+ i=2
269
+ result_data.each do |test_case|
270
+ sheet.Range("A#{i}").Select
271
+ xl.ActiveCell.Formula = test_case[0].to_s
272
+ sheet.Range("B#{i}").Select
273
+ xl.ActiveCell.Formula = test_case[8].to_s
274
+ sheet.Range("C#{i}").Select
275
+ xl.ActiveCell.Formula = test_case[7].to_s
276
+ comment=test_case_comment(test_case)
277
+ xl.ActiveCell.AddComment comment if comment!=nil
278
+
279
+ i+=1
280
+ end
281
+
282
+ excel_file=filename.gsub('/','\\')
283
+
284
+ workbook.SaveAs(excel_file, -4143)#excel 97-2003 format
285
+ xl.Quit
286
+
287
+ filename
288
+
289
+ end
290
+
291
+ def save_results_to
292
+
293
+ zip_file=zipped_report
294
+
295
+ send_file zip_file, :filename => "test_run.zip"
296
+
297
+ end
298
+
299
+ def export_results_to_excel
300
+
301
+ excel_file=excel_report
302
+
303
+ send_file excel_file, :filename => "test_run.xls"
304
+
305
+ end
306
+
307
+ end
@@ -0,0 +1,25 @@
1
+ ############################################################################
2
+ ##
3
+ ## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
+ ## All rights reserved.
5
+ ## Contact: Nokia Corporation (testabilitydriver@nokia.com)
6
+ ##
7
+ ## This file is part of Testability Driver.
8
+ ##
9
+ ## If you have questions regarding the use of this file, please contact
10
+ ## Nokia at testabilitydriver@nokia.com .
11
+ ##
12
+ ## This library is free software; you can redistribute it and/or
13
+ ## modify it under the terms of the GNU Lesser General Public
14
+ ## License version 2.1 as published by the Free Software Foundation
15
+ ## and appearing in the file LICENSE.LGPL included in the packaging
16
+ ## of this file.
17
+ ##
18
+ ############################################################################
19
+
20
+
21
+ class ReportEditorController < ApplicationController
22
+
23
+
24
+
25
+ end
@@ -0,0 +1,478 @@
1
+ ############################################################################
2
+ ##
3
+ ## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
+ ## All rights reserved.
5
+ ## Contact: Nokia Corporation (testabilitydriver@nokia.com)
6
+ ##
7
+ ## This file is part of Testability Driver.
8
+ ##
9
+ ## If you have questions regarding the use of this file, please contact
10
+ ## Nokia at testabilitydriver@nokia.com .
11
+ ##
12
+ ## This library is free software; you can redistribute it and/or
13
+ ## modify it under the terms of the GNU Lesser General Public
14
+ ## License version 2.1 as published by the Free Software Foundation
15
+ ## and appearing in the file LICENSE.LGPL included in the packaging
16
+ ## of this file.
17
+ ##
18
+ ############################################################################
19
+
20
+ # Used session keys:
21
+ #
22
+ # :default_weights - Hash of loaded tests with weights of 0
23
+ # :exec_amount - Type and number defining how long tests are to be executed
24
+ # :exec_friendly - Human readable text describing selected execution constraints, type and amount
25
+ # :exec_root - Root path for test execution, public/tests
26
+ # :exec_type - Execution control criteria: iterations, timestamp, hours
27
+ # :execute_this - Name of the profile that is to be executed
28
+ # :index_message - Optional message displayed to the user at the index page
29
+ # :load_tc - Load Test::Unit test classes in addition to test methods. True by default.
30
+ # :loaded_amount - Number of iterations/hours/time until tests are executed
31
+ # :loaded_profile_name - Name of the profile if it was loaded from or saved to a file
32
+ # :ordered_enable - Boolean, true if TDRunner should be executed with --ordered
33
+ # :pre_reports - Array of reports existing at the start of test execution
34
+ # :selected_tests - Array of tests that the user has selected
35
+ # :save_message - String, result of the latest save as action.
36
+ # :start_time - Timestamp of test execution start
37
+ # :teardown_enable - Boolean, true if TDRunner should be executed with --teardown
38
+ # :test_keys - Array, contains test names in the order required by the user, for use with :weights
39
+ # :test_path - Path based on which tests are searched for and executed
40
+ # :tests_failed - Boolean, true if loading or selecting of tests failed for some reason
41
+ # :tests_message - Message to be displayed on the tests page
42
+ # :weights - Hash of all tests in the chosen target folder, with user defined weights
43
+
44
+
45
+ require 'tdrunner_profile'
46
+ require 'websi_support.rb'
47
+
48
+
49
+ module TDRunner
50
+ #Class for loading tdrunner exeution profile from tdrunner.yml file
51
+ class TDRunnerProfileLoader
52
+ def get_yml
53
+ tdrunner_yml
54
+ end
55
+ end
56
+ end
57
+
58
+ class WebsiController < ApplicationController
59
+
60
+ def index
61
+
62
+ # reset session
63
+ temp_load_tc = session.fetch( :load_tc, true ) # set to true by default, this setting is carried over when new session is started
64
+ if !session[ :index_message ].nil?
65
+ temp_msg = session[ :index_message ]
66
+ reset_session
67
+ session[ :index_message ] = temp_msg
68
+ else
69
+ reset_session
70
+ end
71
+ session[ :load_tc ] = temp_load_tc
72
+
73
+ session[ :exec_root ] = File.join( Dir.getwd, "public", "tests", "" )
74
+ session[ :loaded_amount ] = ""
75
+ session[ :exec_type ] = ""
76
+
77
+ # load existing test reports
78
+ @existing_profiles = []
79
+
80
+ Dir.chdir(session[ :exec_root ]) do
81
+ pl = TDRunner::TDRunnerProfileLoader.new([])
82
+ @existing_profiles = pl.get_yml.keys
83
+ end
84
+
85
+ @index_files = get_report_names( File.join( session[ :exec_root ], "reports" ) )
86
+
87
+ end
88
+
89
+ def after_index
90
+
91
+ session[ :index_message ] = nil
92
+ redirect_to :action => "tests"
93
+
94
+ end
95
+
96
+ def tests
97
+
98
+ @test_names = []
99
+ @selected_names = []
100
+
101
+ @test_path = nil
102
+
103
+ if !session[ :tests_failed ].nil? and session[ :tests_failed ] == true
104
+ session[ :tests_failed ] = false
105
+ else
106
+ session[ :tests_message ] = nil
107
+ end
108
+
109
+ if params.has_key? :test_path and params[ :test_path ].kind_of? String and !params[ :test_path ].empty?
110
+ @test_path = params[ :test_path ]
111
+ elsif session.has_key? :test_path
112
+ @test_path = session[ :test_path ]
113
+ end
114
+
115
+ if @test_path.kind_of?( String ) && @test_path.empty?
116
+ @test_path = nil
117
+ end
118
+
119
+ # load folder contents if a path was defined when the page was loaded
120
+ if ( !@test_path.nil? && File.exist?( @test_path ) )
121
+
122
+ session[ :load_tc ] = ( params[ :load_tc ] == "true" ? true : false )
123
+
124
+ temp_load = "\"" + @test_path + "\""
125
+ locsie = SupportTDRunner::Main.new()
126
+
127
+ # get features
128
+ @test_names = locsie.features( [ @test_path ] )
129
+ session[ :default_weights ] = {}
130
+ test_keys = []
131
+ @test_names.each do | test_name |
132
+ session[ :default_weights ][ test_name ] = "0"
133
+ test_keys << test_name
134
+ end
135
+
136
+ # get test::unit tests
137
+ tu_tests = []
138
+ Dir.chdir('app/controllers/') do
139
+ search_results = %x[ruby websi_script.rb #{temp_load} ]
140
+ tu_tests = search_results.split("\n")
141
+ end
142
+
143
+ tu_tests.each do | test_name |
144
+ if ( session[ :load_tc ] == false and !test_name.include? "(" )
145
+ # test class, do nothing
146
+ else
147
+ session[ :default_weights ][ test_name ] = "0"
148
+ test_keys << test_name
149
+ end
150
+ end
151
+
152
+ @test_names += test_keys
153
+ session[ :test_keys ] = test_keys
154
+ session[ :test_path ] = @test_path
155
+
156
+ end
157
+
158
+ end
159
+
160
+ def after_tests
161
+
162
+ session[ :selected_tests ] = params[ :selected_tests ]
163
+ session[ :tests_message ] = nil
164
+
165
+ if !params[ :selected_tests ].kind_of? Array or params[ :selected_tests ].empty?
166
+ redirect_to :action => "tests"
167
+ session[ :tests_message ] = "Please select some tests before proceeding."
168
+ session[ :tests_failed ] = true
169
+ else
170
+ redirect_to :action => "weights"
171
+ end
172
+
173
+ end
174
+
175
+ def weights
176
+
177
+ @profile_tests = {}
178
+ if session[ :selected_tests ] != nil
179
+ session[ :selected_tests ].each { | tn | @profile_tests[ tn ] = "1" }
180
+ end
181
+
182
+ end
183
+
184
+ def after_weights
185
+
186
+ session[ :weights ] = session[ :default_weights ].merge params[ :weights ]
187
+
188
+ redirect_to :action => "profile"
189
+
190
+ end
191
+
192
+ def profile
193
+
194
+ @loaded_amount = session[ :loaded_amount ].to_s
195
+ @exec_type = session[ :exec_type ].to_s
196
+
197
+ end
198
+
199
+ def after_profile
200
+
201
+ @exec_type = params[:exec_type]
202
+ @exec_amount = params[:exec_amount]
203
+
204
+ session[ :teardown_enable ] = ( params[ :teardown_enable ] == "true" ? true : false )
205
+ session[ :ordered_enable ] = ( params[ :ordered_enable ] == "true" ? true : false )
206
+
207
+ session[ :exec_type ] = params[ :exec_type ]
208
+ case session[ :exec_type ]
209
+ when "Iterations"
210
+ session[ :exec_amount ] = "-i " + params[ :text_Iterations ]
211
+ if params[ :text_Iterations ] == "1"
212
+ session[ :exec_friendly ] = "The tests will be executed for 1 iteration."
213
+ else
214
+ session[ :exec_friendly ] = "The tests will be executed for " + params[ :text_Iterations ] + " iterations."
215
+ end
216
+ when "Elapsed"
217
+ session[ :exec_amount ] = "-H " + params[ :text_Elapsed ]
218
+ if params[ :text_Elapsed ] == "1"
219
+ session[ :exec_friendly ] = "The tests will be executed for 1 hour."
220
+ else
221
+ session[ :exec_friendly ] = "The tests will be executed for " + params[ :text_Elapsed ] + " hours."
222
+ end
223
+ when "Timestamp"
224
+ session[ :exec_amount ] = "-d \"" + params[ :text_Timestamp ] + "\""
225
+ session[ :exec_friendly ] = "The tests will be executed until " + params[ :text_Timestamp ] + "."
226
+ end
227
+
228
+ save_current_profile( "web_profile" )
229
+ session[ :execute_this ] = "web_profile"
230
+
231
+ redirect_to :action => "execution"
232
+
233
+ end
234
+
235
+ def execution
236
+
237
+ @exec_tests = session[ :weights ]
238
+
239
+ if session[ :save_message ].kind_of? String and !session[ :save_message ].empty?
240
+ @save_message = session[ :save_message ]
241
+ end
242
+
243
+ session[ :save_message ] = nil
244
+ end
245
+
246
+ def after_execution
247
+
248
+ session[ :save_message ] = nil
249
+
250
+ case params[ :submit ]
251
+ when "Save"
252
+
253
+ redirect_to :action => "execution"
254
+
255
+ save_name = params[ :save_as_name ]
256
+ save_name.strip!
257
+ if( save_name.kind_of?( String ) && !save_name.empty? )
258
+
259
+ session[ :loaded_profile_name ] = save_name
260
+ if nil == reg_exp_result = /\W/ =~ save_name
261
+ save_current_profile( save_name )
262
+
263
+ session[ :save_message ] = "Save successful"
264
+ else
265
+ session[ :save_message ] = "Save failed. Invalid character in profile name: \"#{ save_name[ reg_exp_result, 1 ] }\""
266
+ end
267
+
268
+ end
269
+
270
+ else
271
+
272
+ redirect_to :action => 'results'
273
+
274
+ Dir.chdir(session[ :exec_root ]) do
275
+
276
+ @index_files = get_report_names( File.join( session[ :exec_root ], "reports" ) )
277
+ now_string = DateTime.now.to_s
278
+ session[ :pre_reports ] = @index_files
279
+ session[ :start_time ] = now_string[8,2] + "." + now_string[5,2] + "." + now_string[0,4] + " " + now_string[11,2] + ":" + now_string[14,2]
280
+
281
+ websi_params = Nokogiri::XML::Builder.new{
282
+ parameters() {
283
+ parameter( :name => 'report_outputter_path', :value => File.join( session[ :exec_root ], 'reports', '' ) )
284
+ }
285
+ }.to_xml.to_s
286
+
287
+ File.open( File.join( session[ :exec_root ], 'websi_parameters.xml' ), 'w' ) do | param_file |
288
+ param_file.write websi_params
289
+ end
290
+
291
+ #puts "DEBUG: EXECUTING TDRUNNER COMMAND: " << '|tdrunner ' + join_execution_params
292
+ Kernel::open('|tdrunner ' + join_execution_params )
293
+
294
+ end
295
+
296
+ end
297
+
298
+ end
299
+
300
+ def results
301
+
302
+ @index_files = get_report_names( File.join( session[ :exec_root ], "reports" ) )
303
+
304
+ @new_reports = @index_files - session[ :pre_reports ]
305
+
306
+ end
307
+
308
+ def after_results
309
+
310
+ # No pause/stop functionality yet
311
+ case params[ :submit ]
312
+ when "Refresh"
313
+ redirect_to :action => "results"
314
+ # when "Pause"
315
+ # redirect_to :action => "results"
316
+ # when "Stop"
317
+ # redirect_to :action => "results"
318
+ else
319
+ redirect_to :action => "results"
320
+ end
321
+
322
+ end
323
+
324
+ def load_profile
325
+
326
+ session[ :test_path ] = nil
327
+ session[ :index_message ] = nil
328
+
329
+ prof_name = params[ :prof_name ]
330
+ lp = nil
331
+ begin
332
+ Dir.chdir( session[ :exec_root ] ) do
333
+ pl = TDRunner::TDRunnerProfileLoader.new( [] )
334
+ sp = pl.args_from( prof_name )
335
+ lp = TDRunner::TDRunnerParameters.new( sp )
336
+ end
337
+
338
+ case lp.execution_mode
339
+ when "-i"
340
+ session[ :exec_type ] = "Iterations"
341
+ session[ :loaded_amount ] = lp.lpt_run
342
+ when "-H"
343
+ session[ :exec_type ] = "Elapsed"
344
+ session[ :loaded_amount ] = lp.lpt_run
345
+ when "-d"
346
+ session[ :exec_type ] = "Timestamp"
347
+ session[ :loaded_amount ] = lp.lpt_run
348
+ end
349
+
350
+ session[ :ordered_enable ] = ( lp.tdrunner_ordered == true )
351
+ session[ :teardown_enable ] = ( lp.tdrunner_teardown == true )
352
+
353
+ session[ :test_path ] = lp.test_framework_command[ 0 ]
354
+
355
+ rescue
356
+ end
357
+
358
+ # load weights from sip file
359
+ tests_defined = false
360
+ @profile_tests = {}
361
+ test_keys = []
362
+
363
+ if File.exist?( session[ :exec_root ] + prof_name + ".sip" )
364
+
365
+ sip_file = File.open( session[ :exec_root ] + prof_name + ".sip", 'r' )
366
+ tests_defined = true
367
+
368
+ sip_file.each do | sip_line |
369
+
370
+ if !sip_line.strip!.empty?
371
+ test_weight = sip_line.split("=")
372
+ test_name = nil
373
+
374
+ if test_weight[ 0 ].rindex("\\").nil?
375
+ test_name = test_weight[ 0 ]
376
+ else
377
+ test_name = test_weight[ 0 ][(test_weight[ 0 ].rindex("\\")+1)..-1 ]
378
+ end
379
+
380
+ @profile_tests[ test_name ] = test_weight[ 1 ]
381
+ test_keys << test_name
382
+
383
+ end
384
+
385
+ end
386
+
387
+ sip_file.close
388
+
389
+ end
390
+
391
+ # if no file or path was found, go back to index
392
+ if session[ :test_path ].nil? || session[ :test_path ] == "" || !tests_defined
393
+ session[ :index_message ] = "Failed to load the profile \"#{ params[ :prof_name ] }\""
394
+ redirect_to :action => "index"
395
+ else
396
+ # initialize session for going to weights page
397
+ session[ :default_weights ] = {}
398
+ session[ :execute_this ] = params[ :prof_name ]
399
+ session[ :loaded_profile_name ] = params[ :prof_name ]
400
+ session[ :test_keys ] = test_keys
401
+ render :action => "weights"
402
+ end
403
+ end
404
+
405
+
406
+ # saves the current profile into tdrunner.yml and profile specific .sip files
407
+ def save_current_profile( profile_name )
408
+
409
+ initial_profile = session[ :execute_this ]
410
+ session[ :execute_this ] = profile_name
411
+
412
+ begin
413
+
414
+ File.open( session[ :exec_root ] + profile_name + '.sip', 'w') do | sip_file |
415
+ session[ :test_keys ].each do | test_key |
416
+ sip_file.write test_key + "=" + session[ :weights ][ test_key ].to_s + "\n"
417
+ end
418
+ end
419
+
420
+ new_content = ""
421
+ File.open( session[ :exec_root ] + 'tdrunner.yml ') do | yml_file |
422
+ new_content = ""
423
+ found = false
424
+ yml_file.each do | yml_line |
425
+ if yml_line.include?( profile_name + ":" )
426
+ found = true
427
+ new_content += profile_name + ": " + join_execution_params + "\n"
428
+ else
429
+ new_content += yml_line
430
+ end
431
+ end
432
+ if !found
433
+ new_content += profile_name + ": " + join_execution_params + "\n"
434
+ end
435
+ end
436
+ File.open( session[ :exec_root ] + 'tdrunner.yml ', "w" ) do | yml_file |
437
+ yml_file.write new_content
438
+ end
439
+ rescue
440
+ #file not found
441
+ end
442
+
443
+ session[ :execute_this ] = initial_profile
444
+
445
+ end
446
+
447
+ # Join execution parameters from current session status into a String than can be used with tdrunner.
448
+ def join_execution_params
449
+
450
+ temp_params = session[ :exec_amount ]
451
+
452
+ if session[ :ordered_enable ] == true
453
+ temp_params += " --ordered"
454
+ end
455
+ if session[ :teardown_enable ] == true
456
+ temp_params += " --teardown"
457
+ end
458
+
459
+ temp_params += ' -e ' + session[ :execute_this ] + ' ' + session[ :test_path ]
460
+
461
+ temp_params += ' --tdriver_parameters ' + File.join( session[ :exec_root ], 'websi_parameters.xml' )
462
+
463
+ return temp_params
464
+
465
+ end
466
+
467
+ def get_report_names( from_path )
468
+
469
+ index2_files = Dir.glob( File.join( from_path, 'test_run*', 'index.html' ) )
470
+ index_files = index2_files.map do | ifile |
471
+ ifile[ ifile.rindex( 'test_run_' )+9, 14 ]
472
+ end
473
+
474
+ return index_files
475
+
476
+ end
477
+
478
+ end