Académique Documents
Professionnel Documents
Culture Documents
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"
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"
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
' 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
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
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
'get new folder CurrentSubName = subjectArray(idx) 'build new path NewPath = Trim(NewPath) & "\" & CurrentSubname 'msgbox "NewPath: " & NewPath 'search Folder Set newNode = TStmgr.NodeByPath(NewPath)
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'
' 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 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("")
For Each myTSTest In TSTestList If myTSTest.testId = Trim(CurrentTest.ID & " ") Then foundTS = 1 End If Next ' myTSTest
If foundTS = 0 Then
'nothing found => add test to testset Set newTSTest = TSTestF.AddItem(CurrentTest.ID) newTSTest.Post End If ' foundTS
'-------------------------------------------------?----'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
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
25. Close the Script Editor 26. In the Customize screen click Return
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.