Thursday 4 March 2010

Test Complete and Ruby

So I'm working on a test automation project using Test Complete and desperate to get away from having to use Test Complete's gigantic front end. So here's the good news. Test Complete has an open API. (Well first you need to purchase a licence). But this means that I can use Ruby to connect to TC and Cucumber as my test framework. Once in the Cucumber domain you can look at Hudson or another CI tool.

So the first thing I did was to convert the TCConnect.bas file which contains all of the methods required.

First Make the connection:

require 'Win32API'
require 'win32ole'

cTestCompleteApplication = "TestComplete.TestCompleteApplication.7"
begin
searchTC = WIN32OLE.connect(cTestCompleteApplication)
searchTC.visible = true
rescue WIN32OLERuntimeError
Thread.new {searchTC = WIN32OLE.new(cTestCompleteApplication)}
searchTC.visible = true
end

def is_runner_active
puts "Checking Runner Activity..."
#Check TC IsRunning
timeout = 1
while searchTC.Integration.IsRunning == false do
sleep(2)
timeout = timeout + 1
puts "waiting for Test Complete to start up...runner state: #{searchTC.Integration.IsRunning}"
if timeout > 15 then
puts "Test complete is going no where"
exit
end
end
end

#Open up Test Complete Project
DATA_PATH = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "TCProject"))
filepath = File.join(DATA_PATH, "TCAutomationProject.pjs")

$runner = searchTC.Integration.GetObjectByName("Runner")

if searchTC.Integration.IsRunning == true then
puts "Test Complete is already running"
else
puts "Test Complete is NOT already running..."
searchTC.Integration.OpenProjectSuite(filepath.gsub("/","\\"))
TestEngine = searchTC.Manager.ManagersByString("{555A3A53-8D35-4F93-9570-00662CF627C6}")
Thread.new { TestEngine.RunConnected("TestLog", "Automation_Script"); is_runner_active; }
#Give TC a chance to startup correctly
sleep(1)
puts "Test Complete started..."
end

testedApps = searchTC.Integration.GetObjectByName("TestedApps")
connectedApp = testedApps.MyConnectedApp.Run

No comments:

Post a Comment