Vous êtes sur la page 1sur 8

Start by logging into your project and undoing the previous changes.

Then Create a toolbar button in the Test Plan module: 1. Go to Tools > Customize > Script Editor 2. Click the Toolbar Button Editor tab 3. In the "Command bar" pull down list select "TestPlan" 4. Click the Add button. This adds a new button named "TestPlan_Command#" 5. Change the value in the Caption field to "CopyToLab" 6. Change the value in the Hint field to "Copy to lab" 7. Change the value in the Action Name field to "copytolab" 8. Select an image for the button. 9. Click Apply 10. Click Save Modify workflow code to tie the new button to new functionality: 11. Click the Script Editor tab 12. Navigate to Workflow Scripts > Project Scripts > Common Script. 13. Click on ActionCanExecute 14. Put the below code into the ActionCanExecute script, between the two lines that start with "On Error"

15. Click Save

Modify workflow code to record the current Test Plan folder: 16. Navigate to Workflow Scripts > Project Scripts > Test Plan module script 17. Click on the TestFolder_MoveTo script 18. Declare variables before the On Error Resume Next statement. Insert additional code into the TestFolder_MoveTo script between the lines that start with "On Error"

19. Click Save

Add custom subroutines: 20. Navigate to Workflow Scripts > Project Scripts > Extensions script 21. Insert the below code
Sub copyToLab() On Error Resume Next dim strMsg dim result dim myPath

dim tdc dim treemgr dim myTestFact dim myTestFilter dim myTestList dim mySNode dim actTest

'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 & " Test Cases to move to Lab" & vbCRLF strMsg = strMsg & "Start copy of " & myFolderPath & " to Test Lab?" result = MsgBox (strMsg,vbYesNo,"Test Plan copy?")

If result = vbNo Then ' no copy wanted MsgBox "Test Plan not copied" 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 'MsgBox "Node path " & myPath 'build testset and add testinstance result = build_case(myPath,actTest) Next 'Testcase

'now the end is near MsgBox "copy finished", 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

dim subjectArray dim NewPath Dim OldPath dim idx dim CurrentSubName dim newNode

dim testSetF dim testSetFilter dim TSList

dim TSTestF dim TSTestList

dim foundTS dim myTSTest

On Error Resume Next ' Preparation 'msgbox "build_case" 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 'msgbox "NewPath: " & NewPath 'search Folder Set newNode = TStmgr.NodeByPath(NewPath)

'create folder if it does not exist

If newNode Is Nothing Then 'msgbox "create folder " 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 'msgbox "last folder in path" 'msgbox "does test set exist?" '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 'msgbox "test set " & CurrentSubName & "does not exist in folder" '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

Add global variables needed by new code: 22. Navigate to Workflow Scripts > Project Scripts > Common Script. 23. Insert the following lines, above the declaration for "Function ActionCanExecute()"
Dim myFolderID Dim myFolderPath

24. Click Save

25. Close the Script Editor 26. In the Customize screen click Return

27. Click the Minor Changes radio button and click OK

You should now see a button in the Test Plan module toolbar for copying test plan folders and cases to the Test Lab.

Here are some caveats: - If you execute the copy function, then remove a test case from one of the copied folders in the Test Plan and re-execute the function, the corresponding Test Instance will be removed from the Test Set in the Test Lab. - If you execute the copy function, then remove a folder in the Test Plan and re-execute the function, the corresponding Folder/Test Sets are not removed from the Test Lab, but corresponding Test Instance will be removed from the Test Set in the Test Lab. - If you re-execute the procedure, Test Instances created by a previous copy execution will not be overwritten. - If you rename a folder in the Test Plan and re-execute the copy function, a new folder/test set with that name will be created in the Test Lab. - I did not test it for users with different privileges, so I don't know what will happen if a user that doesn't have rights to create folders/test sets or add tests to a test set tries to use it.

Vous aimerez peut-être aussi