We use test automation fairly extensively..
I have been working on a simple TC execution update class for our automation test suite.
In theory I should just be able to add a line to the executions table.
If I pass the build, date, status, and tc_versionId.
My question is how do I make sure that I have the correct tc_versionID.
In test plan execution mode the version id does not seem to be the same as Test Case ID displayed in edit mode.. The ID for execution appears to be the Test Case ID + 1 in most cases..
What am I missing to get the current versioID to update the executions table based on the testcase id in execution mode..
Update execution -- SQL query
Got it!!! -- Updating results via Automation..
We are using WATIR for our test automation..
Here is how we are updating the results --
Class -- called testlink
tc is an array of test cases ID's based on ID in edit mode.
trPass or trFail will call TLresults2 (tc, status,notes)
TLresults2 will:
Check for the value of a Global Build ID and Test Plan variable.
If not set then assume -- FULL regression plan and go find the latest build.
Set UserID to an Automated User Account (by ID)
get Current timestamp and set DB connection (ODBC)
for each Test Case passed in array tc :
- Query nodes_hierarchy table to get most recent tc_version id.
- build insert query to executions table
- run insert
The trick was getting the tc_versionid since the results are stored against the versionid and not the tcid in edit mode. The version id will change if you start saving versions.. I wanted to make sure we were always using the latest.
Now in my error handling routine I call trFail and pass the exception.. which falls into notes.
If now exceptions I set the trPass at the end of the scipt execution.
---- very simple test script example in watir
def test_assert1
begin
w = Web_actions_login.new
tc = Array.new
tl = Testlink.new
tc = [665 ,731]
puts tc
# Login ##############
#ie=w.admin_login
##################
assert(ie.button("JUNJK").exists?, "Failure is eminent")
rescue Exception => ex
tl.trFail(tc,ex)
else
puts "Passing Test Case(s)"
tl.trPass(tc)
end
end
end
---- class that updates Testlink
class Testlink
def trFail(tc ,ex)
puts "An Assertion in the script Failed: "+ex
puts "The Execution Trace is: " + ex.backtrace.join("/n")
puts "Failing Test Case(s)"
TLresults2(tc, 'f',ex.message)
flunk "Assertion : " +ex + "\n" +"StackDump : " +ex.backtrace.join("\n")
end
def trPass(tc)
tc.each{|i| puts "Test Completed - Passing Test Cases" + i.to_s}
TLresults2(tc, 'p',"Test Passed! - Automation")
end
def TLresults2 (tc, status,notes)
c = ODBC::connect('testlink')
# Get Time Stamp
t = Time.now
timestamp = t.strftime("%Y-%m-%d %H:%M:%S")
notes = notes.gsub(/'/,'"')
# Set Testlink TestPlan
if !$tl_tpID then
tpID = 3525
#Full Regression Test Test Plan
else
tpID = $tl_tpID
end
#get most current build
if !$tl_build then
query = "select id from Builds where testplan_id = 3525 order by id desc"
data = c.run(query)
$tl_build = data.fetch
buildID = $tl_build
else
buildID = $tl_build
end
#Set Tester as Automation User
testerID = 7
# for each TC in array get version id and update results table
tc.each{|i|
tcID = i.to_s
query = "select id from nodes_hierarchy where parent_id = "+tcID+" order by id desc"
data = c.run(query)
results = data.fetch
tcvID = results[0].to_s
puts "TCVID: " + tcvID
query = "INSERT INTO executions(build_id,tester_id,status,testplan_id,tcversion_id,execution_ts,notes) VALUES("+buildID.to_s+","+testerID.to_s+",'"+status+"',"+tpID.to_s+","+tcvID+",'"+timestamp+"','"+notes+"')"
puts query
data = c.run(query)
res = data.fetch
}
c.disconnect
end
end
Here is how we are updating the results --
Class -- called testlink
tc is an array of test cases ID's based on ID in edit mode.
trPass or trFail will call TLresults2 (tc, status,notes)
TLresults2 will:
Check for the value of a Global Build ID and Test Plan variable.
If not set then assume -- FULL regression plan and go find the latest build.
Set UserID to an Automated User Account (by ID)
get Current timestamp and set DB connection (ODBC)
for each Test Case passed in array tc :
- Query nodes_hierarchy table to get most recent tc_version id.
- build insert query to executions table
- run insert
The trick was getting the tc_versionid since the results are stored against the versionid and not the tcid in edit mode. The version id will change if you start saving versions.. I wanted to make sure we were always using the latest.
Now in my error handling routine I call trFail and pass the exception.. which falls into notes.
If now exceptions I set the trPass at the end of the scipt execution.
---- very simple test script example in watir
def test_assert1
begin
w = Web_actions_login.new
tc = Array.new
tl = Testlink.new
tc = [665 ,731]
puts tc
# Login ##############
#ie=w.admin_login
##################
assert(ie.button("JUNJK").exists?, "Failure is eminent")
rescue Exception => ex
tl.trFail(tc,ex)
else
puts "Passing Test Case(s)"
tl.trPass(tc)
end
end
end
---- class that updates Testlink
class Testlink
def trFail(tc ,ex)
puts "An Assertion in the script Failed: "+ex
puts "The Execution Trace is: " + ex.backtrace.join("/n")
puts "Failing Test Case(s)"
TLresults2(tc, 'f',ex.message)
flunk "Assertion : " +ex + "\n" +"StackDump : " +ex.backtrace.join("\n")
end
def trPass(tc)
tc.each{|i| puts "Test Completed - Passing Test Cases" + i.to_s}
TLresults2(tc, 'p',"Test Passed! - Automation")
end
def TLresults2 (tc, status,notes)
c = ODBC::connect('testlink')
# Get Time Stamp
t = Time.now
timestamp = t.strftime("%Y-%m-%d %H:%M:%S")
notes = notes.gsub(/'/,'"')
# Set Testlink TestPlan
if !$tl_tpID then
tpID = 3525
#Full Regression Test Test Plan
else
tpID = $tl_tpID
end
#get most current build
if !$tl_build then
query = "select id from Builds where testplan_id = 3525 order by id desc"
data = c.run(query)
$tl_build = data.fetch
buildID = $tl_build
else
buildID = $tl_build
end
#Set Tester as Automation User
testerID = 7
# for each TC in array get version id and update results table
tc.each{|i|
tcID = i.to_s
query = "select id from nodes_hierarchy where parent_id = "+tcID+" order by id desc"
data = c.run(query)
results = data.fetch
tcvID = results[0].to_s
puts "TCVID: " + tcvID
query = "INSERT INTO executions(build_id,tester_id,status,testplan_id,tcversion_id,execution_ts,notes) VALUES("+buildID.to_s+","+testerID.to_s+",'"+status+"',"+tpID.to_s+","+tcvID+",'"+timestamp+"','"+notes+"')"
puts query
data = c.run(query)
res = data.fetch
}
c.disconnect
end
end