Class: WatirTestlinkFramework::TestLinkPlan

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

Class Method Summary collapse

Class Method Details

.execute_cases(tl, plan_id, envstring, spectask, test_cases, dryrun) ⇒ Object



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
# File 'lib/watir_testlink_framework.rb', line 69

def self.execute_cases(tl, plan_id, envstring, spectask, test_cases, dryrun)
  test_cases.each do |tc|

    tc_customfield = tl.test_case_custom_field_design_value(tl.project_id($config['testlink']['project']),
                                                            tc[1][0]['full_external_id'], 
                                                            tc[1][0]['version'].to_i,
                                                            'RSPEC CASE ID',{:details=>''})

    exec_string = "#{envstring}bundle exec rake testlink:#{spectask} SPEC_OPTS=\"-e #{tc_customfield}\""
    if dryrun
      puts exec_string
    else
      print "\nRunning testcase #{tc_customfield} with ENV: #{envstring}\n"
      system exec_string
      print "Reporting testcase #{tc_customfield}\n"

      begin
        self.report_a_case(tl, plan_id, tc, envstring) if spectask=='junit'
      rescue Exception => e
        print "EXCEPTION------------------------------------\n"
        puts e.message
        puts e.backtrace.inspect
      end

    end
  end
end

.make_env_string(envarr) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/watir_testlink_framework.rb', line 97

def self.make_env_string(envarr)
  envstr=''
  envarr.each do | varname,varvalue|
    envstr+= "#{varname.upcase}='#{varvalue}' "
  end
  return envstr
end

.planid_by_name(tl, name) ⇒ Object



28
29
30
31
# File 'lib/watir_testlink_framework.rb', line 28

def self.planid_by_name(tl,name)
  plan_id = tl.test_plan_by_name($config['testlink']['project'], name)
  return plan_id[0][:id]
end

.read_report_arrayObject



105
106
107
108
109
110
111
112
# File 'lib/watir_testlink_framework.rb', line 105

def self.read_report_array
  cases_arr ={}
  Dir["reports/*.xml"].each do | report |
    case_arr = XmlSimple::xml_in(report)
    cases_arr[case_arr['testcase'][0]['name']] = case_arr
  end
  return cases_arr
end

.report_a_case(tl, plan_id, tc, envstring) ⇒ Object



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
# File 'lib/watir_testlink_framework.rb', line 114

def self.report_a_case(tl, plan_id, tc, envstring)

  cases_arr = self.read_report_array

  tc_customfield = tl.test_case_custom_field_design_value(tl.project_id($config['testlink']['project']),
                                                          tc[1][0]['full_external_id'],
                                                          tc[1][0]['version'].to_i,
                                                          'RSPEC CASE ID',{:details=>''})
  if cases_arr.has_key?(tc_customfield)
    options = {}
    notes=''
    if cases_arr[tc_customfield]['failures'] == '0'
      status ='p'
    elsif cases_arr[tc_customfield]['failures'] == '1'
      notes +=  "Message: " + cases_arr[tc_customfield]['testcase'][0]['failure'][0]['message']
      notes += "\n"
      notes += "Type: " + cases_arr[tc_customfield]['testcase'][0]['failure'][0]['type']
      notes += "\n"
      notes += "Content: " + cases_arr[tc_customfield]['testcase'][0]['failure'][0]['content']
      notes += "\n"
      notes += "EnvString: " + envstring
      status ='f'
    else
      status = 'b'
    end

    options['notes'] = notes
    tl.report_test_case_result(plan_id, tc[0], status, options)
  end

end

.report_cases(tl, plan_id, cases, envstring) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
# File 'lib/watir_testlink_framework.rb', line 146

def self.report_cases(tl, plan_id, cases, envstring)
  cases_arr ={}
  Dir["reports/*.xml"].each do | report |
    case_arr = XmlSimple::xml_in(report)
    cases_arr[case_arr['testcase'][0]['name']] = case_arr
  end

  cases.each do | tc |
    self.report_a_case(tl, plan_id, tc, envstring)
  end
end

.run_plan_cases(plans_string, spectask = 'spec', dryrun = false) ⇒ Object

plans_string comma seperated string with plans



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/watir_testlink_framework.rb', line 34

def self.run_plan_cases(plans_string, spectask='spec', dryrun=false)

  tl = self.testlinkplanconnection
  plans = plans_string.split(';')

  plans.each do | plan |

    plan_id = self.planid_by_name(tl, plan.strip)
    test_cases = tl.test_cases_for_test_plan(plan_id)

    if $config['testlink'].has_key?("multi_env") && $config['testlink']['multi_env'] != 0
      $config['testlink']['testplans'][plan.strip].each do | envname, envarr |

        #create new build
        buildname = "build_#{Time.new}_#{envname}"
        tl.create_build(plan_id, buildname, 'created by watir_testlink_framework')

        ### REPORT PER CASE
        envstr = make_env_string(envarr)
        self.execute_cases(tl,plan_id,envstr, spectask, test_cases, dryrun)
#        self.report_cases(tl, plan_id, test_cases, envstr) if spectask=='junit' && !dryrun
      end

    else
      buildname = "build_#{Time.new}"
      tl.create_build(plan_id, buildname, 'created by watir_testlink_framework')
      envstr = make_env_string($config['testlink']['testplans'][plan.strip])
      self.execute_cases(tl, plan_id, envstr, spectask, test_cases, dryrun)
#          self.report_cases(tl, plan_id, test_cases, envstr) if spectask=='junit' && !dryrun
    end

  end

end

.testlinkplanconnectionObject



22
23
24
25
26
# File 'lib/watir_testlink_framework.rb', line 22

def self.testlinkplanconnection
  server = $config['testlink']['xmlrpc_url']
  dev_key = $config['testlink']['apikey']
  return TestLinker.new(server, dev_key)
end