Renaming test plan folder using OTA API

In this post, we will discuss how to rename a test plan folder using OTA API. We will use C# for this post

To rename a test plan folder we will use the following classes

  1. SysTreeNode – For renaming Folder
  2. TreeManager – For getting SysTreeNode Object from the folder path

First, we will get the SysTreeNode Object for the parent folder path

TDAPIOLELib.TreeManager OTManager = tDConnection.TreeManager;
TDAPIOLELib.SysTreeNode OParentFolder = OTManager.NodeByPath[folderPath];

in the above code, tDConnection is the connection object. You can read about it here

After this, we will find the folder to be renamed under this folder

OParentFolder = GetNodeObject(parentFolderPath);
TDAPIOLELib.SysTreeNode OCurrentFolder = OParentFolder.FindChildNode(currentFolderName) as TDAPIOLELib.SysTreeNode;

Once we have the folder object, we can simply rename it using the below command

OCurrentFolder.Name = newFolderName;
OCurrentFolder.Post();

Complete Code

public Boolean Rename(String parentFolderPath, String currentFolderName, String newFolderName)
{
TDAPIOLELib.SysTreeNode OParentFolder = GetNodeObject(parentFolderPath);
TDAPIOLELib.SysTreeNode OCurrentFolder = OParentFolder.FindChildNode(currentFolderName) as TDAPIOLELib.SysTreeNode;
OCurrentFolder.Name = newFolderName;
OCurrentFolder.Post();
return true;
}
public TDAPIOLELib.SysTreeNode GetNodeObject(String folderPath, TDAPIOLELib.TDConnection tDConnection)
{
TDAPIOLELib.TreeManager OTManager = tDConnection.TreeManager;
return OTManager.NodeByPath[folderPath];
}

Let me know if you have any questions in Comments.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s