Class: BuildExtractor

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

Instance Method Summary collapse

Constructor Details

#initialize(str_connection_url, str_directory_path, num_host_data_id) ⇒ BuildExtractor

Description : invoked automatically when an object of the class type is created Author : Chandra sekaran Arguments :

str_connection_url : connection url for DB
str_directory_path : json report files directory path
num_host_data_id   : primary key of HostData table


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/friendly/build_extractor.rb', line 39

def initialize(str_connection_url, str_directory_path, num_host_data_id)
  @str_directory_path = str_directory_path
  @num_build_duration = 0
  @bool_build_passed = true
  @num_feature_count = 0
  @num_feature_pass_count = 0
  @num_feature_fail_count = 0
  @num_feature_skip_count = 0

  @str_connection_url = ""
  @str_user_name = ""
  @str_password = ""
  split_connection_url(str_connection_url)

  @num_host_data_id = num_host_data_id
end

Instance Method Details

#convert_duration(num_duration) ⇒ Object

Description : converts nanoseconds to seconds Author : Chandra sekaran Arguments :

num_duration        : time in nanoseconds

Return Argument : time in seconds



575
576
577
# File 'lib/friendly/build_extractor.rb', line 575

def convert_duration(num_duration)
  num_duration/(1000*1000*1000) #.to_f    # convert nanosecond to second
end

#format_file_path(str_fileabs_path) ⇒ Object

Description : formats the file path by replacing “\” with “/” Author : Chandra sekaran Arguments :

str_fileabs_path : absolute path of file

Return value :

str_file_path    : formatted absolute path of file


607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/friendly/build_extractor.rb', line 607

def format_file_path(str_fileabs_path)
  str_file_path = str_fileabs_path
  str_file_path.each_char do |letter|     # replace all the escape sequences
    case letter
      when /[\a]/
        str_file_path[letter] = "/a"
      when /[\e]/
        str_file_path[letter] = "/e"
      when /[\b]/
        str_file_path[letter] = "/b"
      when /[\cx]/
        str_file_path[letter] = "/cx"
      when /[\f]/
        str_file_path[letter] = "/f"
      when /[\n]/
        str_file_path[letter] = "/n"
      when /[\nnn]/
        #str_file_path[letter] = "/nnn" # not required as \n is given
      when /[\r]/
        str_file_path[letter] = "/r"
      when /[\s]/
        str_file_path[letter] = "/t"   # it is taking "\t" as "\s"
      when /[\t]/
        str_file_path[letter] = "/t"
      when "\\"
        str_file_path[letter] = "/"
     #when /[\v]/                       #  not required due to expression error
     #str_file_path[letter] = "/v"    #  not required due to expression error
     #when /[\x]/                       #  not required due to expression error
     #str_file_path[letter] = "/x"    #  not required due to expression error
     #when /[\xnn]/                     #  not required due to expression error
     #str_file_path[letter] = "/xnn"  #  not required due to expression error
    end
  end
  return str_file_path
rescue Exception => ex
  puts("Error in formatting file path (#{str_file_path}) : #{ex}")
  exit
end

#get_host_dataObject

Description : gets the host data from Sybase based on current execution host Author : Chandra sekaran Return Arguments :

num_host_id   : primary key the host


231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/friendly/build_extractor.rb', line 231

def get_host_data
  # as of now I took hostid primary key for getting the current host where the execution has been made
  # and I took BROWSER for selecting under the assumption that each browser executes on different host machines
  # if you are using some other parameter, kindly uncomment and update the required fields
  #DBI.connect(@str_connection_url, @str_user_name, @str_password) do |dbh|
  #  # str_query = "select HostDataID from HostData where HostName like '#{ENV['COMPUTERNAME'].downcase}' and OS like '#{ENV['OS'].downcase}' and Browser like '#{BROWSER.downcase}'"
  #  str_query = "select HostDataID from HostData where HostDataID=#{@num_host_data_id}"
  #  sth = dbh.prepare(str_query)
  #  sth.execute()
  #  num_host_id  = sth.fetch[0]
  #  dbh.disconnect()
  #  $log.info("------------host id : #{num_host_id.nil?}")
  #  num_host_id.nil? ? 5 : num_host_id
  #end
  @num_host_data_id
rescue Exception => ex
  puts("Error in getting host data from HostData table: #{ex}")
  exit
end

#parse_jsonObject

Description : parses the json object saves the required execution data into Sybase DB Author : Chandra sekaran



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/friendly/build_extractor.rb', line 105

def parse_json
  @json.each_with_index do |json, index|         # iterate each feature
    str_feature_id, num_feature_result_id = set_feature(json["name"].to_s)      # add feature name
    @num_feature_count += 1
    scenario_count = 0
    feature_duration = 0
    bool_feature_passed = true
    num_scenario_pass_count = 0
    num_scenario_fail_count = 0
    num_scenario_skip_count = 0

    json["elements"].each do |element|
      # for including the first background steps duration to the first scenario background steps as Cucumber json
      # report considers background for the first scenario and hence will have 0 duration for the background steps
      # under first scenario and the actual duration for the background will be set for the subsequent scenarios
      if index == 0
        if element["keyword"] == "Background"
          element["steps"].each do |step|
            @arr_background_step_duration << step["result"]["duration"].to_i
            @bool = true
          end
        end
      end
      num_step_pass_count = 0
      num_step_fail_count = 0
      num_step_skip_count = 0

      if element["keyword"] == "Scenario"       # take scenario for scenario level details
        str_scenario_id, scenario_result_id = set_scenario(element["name"], element["tags"][0]["name"], str_feature_id)     # add scenario name
                                                                                                                            # above element["tags"][0]["name"] takes the first tag which should be the scenario id (here @tc_<scenarioid>)

        scenario_count += 1  # as it counts only 'Scenarios' and not 'Backgrounds'
        step_count = 0
        scenario_duration = 0
        bool_scenario_passed = true

        element["steps"].each_with_index do |step, indx|    # iterate each steps of the current scenario
                                                            #num_step_id, num_step_result_id = set_step(step['keyword']+step['name'], str_scenario_id, scenario_result_id)    # add step name
          num_step_id = set_step(step['keyword']+step['name'], str_scenario_id, scenario_result_id)    # add step name

          step_count += 1
          step_duration = 0
          bool_step_passed = true
          if (index == 0) && (indx < @arr_background_step_duration.size) && @bool
            step_duration = @arr_background_step_duration[indx]    # take duration from Background for the first scenario
          else
            step_duration = step['result']['duration'].to_i     # take usual duration
            @bool = false
          end
          scenario_duration += step_duration
          if step['result']['status'] == "passed"
            num_step_pass_count += 1
          elsif step['result']['status'] == "failed"
            num_step_fail_count += 1
          elsif step['result']['status'] == "skipped"
            num_step_skip_count += 1
          end
          bool_step_passed = ["passed", "pending"].include?(step['result']['status']) ? true : false
          bool_scenario_passed &&= bool_step_passed
                                                                                                       #puts "\t\t Step : #{step['keyword']+step['name']} - #{step_duration} - #{bool_step_passed}"
                                                                                                       #reset_step_result(bool_step_passed, step_duration, num_step_result_id)
          set_step_result_new(num_step_id, str_scenario_id, scenario_result_id, bool_step_passed, step_duration)
        end
                                                                                                                            #puts "Scenario : #{element["tags"][0]["name"]} - #{element['name']} - #{scenario_duration} - #{bool_scenario_passed} - #{step_count}"
        reset_scenario_result(scenario_result_id, scenario_duration, num_step_pass_count, num_step_fail_count, num_step_skip_count, bool_scenario_passed)
        feature_duration += scenario_duration
        bool_feature_passed &&= bool_scenario_passed

        if bool_scenario_passed
          num_scenario_pass_count += 1    # scenario pass count
        else
          if num_step_pass_count == 0 && num_step_fail_count == 0 && num_step_skip_count > 0
            num_scenario_skip_count += 1   # scenario skip count
          else
            num_scenario_fail_count += 1   # scenario fail count
          end
        end

      end
    end
                                                                                #puts "Feature : #{json['name']} - #{feature_duration} - #{bool_feature_passed} - #{scenario_count}"
    reset_feature_result(feature_duration, num_scenario_pass_count, num_scenario_fail_count, num_scenario_skip_count, bool_feature_passed, num_feature_result_id)
    @num_build_duration += feature_duration
    @bool_build_passed &&= bool_feature_passed

    if bool_feature_passed
      @num_feature_pass_count += 1
    else
      @num_feature_fail_count += 1    # to do feature skip count
    end
  end
rescue Exception => ex
  puts("Error while parsing JSON : #{ex}")
  exit
end

#reset_build(num_run_length, num_pass_count, num_fail_count, num_skip_count, bool_result) ⇒ Object

Description : resets the build data with execution details into Sybase Author : Chandra sekaran Arguments :

num_run_length : total execution time in nanoseconds
num_pass_count : number of features passed
num_fail_count : number of features failed
num_skip_count : number of features skipped
bool_result    : boolean value resembling the state of build result


260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/friendly/build_extractor.rb', line 260

def reset_build(num_run_length, num_pass_count, num_fail_count, num_skip_count, bool_result)
  num_result =  bool_result ? 1 : 0
  DBI.connect(@str_connection_url, @str_user_name, @str_password) do |dbh|
    sth = dbh.prepare("update BuildData set RunLength=?, Passes=?, Failures=?, Skips=?, Result=? where BuildID=?")
    sth.execute(convert_duration(num_run_length), num_pass_count, num_fail_count, num_skip_count, num_result, @build_id)
    sth.finish
    dbh.commit
    #puts "Updated a record (#{@build_id}) in BuildData table successfully"
    dbh.disconnect()
  end
rescue Exception => ex
  puts("Error in resetting build data to BuildData table: #{ex}")
  exit
end

#reset_feature_result(num_run_length, num_pass_count, num_fail_count, num_skip_count, bool_result, num_feature_result_id) ⇒ Object

Description : resets the feature result data with execution details into Sybase Author : Chandra sekaran Arguments :

num_run_length : feature execution time in nanoseconds
num_pass_count : number of scenarios passed
num_fail_count : number of scenarios failed
num_skip_count : number of scenarios skipped
bool_result    : boolean value resembling the state of build result
num_feature_result_id : primary key of the TestFeatureResult table


352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/friendly/build_extractor.rb', line 352

def reset_feature_result(num_run_length, num_pass_count, num_fail_count, num_skip_count, bool_result, num_feature_result_id)
  num_result =  bool_result ? 1 : 0
  DBI.connect(@str_connection_url, @str_user_name, @str_password) do |dbh|
    sth = dbh.prepare("update TestFeatureResult set RunLength=?, Passes=?, Failures=?, Skips=?, Result=? where TestFeatureResultID=?")
    sth.execute(convert_duration(num_run_length), num_pass_count, num_fail_count, num_skip_count, num_result, num_feature_result_id)
    sth.finish
    dbh.commit
    #puts "Updated a record (#{num_feature_result_id}) in TestFeatureResult table successfully"
    dbh.disconnect()
  end
rescue Exception => ex
  puts("Error in resetting feature result data to TestFeatureResult table : #{ex}")
  exit
end

#reset_scenario_result(num_scenario_result_id, num_run_length, num_pass_count, num_fail_count, num_skip_count, bool_result) ⇒ Object

Description : resets the scenario result data with execution details into Sybase Author : Chandra sekaran Arguments :

num_scenario_result_id : primary key of the scenario result
num_run_length         : steps execution time in nanoseconds
num_pass_count         : number of steps passed
num_fail_count         : number of steps failed
num_skip_count         : number of steps skipped
bool_result            : boolean value resembling the state of steps result


444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/friendly/build_extractor.rb', line 444

def reset_scenario_result(num_scenario_result_id, num_run_length, num_pass_count, num_fail_count, num_skip_count, bool_result)
  num_result =  bool_result ? 1 : 0
  DBI.connect(@str_connection_url, @str_user_name, @str_password) do |dbh|
    sth = dbh.prepare("update TestScenarioResult set RunLength=?, Passes=?, Failures=?, Skips=?, Result=? where TestScenarioResultID=?")
    sth.execute(convert_duration(num_run_length), num_pass_count, num_fail_count, num_skip_count, num_result, num_scenario_result_id)
    sth.finish
    dbh.commit
    #puts "Updated a record (#{num_scenario_result_id}) in TestScenarioResult table successfully"
    dbh.disconnect()
  end
rescue Exception => ex
  puts("Error in resetting scenario data to TestScenarioResult table : #{ex}")
  exit
end

#reset_step_result(bool_result, num_run_length, num_step_result_id) ⇒ Object

Description : resets the step result data with execution details into Sybase Author : Chandra sekaran Arguments :

bool_result         : boolean value resembling the state of step result
num_run_length      : step execution time in nanoseconds
num_step_result_id  : primary key of step result


554
555
556
557
558
559
560
561
562
563
564
565
566
567
# File 'lib/friendly/build_extractor.rb', line 554

def reset_step_result(bool_result, num_run_length, num_step_result_id)
  num_result = bool_result ? 1 : 0
  DBI.connect(@str_connection_url, @str_user_name, @str_password) do |dbh|
    sth = dbh.prepare("update TestStepResult set Result=?, RunLength=? where TestStepResultID=?")
    sth.execute(num_result, convert_duration(num_run_length), num_step_result_id)
    sth.finish
    dbh.commit
    #puts "Updated a record (#{num_step_result_id}) in TestStepResult table successfully"
    dbh.disconnect()
  end
rescue Exception => ex
  puts("Error in resetting step results data in TestStepResult table : #{ex}")
  exit
end

#save_build_dataObject

Description : function that creates performance report data and stores it in Sybase Author : Chandra sekaran



582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
# File 'lib/friendly/build_extractor.rb', line 582

def save_build_data
  puts "Extracting build data ...\nThis might take a moment, please wait"
  set_build       # set Build data only once for each execution (Single or Parallel)
  Dir["#{format_file_path(@str_directory_path)}/*.json"].each do |path|
    puts "Extracting build execution data from '#{path}'"
    @arr_background_step_duration = []
    file = File.read(path)
    @json = JSON.parse(file)
    parse_json    # parse each json file and extract report data
  end
                  #puts "Build duration : #{@num_build_duration} - #{@bool_build_passed} - #{@num_feature_count}"
  reset_build(@num_build_duration, @num_feature_pass_count, @num_feature_fail_count, @num_feature_skip_count, @bool_build_passed)  # Update the Build data with execution summary
  puts "\nThe build execution data for the build ID=#{@build_id} are saved into #{@str_db} DataBase successfully"
rescue Exception => ex
  puts("Error while creating report : #{ex}")
  exit
end

#set_buildObject

Description : sets the build data with default details into Sybase Author : Chandra sekaran



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/friendly/build_extractor.rb', line 204

def set_build
  num_host_id = get_host_data
  build_name = Time.now.strftime("%d_%m_%Y-%H_%M_%S")
  DBI.connect(@str_connection_url, @str_user_name, @str_password) do |dbh|
    str_query = "insert into BuildData(BuildName,HostDataID) values (?,?)"
    sth = dbh.prepare(str_query)
    sth.execute(build_name, num_host_id)
    sth.finish
    dbh.commit
    #puts "Added a record to BuildData table successfully"

    str_query = "select BuildID from BuildData where BuildName='#{build_name}' and HostDataID=#{num_host_id}"
    sth = dbh.prepare(str_query)
    sth.execute()
    @build_id  = sth.fetch[0]
    dbh.disconnect()
  end
rescue Exception => ex
  puts("Error in setting build data to BuildData table: #{ex}")
  exit
end

#set_feature(str_feature_name) ⇒ Object

Description : sets the feature data with default details into Sybase Author : Chandra sekaran Arguments :

str_feature_name : feature name

Return Arguments :

num_feature_id   : primary key the feature
num_feature_result_id  : primary key of the feature result


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
# File 'lib/friendly/build_extractor.rb', line 283

def set_feature(str_feature_name)
  DBI.connect(@str_connection_url, @str_user_name, @str_password) do |dbh|
    str_query = "select TestFeatureID from TestFeature where FeatureName=?"
    sth = dbh.prepare(str_query)
    sth.execute(str_feature_name)

    if sth.fetch.nil?   # insert only if the data is not present in the table
      sth = dbh.prepare("insert into TestFeature(FeatureName) values (?)")
      sth.execute(str_feature_name)
      dbh.commit
                        #puts "Added a record to TestFeature table successfully"
    end
    str_query = "select TestFeatureID from TestFeature where FeatureName='#{str_feature_name}'"
    sth = dbh.prepare(str_query)
    sth.execute()
    num_feature_id = sth.fetch[0]
    #puts "********** Record found with Primary key '#{num_feature_id}' in TestFeature *************"
    dbh.disconnect()
    num_feature_result_id = set_feature_result(num_feature_id)
    return num_feature_id, num_feature_result_id   # return the feature id and feature result id of the feature
  end
rescue Exception => ex
  puts("Error in setting feature data to TestFeature table : #{ex}")
  exit
end

#set_feature_result(num_feature_id) ⇒ Object

Description : sets the feature result data with default details into Sybase Author : Chandra sekaran Arguments :

str_feature_name : feature_id of the feature

Return Arguments :

num_feature_result_id  : primary key of the feature result


316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/friendly/build_extractor.rb', line 316

def set_feature_result(num_feature_id)
  DBI.connect(@str_connection_url, @str_user_name, @str_password) do |dbh|
    str_query = "select TestFeatureResultID from TestFeatureResult where TestFeatureID=? and BuildID=?"
    sth = dbh.prepare(str_query)
    sth.execute(num_feature_id, @build_id)

    if sth.fetch.nil?   # insert only if the data is not present in the table
      sth = dbh.prepare("insert into TestFeatureResult(TestFeatureID,BuildID) values (?,?)")
      sth.execute(num_feature_id, @build_id)
      dbh.commit
                        #puts "Added a record to TestFeatureResult table successfully"
    end

    str_query = "select TestFeatureResultID from TestFeatureResult where TestFeatureID=#{num_feature_id} and BuildID=#{@build_id}"
    sth = dbh.prepare(str_query)
    sth.execute()
    num_feature_result_id = sth.fetch[0]
    #puts "********** Record found with Primary key '#{num_feature_result_id}' in TestFeatureResult *************"
    dbh.disconnect()
    return num_feature_result_id   # return the feature result id of the feature
  end
rescue Exception => ex
  puts("Error in setting feature result data to TestFeatureResult table : #{ex}")
  exit
end

#set_scenario(str_scenario_name, str_qa_complete_id, str_feature_id) ⇒ Object

Description : sets the scenario data with default details into Sybase Author : Chandra sekaran Arguments :

str_scenario_name  : scenario name
str_qa_complete_id : QA Complete ID (Scenario ID) of the scenario
str_feature_id     : primary key of the feature

Return Arguments :

num_scenario_id    : primary key of the scenario
scenario_result_id : primary key of the scenario result


377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# File 'lib/friendly/build_extractor.rb', line 377

def set_scenario(str_scenario_name, str_qa_complete_id, str_feature_id)
  DBI.connect(@str_connection_url, @str_user_name, @str_password) do |dbh|
    str_query = "select TestScenarioID from TestScenario where ScenarioName=? and TestFeatureID=?"
    sth = dbh.prepare(str_query)
    sth.execute(str_scenario_name, str_feature_id.to_i)

    if sth.fetch.nil?  # insert only if the data is not present in the table
      sth = dbh.prepare("insert into TestScenario(ScenarioName,QACompleteID,TestFeatureID) values (?,?,?)")
      sth.execute(str_scenario_name, str_qa_complete_id, str_feature_id.to_i)
      sth.finish
      dbh.commit
      #puts "Added a record to TestScenario table successfully"
    end

    str_query = "select TestScenarioID from TestScenario where ScenarioName='#{str_scenario_name}' and TestFeatureID=#{str_feature_id}"
    sth = dbh.prepare(str_query)
    sth.execute()
    num_scenario_id = sth.fetch[0]
    #puts "********** Record found with Primary key '#{num_scenario_id}' in TestScenario *************"
    scenario_result_id = set_scenario_result(num_scenario_id, str_feature_id)
    dbh.disconnect()
    return num_scenario_id, scenario_result_id    # return the scenario id and scenario result id of the scenario
  end
rescue Exception => ex
  puts("Error in setting scenario data to TestScenario table : #{ex}")
  exit
end

#set_scenario_result(num_scenario_id, num_feature_id) ⇒ Object

Description : sets the scenario result data with default details into Sybase Author : Chandra sekaran Arguments :

num_scenario_id    : primary key of the scenario
num_feature_id     : primary key of the feature

Return Arguments :

num_scenario_result_id : primary key of the scenario result


413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/friendly/build_extractor.rb', line 413

def set_scenario_result(num_scenario_id, num_feature_id)
  DBI.connect(@str_connection_url, @str_user_name, @str_password) do |dbh|
    sth = dbh.prepare("insert into TestScenarioResult(TestFeatureID,TestScenarioID,BuildID) values (?,?,?)")
    sth.execute(num_feature_id, num_scenario_id, @build_id)
    sth.finish
    dbh.commit
    #puts "Added a record to TestScenarioResult table successfully"

    str_query = "select TestScenarioResultID from TestScenarioResult where TestFeatureID=#{num_feature_id} and TestScenarioID=#{num_scenario_id} and BuildID=#{@build_id}"
    sth = dbh.prepare(str_query)
    sth.execute()
    num_scenario_result_id = sth.fetch[0]
    #puts "********** Record found with Primary key '#{num_scenario_result_id}' in TestScenarioResult *************"
    dbh.disconnect()
    return num_scenario_result_id    # return the scenario id of the scenario
  end
rescue Exception => ex
  puts("Error in setting scenario data to TestScenarioResult table : #{ex}")
  exit
end

#set_step(str_step_name, str_scenario_id, num_scenario_result_id) ⇒ Object

Description : sets the step data with default details into Sybase Author : Chandra sekaran Arguments :

str_step_name           : step name
str_scenario_id         : primary key of scenario
num_scenario_result_id  : primary key of scenario result

Return Arguments :

num_step_id             : primary key of step
num_step_result_id      : primary key of step result


469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/friendly/build_extractor.rb', line 469

def set_step(str_step_name, str_scenario_id, num_scenario_result_id)
  DBI.connect(@str_connection_url, @str_user_name, @str_password) do |dbh|
    str_query = "select TestStepID from TestStep where StepName=? and TestScenarioID=?"
    sth = dbh.prepare(str_query)
    sth.execute(str_step_name, str_scenario_id)

    if sth.fetch.nil?   # insert only if the data is not present in the table
      sth = dbh.prepare("insert into TestStep(StepName,TestScenarioID) values (?,?)")
      sth.execute(str_step_name, str_scenario_id)
      dbh.commit
                        #puts "Added a record to TestStep table successfully"
    end

    str_query = "select TestStepID from TestStep where StepName='#{str_step_name}' and TestScenarioID=#{str_scenario_id}"
    sth = dbh.prepare(str_query)
    sth.execute()
    num_step_id = sth.fetch[0]
    #puts "********** Record found with Primary key '#{num_step_id}' in TestStep *************"
    dbh.disconnect()
    return num_step_id
  end
rescue Exception => ex
  puts("Error in setting step data to TestStep table : #{ex}")
  exit
end

#set_step_result(num_step_id, num_scenario_id, num_scenario_result_id) ⇒ Object

Description : sets the step result data with default details into Sybase Author : Chandra sekaran Arguments :

num_step_id             : primary key of step
str_scenario_id         : primary key of scenario
num_scenario_result_id  : primary key of scenario result

Return Arguments :

num_step_result_id      : primary key of step result


527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
# File 'lib/friendly/build_extractor.rb', line 527

def set_step_result(num_step_id, num_scenario_id, num_scenario_result_id)
  DBI.connect(@str_connection_url, @str_user_name, @str_password) do |dbh|
    sth = dbh.prepare("insert into TestStepResult(TestScenarioResultID,TestStepID,BuildID,TestScenarioID) values (?,?,?,?)")
    sth.execute(num_scenario_result_id, num_step_id, @build_id, num_scenario_id)
    dbh.commit
    #puts "Added a record to TestStepResult table successfully"

    str_query = "select TestStepResultID from TestStepResult where TestScenarioResultID=#{num_scenario_result_id} and TestStepID=#{num_step_id} and BuildID=#{@build_id} and TestScenarioID=#{num_scenario_id}"
    sth = dbh.prepare(str_query)
    sth.execute()
    num_step_result_id = sth.fetch[0]
    #puts "********** Record found with Primary key '#{num_step_result_id}' in TestStepResult *************"
    dbh.disconnect()
    return num_step_result_id     # return the step result id of the step
  end
rescue Exception => ex
  puts("Error in setting step data to TestStep table : #{ex}")
  exit
end

#set_step_result_new(num_step_id, num_scenario_id, num_scenario_result_id, bool_result, num_run_length) ⇒ Object

Description : sets the step result data with execution details into Sybase Author : Chandra sekaran Arguments :

num_step_id             : primary key of step
num_scenario_id         : primary key of scenario
num_scenario_result_id  : primary key of scenario result
bool_result             : boolean value resembling the state of step result
num_run_length          : steps execution time in nanoseconds


504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'lib/friendly/build_extractor.rb', line 504

def set_step_result_new(num_step_id, num_scenario_id, num_scenario_result_id, bool_result, num_run_length)
  num_result = bool_result ? 1 : 0
  DBI.connect(@str_connection_url, @str_user_name, @str_password) do |dbh|
    sth = dbh.prepare("insert into TestStepResult(TestScenarioResultID,Result,RunLength,TestStepID,BuildID,TestScenarioID) values (?,?,?,?,?,?)")
    sth.execute(num_scenario_result_id, num_result, convert_duration(num_run_length), num_step_id, @build_id, num_scenario_id)
    dbh.commit
    dbh.disconnect()
    #puts "Added a record to TestStepResult table successfully"
  end
rescue Exception => ex
  puts("(set_step_result_new)Error in setting step data to TestStepResult table : #{ex}")
  exit
end

#split_connection_url(str_connection_url) ⇒ Object

Description : extracts connection url, username and password from the input connection url Author : Chandra sekaran



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/friendly/build_extractor.rb', line 59

def split_connection_url(str_connection_url)
  tmp_arr = str_connection_url.split(";")
  num_count = 0
  ["dbi"].each do |key|
    if str_connection_url.downcase.include? key
      tmp_arr.each do |ele|
        @str_connection_url = ele.split(";").first.strip + ";" if ele.downcase.include? key
      end
    else num_count += 1
    end
  end
  raise "Invalid connection url, it doesn't include dbi field : #{str_connection_url}" if num_count == ["dbi"].size
  num_count = 0
  ["dbn", "database", "dbname"].each do |key|
    if str_connection_url.downcase.include? key
      tmp_arr.each do |ele|
        if ele.downcase.include? key
          @str_connection_url << "DBN=" + ele.split("=").last.strip + ";"
          @str_db = ele.split("=").last.strip
        end
      end
    else num_count += 1
    end
  end
  raise "Invalid connection url, it doesn't include database field : #{str_connection_url}" if num_count == ["dbi"].size
  num_count = 0
  ["uid", "userid", "username"].each do |key|
    if str_connection_url.downcase.include? key
      tmp_arr.each do |ele|
        @str_user_name = ele.split("=").last.strip if ele.downcase.include? key
      end
    else num_count += 1
    end
  end
  ["pwd", "password"].each do |key|
    if str_connection_url.downcase.include? key
      tmp_arr.each do |ele|
        @str_password = ele.split("=").last.strip if ele.downcase.include? key
      end
    end
  end
end