|
require 'win32ole'
|
|
require 'rubygems'
|
|
require 'highline/import'
|
|
|
|
def get_interface_iid(interface_name)
|
|
require 'win32/registry'
|
|
interface_iid = ''
|
|
reg_interface = Win32::Registry::HKEY_CLASSES_ROOT.open('Interface')
|
|
reg_interface.each_key {|subkey, wtime| key = subkey.to_s
|
|
reg_subkey = reg_interface.open(key)
|
|
begin
|
|
interface_iid = key if reg_subkey.read_s('') == interface_name
|
|
rescue
|
|
next
|
|
end
|
|
}
|
|
reg_interface.close()
|
|
return interface_iid
|
|
end
|
|
|
|
system 'cls'
|
|
tdcon = WIN32OLE.new('TDApiOle80.TDConnection')
|
|
|
|
puts 'Starting to login QualityCenter...'
|
|
url = 'https://qc10.xxx.com/qcbin'
|
|
login_domain = 'Domain'
|
|
login_project = 'Project'
|
|
wk_of_year = Time.now.strftime("%U").to_i
|
|
|
|
puts "\nConnect to server..."
|
|
tdcon.InitConnectionEx(url)
|
|
# puts " Server Name = #{tdcon.ServerName}"
|
|
puts " Connected = #{tdcon.Connected}"
|
|
puts "\nAuthenticate user..."
|
|
begin
|
|
login_name = ask(" Please enter your user name: ")
|
|
login_password = ask(" Please enter your password: ") {|q| q.echo = '*'}
|
|
tdcon.Login(login_name, login_password)
|
|
rescue => exception
|
|
regex_exception = /error code.*?\n.*?\n/
|
|
exception = regex_exception.match(exception.to_s).to_s.gsub(/error code.*?\n/, '').chomp.gsub(/^\s+/, '')
|
|
puts " #{exception}"
|
|
retry
|
|
end
|
|
puts " LoggedIn = #{tdcon.LoggedIn}"
|
|
puts "\nLogin Project..."
|
|
tdcon.Connect(login_domain, login_project)
|
|
puts " ConnectedToProject = #{tdcon.ProjectConnected}"
|
|
|
|
def check_node_and_add(td_connection, path, node)
|
|
puts "\nFinding folder \"#{node}\"..."
|
|
begin
|
|
td_connection.TestSetTreeManager.NodeByPath(path).FindChildNode(node)
|
|
rescue => exception
|
|
regex_exception = /error code.*?\n.*?\n/
|
|
exception = regex_exception.match(exception.to_s).to_s.gsub(/error code.*?\n/, '').chomp.gsub(/^\s+/, '')
|
|
if exception == "Node not found."
|
|
puts " #{exception} Folder will be created."
|
|
puts " Folder has been created successfully." if td_connection.TestSetTreeManager.NodeByPath(path).AddNode(node)
|
|
end
|
|
end
|
|
puts " Folder exists already." if exception == nil
|
|
end
|
|
|
|
path_1 = "Root\\Project1\\Test"
|
|
path_2 = "Root\\Project2\\Test"
|
|
|
|
check_node_and_add(tdcon, path_1, "wk#{wk_of_year}")
|
|
check_node_and_add(tdcon, "#{path_1}\\wk#{wk_of_year}", "Component")
|
|
|
|
iid_ISupportCopyPaste = get_interface_iid('ISupportCopyPaste')
|
|
copied_id = tdcon.TestSetTreeManager.NodeByPath("#{path_1}\\wk30\\Component").FindTestSets("BAT_2010_0808").Item(1).ID
|
|
pasted_id = tdcon.TestSetTreeManager.NodeByPath("#{path_1}\\wk#{wk_of_year}\\Component").NodeID
|
|
tstsf = tdcon.TestSetTreeManager.NodeByPath("#{path_1}\\wk30\\Component").TestSetFactory
|
|
iscp = tstsf.ole_query_interface(iid_ISupportCopyPaste)
|
|
clipboard = iscp.CopyToClipBoard(copied_id, 0, "")
|
|
iscp.PasteFromClipBoard(clipboard, pasted_id)
|
|
puts "\nTestSet has been copied to this week's test folder"
|
|
|
|
puts "\nDisconnect from project..."
|
|
tdcon.Disconnect()
|
|
puts " ConnectedToProject = #{tdcon.ProjectConnected}"
|
|
puts "\nLogout..."
|
|
tdcon.Logout()
|
|
puts " LoggedIn = #{tdcon.LoggedIn}"
|
|
puts "\nFinish connection..."
|
|
tdcon.ReleaseConnection()
|
|
puts " Connected = #{tdcon.Connected}"
|