Re: Workflow Problem: Copy Test Plan to Test Lab (5750 Views)
Reply
Frequent Advisor
Michael Versemann
Posts: 54
Registered: ‎06-17-2008
Message 1 of 23 (8,581 Views)

Workflow Problem: Copy Test Plan to Test Lab

Hi,

i am working on a function to "copy" a test plan folder to test lab, i. e. a folder from test plan "becomes" a folder in test lab. The last folder of the test plan folder will be the test set in test lab.

Now i am hitting a wall in the workflow:
----- begin of code -----

Function build_case(currentId, CurrentPath)
'CurrentId and CurrentPath are set in TestPlan_ActionCanExecute

On Error Resume Next
build_case = False
Set tdcF = TDConnection
Set TStmgr = tdcF.TestSetTreeManager

'split CurrentPath
subjectArray = Split(currentPath, "\")

' NewPath starts with Root instead of Subject'
NewPath = "Root"
OldPath = ""


' Start with 1 because Root exists => no check necessary
For idx = 1 To UBound(subjectArray)
OldPath = NewPath ' Save last known Path
CurrentSubName = subjectArray(idx) 'fetch new Path
NewPath = NewPath & "\" & CurrentSubname 'build full path

'search NewPath
'if exist: nothing to do => next iteration
'else: create folder
Set newNode = TStmgr.NodeByPath(NewPath)

If newNode Is Nothing Then
' branch(not sure if necessary)'
if idx = 1 then
Set myRoot = TStmgr.Root
else
Set myRoot = TStmgr.NodeByPath(OldPath)
end if ' idx'

Set folder = myRoot.addNode(CurrentSubName)
folder.post

End If 'new Node

Next 'idx

On Error GoTo 0
build_case = True
End Function

----- end of code -----

Everything works fine until the script reaches the "set myroot ..." - lines. Before these lines, TStmgr works fine. Now i want ot set myroot and get VB Runtime error 438 (Object doesn't support this property or method) or 451 (Object not a collection).

Anyone got a clue?

Thanks in advance and best regards,
Michael
Occasional Visitor
Rahul Yarlagadda
Posts: 3
Registered: ‎05-17-2011
Message 2 of 23 (8,552 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Hi Michael, were you successful in making the code work ?
Frequent Advisor
Michael Versemann
Posts: 54
Registered: ‎06-17-2008
Message 3 of 23 (8,552 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Hi,

the code works fine.

If anyone is interested i will post the code in this forum.

regards,
Michael
Occasional Visitor
Nemeth Gabor
Posts: 1
Registered: ‎05-20-2011
Message 4 of 23 (8,552 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Hi Michael,

We are working on the same process like you, but we need a small help, because we are stucked.
If you could send for me the whole code then it would be great.

Thanks in advance,
Gábor
Occasional Visitor
Rahul Yarlagadda
Posts: 3
Registered: ‎05-17-2011
Message 5 of 23 (8,552 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

It would really helpful if can post the code. Thanks in advance.
Frequent Advisor
Michael Versemann
Posts: 54
Registered: ‎06-17-2008
Message 6 of 23 (8,552 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Hi Folks,

here is my code:

'-----------------------------------------------------'
'--------- Put these lines in Common Script ----------'
'-----------------------------------------------------'
Dim myFolderID
Dim myFolderPath

'-----------------------------------------------------'

'-----------------------------------------------------'
'----- put the rest of the lines into Test Plan ------'
'-----------------------------------------------------'
Function TestPlan_ActionCanExecute(ActionName)

TestPlan_ActionCanExecute = Project_DefaultRes

'----------- Add this to your existing func ----------'

If ActionName = "copyToLab" And _
User.IsInGroup("Testmanager") Then
' Check if user has correct group
' Change if necessary
copyToLab
End If

'-----------------------------------------------------'
On Error Resume Next
End Function


Sub MoveToSubject(Subject)
On Error Resume Next

myFolderID = Subject.nodeID
myFolderPath = Subject.Path

On Error GoTo 0
End Sub


Sub copyToLab()
On Error Resume Next

'Preparation'
Set tdc = TDConnection
Set treemgr = tdc.treemanager
Set myTestFact = tdc.TestFactory
Set myTestFilter = myTestFact.Filter

' build filter regarding the last known folder'
myTestFilter.Filter("TS_SUBJECT") = "^\" & myFolderPath & "^"
Set myTestList = myTestFact.NewList(myTestFilter.Text)

'are you sure you want to copy?'
strMsg = myTestList.Count & " Testfälle gefunden!" & vbCRLF
strMsg = strMsg & "Kopieren für " & myFolderPath & " starten?"
result = MsgBox (strMsg,vbYesNo,"Test Plan kopieren?")

If result = vbNo Then
' no copy wanted
Exit Sub
End If

'now the fun begins

For Each actTest In myTestList
' Node of Subject-Folder
Set mySNode = actTest.Field("TS_Subject")
' Path of Subject-Folder [Subject\... (w/o Testname)]
myPath = mySNode.Path

'build testset and add testinstance
result = build_case(myPath,actTest)
Next 'Testcase

'now the end is near
MsgBox "Kopieren beendet", vbOKOnly

Set myTestList = Nothing
Set myTestFilter = Nothing
Set myTestFact = Nothing

On Error GoTo 0
End Sub


Function build_case(CurrentPath, CurrentTest)
Dim tdcF
Dim TStmgr
Dim myRoot
Dim newTSTest

On Error Resume Next
' Preparation
Set tdcF = TDConnection
Set TStmgr = tdcF.TestSetTreeManager
' Split path for loop
subjectArray = Split(currentPath, "\")

' initialize variable for path
' Remember: Test Plan begins with Subject and Test Lab with Root!
NewPath = "Root"
OldPath = ""

'Begin loop

For idx = 1 To UBound(subjectArray)
'save path
OldPath = NewPath

'get new folder
CurrentSubName = subjectArray(idx)
'build new path
NewPath = Trim(NewPath) & "\" & CurrentSubname

'search Folder
Set newNode = TStmgr.NodeByPath(NewPath)

'create folder if it does not exist

If newNode Is Nothing Then
Set TStmgr = Nothing
Set TStmgr = tdcF.TestSetTreeManager

If idx = 1 Then
Set myRoot = TStmgr.Root
Else
Set myRoot = TStmgr.NodeByPath(OldPath)
End If ' idx'

Set newNode = myRoot.addNode(CurrentSubName)
newNode.post
End If 'new Node

' if the current folder is the last folder of the array
' create a testset (if necessary) and add the current test

If idx = UBound(subjectArray) Then
'Check: Does the testset exist?
' create a filter with Folder-id and -name
Set testSetF = newNode.TestSetFactory
Set testSetFilter = testSetF.Filter
testSetFilter.Filter("CY_FOLDER_ID") = NewNode.Nodeid
testSetFilter.Filter("CY_CYCLE") = CurrentSubName
Set TSList = testSetF.newList(testSetFilter.Text)

'Add Testset only if necessary

If TSList.Count = 0 Then
'nothing found'
Set testSet1 = testSetF.AddItem(Null)
testSet1.Name = CurrentSubName
testSet1.Status = "Open"
testSet1.Post
Else
'else get it
Set testSet1 = TSList.Item(1)
End If 'TSList

'Check: testinstance
'DO not use FindTestInstance (way too much overhead)
Set TSTestF = TestSet1.TSTestFactory
Set TSTestList = TSTestF.newList("")

'initialize marker
foundTS = 0

If TSTestList.Count > 0 Then

For Each myTSTest In TSTestList

If myTSTest.testId = Trim(CurrentTest.ID & " ") Then
foundTS = 1
End If

Next ' myTSTest

End If ' TSTestList

'Add Test if necessary :)

If foundTS = 0 Then
'nothing found => add test to testset
Set newTSTest = TSTestF.AddItem(CurrentTest.ID)
newTSTest.Post
End If ' foundTS

End If ' idx

'------------------------------------------------------
'Cleanup for objects (just to be sure)
Set newTSTest = Nothing
Set myTSTest = Nothing
Set testSetFilter = Nothing
Set TSTestF = Nothing
Set TSTestList = Nothing
Set testSetFilter = Nothing
Set testSetF = Nothing
Set folder = Nothing
Set newNode = Nothing

Next 'idx

On Error GoTo 0
build_case = True
End Function


This code will be enhanced in the future. For now, it is a brute force method to do what is necessary. :)

Have fun,
Michael
Frequent Advisor
Michael Versemann
Posts: 54
Registered: ‎06-17-2008
Message 7 of 23 (8,306 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Hi,

 

forgot two small but important parts:

 

Test Plan Module:

Sub MoveToSubject(Subject)
  On Error Resume Next
    myFolderID   = Subject.nodeID
    myFolderPath = Subject.Path
  On Error GoTo 0
End Sub

 Test Lab Module:

Sub MoveToFolder(Folder)
  On Error Resume Next

  myTLFolderID   = Folder.nodeID
  myTLFolderPath = Folder.Path

  On Error GoTo 0
End Sub

 Have fun,

Mike

 

Occasional Contributor
vj2012
Posts: 6
Registered: ‎03-20-2012
Message 8 of 23 (7,940 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Spoiler
Spoiler
 

 

Hi ,

I am trying to write a testscript for this using workflow in QC for below.

I am trying to move the test instance in the test lab and paste it in the another folder called "delete trash" folder  which is inside the test lab depend on the status (say filter by "blocked").

 

For ex :

consider a testset which have 10 test instance in test lab .If the status is "Blocked " then I need to move the blocked test instance to seprate folder "delete trash" .

Appreciate your help on this is there a way we can acheive this using workflow script.I am new to workflow so not sure wheter this is possible.

 

 

Honored Contributor
Trudy Claspill
Posts: 3,759
Registered: ‎09-09-2010
Message 9 of 23 (7,921 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

It is poor forum etiquette to tack an unrelated question onto an existing thread. Please start a new thread for your question.
[If this post solves or helps solve your issue, mark the thread as solved and give KUDOS to the author for their assistance.]

(Opinions expressed in my postings are mine alone, and do not reflect the opinions of my employer.No warranties express or implied for any solution/suggestion posted.)
Occasional Visitor
SMehrotra
Posts: 1
Registered: ‎07-10-2012
Message 10 of 23 (7,312 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Hi,

 

I used the code given by you. Could successfully create a button in Test Plan module to invoke the function on the click. But, I guess I may be missing something because folders from Test Plan are not getting copied to Test Lab. Any help would be appreciated!

 

Do I need to have Admin rights to have this script work for me?

 

Thanks!

Sandy

Established Member
JaneteMartins
Posts: 3
Registered: ‎09-10-2012
Message 11 of 23 (6,763 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Hello,

I have a similar request and maybe you could help me giving me any ideias to solve my problem.
For exemple I have a test plan folder named XYZ, and for XYZ I have several test lab folders named XYZ1, XYZ2.
If I had an excel with the name of the test plan folder and the name I would like to give for each test lab folder, for exemple:
 TestPlan | TestLab
 XYZ      | VYZ1
 XYZ      | XYZ2
.....
 there would be a way to create those folders in test lab using a macro and OTA script?
 
 Thank you.

Occasional Advisor
arch84
Posts: 6
Registered: ‎02-07-2013
Message 12 of 23 (5,750 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

[ Edited ]

Hi,

 

  In ALM 11, some of the methods are not there.

 

 I tried the following code and it works fine. Improvements and sugestions are welcome!. I tried checking only single folder structure with testcases.

 

Function PortToTestLab(testPlanPath,testLabPath,testSetName,testType)

    Set tdc         = TDConnection
    Set treeMng     = tdc.TreeManager
    Set TestNode    = treeMng.nodebypath(testPlanPath)
    Set TestFact    = TestNode.TestFactory
    Set TestsList   = TestFact.NewList("")
    
    Set TStreeMng   = tdc.TestSetTreeManager
    Set TreeNode    = TStreeMng.NodebyPath(testLabPath)
    Set TestSetFact = TreeNode.TestSetFactory
    
    Set NewTestSet=TestSetFact.AddItem(Null)' Creates new testset
    NewTestSet.name = testSetName
    NewTestSet.Field("CY_COMMENT") = testSetName
    NewTestSet.status="Open"
    NewTestSet.post

    Set testfac = NewTestSet.TSTestFactory

    For Each tests In TestsList

        If tests.Field("TS_TYPE")= testType Then

           Set tmptstset = testfac.AddItem(tests.ID)

        End If
    Next

End Function

=======

Call the function like the one mentioned below:

 PortToTestLab "Subject\arkas", "Root\arkas", "auto", "MANUAL"

 

Occasional Advisor
arch84
Posts: 6
Registered: ‎02-07-2013
Message 13 of 23 (5,701 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

In the below code snippet, the search folder step is not working.. Its not throwing any error. It just did not work. Not sure what I am missing it here. I assume that if there is no folder by the name searched in TestLab, the newNode variable is not initialized and then the code moves to If loop as "Is Nothing" condition is satisfied. My code stops n the set newNode step itself. Please throw some light in this issue, if u have some time..
'search Folder
Set newNode = TStmgr.NodeByPath(NewPath)

'create folder if it does not exist 

If newNode Is Nothing Then
Set TStmgr = Nothing
Set TStmgr = tdcF.TestSetTreeManager

If idx = 1 Then
Set myRoot = TStmgr.Root
Else
Set myRoot = TStmgr.NodeByPath(OldPath)
End If ' idx'

 

Occasional Visitor
ARI2013
Posts: 2
Registered: ‎04-04-2013
Message 14 of 23 (5,275 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Hi , I'm trying to coy  test case from test plan to test lab folder, where a new test set will be created through code & test cases will be added.When trying to run the below code , getting error in the section, where - after calling the function CopyTTestLb , trying to set the node in the below line.

Error says OTA server not available. Though I added the reference from tool tab of the XL , getting the same error. I'm in QC 10. 

 

Please help to correct the issue.

 

"Set TestNode = treeMng.NodeByPath(testPlanPath)"

 

'########################################################

 

'CALLING THE FUNCTIONA TO COPY TEST CASE UNDER A TEST SET

 

Call CopyTTestLb("Root\TESTPLAN", "Sub\TESTSET", "TESTSET", "MANUAL")

 

Set objQCConnection = Nothing

End Sub


'#############################################################################################################

Function CopyTTestLb(testPlanPath, testLabPath, testSetName, testType)

    Set tdc = TDConnection
    Set treeMng = tdc.TreeManager
    Set TestNode = treeMng.NodeByPath(testPlanPath)
    Set TestFact = TestNode.TestFactory
    Set TestsList = TestFact.NewList("")
   
    Set TStreeMng = tdc.TestSetTreeManager
    Set TreeNode = TStreeMng.NodeByPath(testLabPath)
    Set TestSetFact = TreeNode.TestSetFactory
   
    Set NewTestSet = TestSetFact.AddItem(Null) ' Creates new testset
    NewTestSet.Name = testSetName
    NewTestSet.Field("CY_COMMENT") = testSetName
    NewTestSet.Status = "Open"
    NewTestSet.Post

    Set testfac = NewTestSet.TSTestFactory

    For Each tests In TestsList

        If tests.Field("TS_TYPE") = testType Then

           Set tmptstset = testfac.AddItem(tests.ID)

        End If
    Next

End Function


 

Frequent Advisor
Michael Versemann
Posts: 54
Registered: ‎06-17-2008
Message 15 of 23 (3,529 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Sorry,

I have been away for a while.

I have not thought about moving test, only copying. So I will think about it and post a message.
Frequent Advisor
Michael Versemann
Posts: 54
Registered: ‎06-17-2008
Message 16 of 23 (3,527 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Hi SMehrotra,

did you remember to write some code in ActionCanExecute to invoke the code?

Regards,
Michael
Frequent Advisor
Michael Versemann
Posts: 54
Registered: ‎06-17-2008
Message 17 of 23 (3,527 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Hi,

yes you can use a OTA-script to create the folders.

It is similar to my code. Just omitt the creating of testsets and instances.

Regards,
Mike
Frequent Advisor
Michael Versemann
Posts: 54
Registered: ‎06-17-2008
Message 18 of 23 (3,526 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Hi arch84,

I have to look into the coding.

I will post later this month.

Regards,
Michael
Frequent Advisor
Michael Versemann
Posts: 54
Registered: ‎06-17-2008
Message 19 of 23 (3,526 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Hi ARI2013,

I will post later this month on yur issue.

Regards,
Michael
Occasional Visitor
Ryan Rapier
Posts: 4
Registered: ‎01-10-2006
Message 20 of 23 (3,435 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Will this work on QC 9.0?

 

if so, i'm a newbie to workflow items and script editor...can someone give me a walk through/how to for this?

Honored Contributor
Trudy Claspill
Posts: 3,759
Registered: ‎09-09-2010
Message 21 of 23 (3,427 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

There is another thread on this same topic that you may find helpful. Note the code in that thread has not been tested on QC 9.0.
http://h30499.www3.hp.com/t5/Quality-Center-Support-and-News/Test-Plan-folders-export-to-Test-Lab-in...
[If this post solves or helps solve your issue, mark the thread as solved and give KUDOS to the author for their assistance.]

(Opinions expressed in my postings are mine alone, and do not reflect the opinions of my employer.No warranties express or implied for any solution/suggestion posted.)
Occasional Visitor
myqc
Posts: 1
Registered: ‎04-03-2014
Message 22 of 23 (2,267 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Hello,

 

I'm new to QC (using HP QC 11.00) and would like to get assistance in applying this code making it happen to copy from test plan to test lab.

Please , could you hel^p me in this?

 

Thanks  

Honored Contributor
Trudy Claspill
Posts: 3,759
Registered: ‎09-09-2010
Message 23 of 23 (2,256 Views)

Re: Workflow Problem: Copy Test Plan to Test Lab

Refer to the thread I mentioned in my previous response. It includes a document with instructions.
http://h30499.www3.hp.com/t5/Quality-Center-Support-and-News/Test-Plan-folders-export-to-Test-Lab-in...

If you have questions about those instructions, respond on that thread with your specific question.
[If this post solves or helps solve your issue, mark the thread as solved and give KUDOS to the author for their assistance.]

(Opinions expressed in my postings are mine alone, and do not reflect the opinions of my employer.No warranties express or implied for any solution/suggestion posted.)
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.