In this post, we will discuss how to delete test plan folder using OTA API. We will use C# for this tutorial.
We will use the following classes for deleting the test plan folder
- SysTreeNode : For deleting the test plan folder
- TreeManager : For finding the folder in the test plan.
First, we will get the SysTreeNode Object for the parent folder
TDAPIOLELib.TreeManager OTManager = tDConnection.TreeManager; TDAPIOLELib.SysTreeNode parentNode = OTManager.NodeByPath[folderPath];
Where tDConnection is the ALM Connection object. You can read about it here.
After this, we will search for the folder to be deleted
TDAPIOLELib.SysTreeNode NodeToBeDeleted = parentNode.FindChildNode(deleteFolderName) as TDAPIOLELib.SysTreeNode;
Once we have the SysTreeNode object for the folder we can delete it using the below command.
parentNode.RemoveNode(NodeToBeDeleted);
Below is the complete Code
public Boolean Delete(String parentFolderPath, String deleteFolderName)
{
TDAPIOLELib.SysTreeNode parentNode= GetNodeObject(parentFolderPath);
TDAPIOLELib.SysTreeNode NodeToBeDeleted = parentNode.FindChildNode(deleteFolderName) as TDAPIOLELib.SysTreeNode;
if (NodeToBeDeleted.NodeID > 0)
{
parentNode.RemoveNode(NodeToBeDeleted);
return true;
}
else
{
return false;
}
}
public TDAPIOLELib.SysTreeNode GetNodeObject(String folderPath)
{
TDAPIOLELib.TreeManager OTManager = tDConnection.TreeManager;
return OTManager.NodeByPath[folderPath];
}
If you want to delete Dummy2 folder in path “Subject\Dummy1\Dummy2” then you can call the delete function like below
Delete("Subject\\Dummy1", "Dummy2");
Let me know if you have any questions in Comments.
