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, envstr, spectask, test_cases, dryrun) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/watir_testlink_framework.rb', line 68

def self.execute_cases(tl, envstr,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 = "#{envstr}bundle exec rake testlink:#{spectask} SPEC_OPTS=\"-e #{tc_customfield}\""
    if dryrun
      puts exec_string
    else
      system exec_string
    end
  end
end

.make_env_string(envarr) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/watir_testlink_framework.rb', line 85

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

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



93
94
95
96
97
98
99
100
101
102
103
104
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
# File 'lib/watir_testlink_framework.rb', line 93

def self.report_cases(tl, plan_id, cases, envstring)
  cases_arr ={}
  require 'pp'
  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 |
    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
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
# 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_#{envname}_#{Time.new}"
        tl.create_build(plan_id, buildname, 'created by watir_testlink_framework')

        envstr = make_env_string(envarr)
        self.execute_cases(tl, 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, 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