In this post, we will discuss creating folders in ALM Test plan using OTA API. We will use C#.
To create a folder in test plan using OTA API we will use the following Classes from OTA API.
- TreeManager – To get the SysTreeNode Object.
- SysTreeNode – To add the new test folder in the TestPlan.
First, we will get the SysTreeNode Object of the current folder path from the test plan. So, if you want to create a folder under Subject folder then we will need to get the SysTreeNode object of the Subject Folder.
TDAPIOLELib.TreeManager OTManager = tDConnection.TreeManager; TDAPIOLELib.SysTreeNode OSysTreeNode = OTManager.NodeByPath[folderPath];
Where Folder Path will be “Subject”, if you want to create a Folder under Subject Folder.
Once we have the SysTreeNode Object then we will just have to add the new folder
OSysTreeNode.AddNode(newFolderName);
Complete Code
public Boolean Create(String parentFolderPath, String newFolderName) { TDAPIOLELib.SysTreeNode OSysTreeNode = GetNodeObject(parentFolderPath); OSysTreeNode.AddNode(newFolderName); return true; } public TDAPIOLELib.SysTreeNode GetNodeObject(String folderPath) { TDAPIOLELib.TreeManager OTManager = tDConnection.TreeManager; return OTManager.NodeByPath[folderPath]; }
To create a new Folder under Subject Folder, You can call the create Function like this
Create("Subject", "Dummy1");
To create a new folder under this Dummy1 folder
Create("Subject\\Dummy1", "Dummy2");
Let me know if you have any questions in Comments.