Class: TDRunner::TDRunnerParameters

Inherits:
Object
  • Object
show all
Defined in:
lib/tdrunner_profile.rb

Overview

Calss for holding the tdrunner execution parameters

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ TDRunnerParameters

intializes tdrunner execution parameters and loads them to memory



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/tdrunner_profile.rb', line 116

def initialize(args)
  @test_framework=nil
  @test_framework_command=Array.new
  @execution_mode='-i'
  @lpt_run=1
  @duration_value=0
  @execution_profile=nil
  @tdrunner_teardown=false
  @tdrunner_ordered=false
  @tdrunner_combine_report=nil
  @start_time=nil
  @failed_execution_profile=nil
  @recorded_execution_profile=nil
  parse_tdrunner_parameters(args)
end

Instance Method Details

#check_duration(duration_value) ⇒ Object

method to check that the format of the duration value is correct - e.g. 4, 4.5, 4:23 are correct



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/tdrunner_profile.rb', line 138

def check_duration(duration_value)
  ret=false
  if (/^\d+$/.match(duration_value) or /^\d+.\d+$/.match(duration_value))
    ret=true
  elsif (/^\d+:\d+$/.match(duration_value))
    if(duration_value.split(':') [1].to_i)<60
      ret=true
    end
  end
  ret
end

#check_if_parameters_contain_a_framework_command(args) ⇒ Object

method for checking the framework command



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/tdrunner_profile.rb', line 157

def check_if_parameters_contain_a_framework_command(args)
  parameters_contains_framework_command=false
  is_directory=false
  args.each do |value|
    is_directory=File.directory?(value)
    if value=='test_suite'
      if is_directory==false
        parameters_contains_framework_command=true
        @test_framework='test_suite'
      end
    end
    if value=='test_unit'
      if is_directory==false
        parameters_contains_framework_command=true
        @test_framework='test_unit'
      end
    end
    if value=='cucumber'
      if is_directory==false
        parameters_contains_framework_command=true
        @test_framework='cucumber'
      end
    end
  end
  parameters_contains_framework_command
end

#combine_with_existing_tdriver_report(report_location) ⇒ Object

method for combining a TDriver report with the current tdrunner execution



151
152
153
154
# File 'lib/tdrunner_profile.rb', line 151

def combine_with_existing_tdriver_report(report_location)
  Kernel::raise ArgumentError.new("Report folder does not exists") if File.directory?(report_location)==false
  TDriverReportAPI::tdriver_report_combine_reports(report_location)
end

#create_failed_sip(failed_sip_profile) ⇒ Object



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/tdrunner_profile.rb', line 333

def create_failed_sip(failed_sip_profile)
  sip_file=nil
  failed_sip_profile=failed_sip_profile+'.sip' if failed_sip_profile.include?('.sip')==false
  #check if failed_sip_profile already exists in current dir
  if File.file?(failed_sip_profile)
    sip_file =  failed_sip_profile
  end

  #check if path given
  if sip_file==nil
    failed_sip_profile=failed_sip_profile.gsub(/\\/,'/')
    dirs = File.dirname(failed_sip_profile)
    if (dirs != ".")
      #check if the dirs exist, if not create the dirs
      FileUtils.mkdir_p(dirs) if !File.exist?(dirs)
      sip_file=failed_sip_profile
    else
      FileUtils.mkdir_p 'config'  if File::directory?('config')==false
      sip_file=File.join('config/', failed_sip_profile)
    end
    #File.open(sip_file, 'w') { |file| file.write('') }
  end

 return sip_file
end

#duration_valueObject



407
408
409
# File 'lib/tdrunner_profile.rb', line 407

def duration_value()
  @duration_value
end

#execution_modeObject



401
402
403
# File 'lib/tdrunner_profile.rb', line 401

def execution_mode()
  @execution_mode
end

#execution_profileObject



413
414
415
# File 'lib/tdrunner_profile.rb', line 413

def execution_profile()
  @execution_profile
end

#failed_execution_profileObject



419
420
421
# File 'lib/tdrunner_profile.rb', line 419

def failed_execution_profile()
  @failed_execution_profile
end

#format_tdrunner_date(date_time) ⇒ Object

method for checking the end time for tdrunner run



133
134
135
# File 'lib/tdrunner_profile.rb', line 133

def format_tdrunner_date(date_time)
  Time.parse(date_time)
end

#lpt_runObject



404
405
406
# File 'lib/tdrunner_profile.rb', line 404

def lpt_run()
  @lpt_run
end

#make_execution_profileObject



416
417
418
# File 'lib/tdrunner_profile.rb', line 416

def make_execution_profile()
  @make_execution_profile
end

#parse_tdrunner_parameters(args) ⇒ Object

Parser method for tdrunner commandline parameters -H prameter defines the runtime -d parameter is for the end time stamp -i parameter is for the iteration number for the tests -m parameter is for creating a test set execution profile without running the tests



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/tdrunner_profile.rb', line 189

def parse_tdrunner_parameters(args)
  hour_defined=false
  end_date_defined=false
  start_date_defined=false
  iterations_defined=false
  execution_profile_defined=false
  make_execution_profile=false
  combine_report_defined=false
  make_failed_execution_profile_defined=false
  make_recorded_execution_profile_defined=false
  parameters_contains_framework_command=check_if_parameters_contain_a_framework_command(args)

  args.each do |value|
    if hour_defined==true
      @execution_mode='-H' if @execution_mode!='-m'
      @duration_value=value.to_s
      if !check_duration(@duration_value)
        puts 'Error duration '+ @duration_value+ ' is not valid!'
        exit
      end
      hour_defined=false
    end
    if end_date_defined==true
      @execution_mode='-d' if @execution_mode!='-m'
      @lpt_run=Time.new
      @lpt_run=format_tdrunner_date(value)
      if @lpt_run < Time.now
        puts 'Error date '+ @lpt_run.to_s + ' is in the past!'
        exit
      end
      end_date_defined=false
    end
    if start_date_defined==true
      @start_time=format_tdrunner_date(value)
      if @start_time < Time.now
        puts 'Error date '+ @start_time.to_s + ' is in the past!'
        exit
      end
      start_date_defined=false
    end
    if iterations_defined==true
      @execution_mode='-i' if @execution_mode!='-m'
      @lpt_run=value.to_i
      iterations_defined=false
    end
    if execution_profile_defined==true
      #@execution_mode='-e'
      @execution_profile=value
      execution_profile_defined=false
    end
    if make_execution_profile==true
      @execution_mode='-m'
      @execution_profile=value
      make_execution_profile=false
    end
    if combine_report_defined==true
      combine_report_defined=false
      @tdrunner_combine_report=value
      combine_with_existing_tdriver_report(value)
    end
    if make_failed_execution_profile_defined==true
      make_failed_execution_profile_defined=false
      @failed_execution_profile=value
    end
    if make_recorded_execution_profile_defined==true
      make_recorded_execution_profile_defined=false
      @recorded_execution_profile=value
    end

    if value.to_s == '--teardown'
      @tdrunner_teardown=true
    end
    if value.to_s == '--ordered'
      @tdrunner_ordered=true
    end
    if value.to_s == '-H'
      hour_defined=true
    end
    if value.to_s == '-d'
      end_date_defined=true
    end
    if value.to_s == '-s'
      start_date_defined=true
    end
    if value.to_s == '-i'
      iterations_defined=true
    end
    if value.to_s == '-e'
      execution_profile_defined=true
    end
    if value.to_s == '-m'
      make_execution_profile=true
    end
    if value.to_s == '-c'
      combine_report_defined=true
    end
    if value.to_s == '-t'
      make_failed_execution_profile_defined=true
    end
    if value.to_s == '-r'
      make_recorded_execution_profile_defined=true
    end

  end

  framework_command_start=false
  args.each do |value|
    if value=='.'
      value=Dir.getwd
    end
    if framework_command_start==true
      @test_framework_command << value
    end
    if value==@test_framework && parameters_contains_framework_command==true
      framework_command_start=true
    else
      if File.directory?(value) && framework_command_start==false && value!=@tdrunner_combine_report
        @test_framework_command << value
        framework_command_start=true
      end
      if File.file?(value) && framework_command_start==false && value.include?('.sip')==false
        @test_framework_command << value
        framework_command_start=true
      end
    end
  end
  if @execution_profile!=nil
    if parameters_contains_framework_command==false
      profile_location=sip_file(@execution_profile,@test_framework_command)
      @execution_profile=profile_location
    else
      profile_location=sip_file(@execution_profile)
      @execution_profile=profile_location
    end
  end
  if @failed_execution_profile!=nil
    failed_profile_location=create_failed_sip(@failed_execution_profile)
    @failed_execution_profile=failed_profile_location
  end
  if @recorded_execution_profile!=nil
    recorded_profile_location=create_failed_sip(@recorded_execution_profile)
    @recorded_execution_profile=recorded_profile_location        
  end
end

#recorded_execution_profileObject



422
423
424
# File 'lib/tdrunner_profile.rb', line 422

def recorded_execution_profile()
  @recorded_execution_profile
end

#sip_file(tdrunner_profile, profile_folder = nil) ⇒ Object

Locates sip file. and be located in the current directory (eg. project root) or in a .config/ or config/ subdirectory of the current directory.



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/tdrunner_profile.rb', line 361

def sip_file(tdrunner_profile,profile_folder=nil)
  @tdrunner_profile_file=nil
  tdrunner_profile=tdrunner_profile+'.sip' if tdrunner_profile.include?('.sip')==false
  if File.file?(tdrunner_profile)
    @tdrunner_profile_file=tdrunner_profile
  end

  if @tdrunner_profile_file==nil
    profile_finder=TDRunnerFileFinder.new('sip')
    found_profile_files=profile_finder.get_files(Dir.getwd)
    found_profile_files.each do |profile_file|
      if File.basename(profile_file.gsub('\\','/')).downcase==tdrunner_profile.downcase
        @tdrunner_profile_file=profile_file.gsub('\\','/')
      end
    end
  end

  if @tdrunner_profile_file==nil
    if File::directory?('config')==false
      FileUtils.mkdir_p 'config'
    end
    if tdrunner_profile.include?("\\")
      prof_arr=tdrunner_profile.split("\\")
      tdrunner_profile=prof_arr.last
    elsif tdrunner_profile.include?('/')
      prof_arr=tdrunner_profile.split("/")
      tdrunner_profile=prof_arr.last
    end
    File.open('config/'+tdrunner_profile, 'w') { |file| file.write('') }
    profile_file=File.join('config','**', tdrunner_profile)
  end
  @tdrunner_profile_file ||= Dir.glob(profile_file).first
  @tdrunner_profile_file
end

#start_timeObject



428
429
430
# File 'lib/tdrunner_profile.rb', line 428

def start_time()
  @start_time
end

#tdrunner_orderedObject



425
426
427
# File 'lib/tdrunner_profile.rb', line 425

def tdrunner_ordered()
  @tdrunner_ordered
end

#tdrunner_teardownObject



410
411
412
# File 'lib/tdrunner_profile.rb', line 410

def tdrunner_teardown()
  @tdrunner_teardown
end

#test_frameworkObject



395
396
397
# File 'lib/tdrunner_profile.rb', line 395

def test_framework()
  @test_framework
end

#test_framework_commandObject



398
399
400
# File 'lib/tdrunner_profile.rb', line 398

def test_framework_command()
  @test_framework_command
end