How do I create a Test Definition using the SilkCentral Test Manager Web Services?

0 Likes

Problem:

How do I create a Test Definition using the SilkCentral Test Manager Web Services?

Resolution:

To create a new Test Definition via the SilkCentral Web Services we need to make use of the following Class stubs:

  • SccsystemSoapBindingStub
  • TmplanningSoapBindingStub
  • TestPlanningNode
  • PropertyValue

Before we can begin interacting with SilkCentral Test Manager we must first login and obtain a session id, all interactions with the SilkCentral Test Manager Web Services require that we provide a session id. To login we create an instance of the class "SccsystemSoapBindingStub" which provides us with a method to login to SilkCentral and obtain a session id:

//Variables

SccsystemSoapBindingStub bind;
long sessionID;

....

....

public void GetSessionID(){

//Generate the session ID
try{
bind = (SccsystemSoapBindingStub)new SystemServiceServiceLocator().getsccsystem();
logonUser("admin","admin");
}
catch(Exception e){
e.printStackTrace();
}
}

public void logonUser(String username, String password){

try{
sessionID = bind.logonUser(username, password);
}
catch(Exception e){
e.printStackTrace();
}

}

When the above method, GetSessionID, is executed it calls the local logonUser function which uses the Web Service function logonUser to login to SilkCentral Test Manager using the provided credentials and obtain a session id. This session id is stored in the variable sessionID which is available to all methods in our Java class. Now that we have generated our session id we can now use the test planning Web Service to create our Test Definition, let us firstly retrieve the test planning Web Service which will provide with all the required functionality that we require:

//Variables

SccsystemSoapBindingStub bind;
TmplanningSoapBindingStub plnBind;
long sessionID;

....

....

public void GetPlanningService(){

//Generate the test planning service
try{
plnBind = (TmplanningSoapBindingStub) new PlanningServiceServiceLocator().gettmplanning();
}
catch(Exception e){
e.printStackTrace();
}
}

Now that we have access to the test planning service we can proceed with the creation of our Test Definition. When creating a Test Definition using the Web Services we use the class TestPlanningNode to store the information with regards to the Test Definition we wish to create. Let us look at the code for creating a Test Definition via the Web Services:

....

....

public void createTD(){
try{
TestPlanningNode newTestDef = new TestPlanningNode();
newTestDef.setKind(3); //3 represents a node which is a Test Definition
newTestDef.setPropertyValues(getTestDefProps());
plnBind.addNode(sessionID, , newTestDef, false);
}
catch(Exception e){
e.printStackTrace();
}
}

In the above code excerpt we make use of the method getTestDefProps which will be demonstrated later and which should be replaced with the ID of the Test Container or folder to which this new Test Definition should be added. The getTestDefProps method is quite important as this will set all the relevant information with regards to your Test Definition, it also important as most errors that occur when creating a Test Definition arise due to some missing property information. The method getTestDefProps below will demonstrate how to set and return the relevant properties for a SilkTest Test Definition:

public PropertyValue[] getTestDefProps(){
PropertyValue pvName, pvDesc, pvTestType,pvScript,pvTestCase,
pvDataDriven,pvTestData,pvOptionSet,pvInherit;

pvName = new PropertyValue();
pvName.setName("Name");
pvName.setPropertyTypeID("_node_properties_");
pvName.setPropertyID("_node_properties_Name");
pvName.setValue("SilkTest Web Services");

pvDesc = new PropertyValue();
pvDesc.setPropertyTypeID("_node_properties_");
pvDesc.setPropertyID("_node_properties_Description");
pvDesc.setValue("SilkTest Web Services Description");

pvTestType = new PropertyValue();
pvTestType.setPropertyTypeID("_test_def_type_");
pvTestType.setPropertyID("_test_def_type_st_");
pvTestType.setValue("_st_");

pvScript = new PropertyValue();
pvScript.setPropertyTypeID("_st_");
pvScript.setPropertyID("Script File");
pvScript.setValue("MyTest.t");

pvTestCase = new PropertyValue();
pvTestCase.setPropertyTypeID("_st_");
pvTestCase.setPropertyID("TestCase");
pvTestCase.setValue("testcaseOne");

pvDataDriven = new PropertyValue();
pvDataDriven.setPropertyTypeID("_st_");
pvDataDriven.setPropertyID("DataDriven");
pvDataDriven.setValue("true");

pvTestData = new PropertyValue();
pvTestData.setPropertyTypeID("_st_");
pvTestData.setPropertyID("TestData");
pvTestData.setValue("\"arg1\",\"arg2\",\"arg3\"");

pvOptionSet = new PropertyValue();
pvOptionSet.setPropertyTypeID("_st_");
pvOptionSet.setPropertyID("OptionSet");
pvOptionSet.setValue("MyOpt.t");

pvInherit = new PropertyValue();
pvInherit.setPropertyTypeID("_node_properties_");
pvInherit.setPropertyID("InheritAttributes");
pvInherit.setValue("true");

return new PropertyValue[]{pvName, pvDesc,pvTestType,pvScript,
pvTestCase,pvDataDriven,pvTestData,pvOptionSet,pvInherit};
}


Old KB# 25093
Comment List
Anonymous
Related Discussions
Recommended