Topic
5 replies Latest Post - ‏2010-12-15T06:01:33Z by SystemAdmin
SystemAdmin
SystemAdmin
1545 Posts
ACCEPTED ANSWER

Pinned topic TM API: How to get Test Result.

‏2010-12-11T06:57:38Z |
Hello,

Using TM API, I can get TestCase or TestScript object from TM. Can anyone share me an example about how to get the test result(pass or failed) through a TestCase and/or TestLogEvent objects etc?

Thanks a lot in advance!

Andrew
Updated on 2010-12-15T06:01:33Z at 2010-12-15T06:01:33Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    1545 Posts
    ACCEPTED ANSWER

    Re: TM API: How to get Test Result.

    ‏2010-12-13T14:53:42Z  in response to SystemAdmin
    Hello,

    I want to use API to get the testcase's result(pass or fail). I still could not figure it out after browsing through TMSComServerLib and TMSUILib and some TM API examples on the web.

    Could someone please help?

    Thanks a lot in advance!
    Andrew
    • SystemAdmin
      SystemAdmin
      1545 Posts
      ACCEPTED ANSWER

      Re: TM API: How to get Test Result.

      ‏2010-12-14T14:38:56Z  in response to SystemAdmin
      bool CGenerateXML::GenerateStepResultsForResult(ITMSLogEventPtr piLogEventPtr, CXMLNode *pRootElement)
      {
      ..
      .. CXMLElementNode *pStepResultsNode = new CXMLElementNode();
      pStepResultsNode->setNodeName("er:stepResults");
      CString sScriptName;

      if (piLogEventPtr != NULL) {
      ITMSLogEventPtr piScriptEventPtr = piLogEventPtr->GetNextLogEvent();
      if (piScriptEventPtr != NULL) {
      TMS_LOG_EVENT_TYPE eventType = (TMS_LOG_EVENT_TYPE) piScriptEventPtr->GetEventType();
      if (eventType == TMS_LOG_EVENT_TYPE_SCRIPT_START) {
      /*
      try {
      ITMSVariantArrayPtr vArray;
      CString sName;
      vArray = piScriptEventPtr->GetEventSpecificProperties(FALSE);
      //vArray = pLog->GetFirstLogEvent()->GetEventSpecificProperties(FALSE);
      for (int i = 1; i <= vArray->Count; i++)
      {
      _variant_t vData;
      BSTR bsName = 0; // Remember to free
      int iVal;
      vData = vArray->GetNamedValue(i,&bsName,&iVal);

      sName = (BSTR) bsName;
      if (sName == SZ_TMS_PROPERTY_NAME_SCRIPT_NAME)
      {
      sScriptName = (LPCSTR)(bstr_t)vData;
      break;
      }
      ::SysFreeString(bsName);
      }
      }
      catch (...) {}
      */
      int nestedCallScript = 0;
      CXMLElementNode *pKeywordStepResultsNode = NULL;
      // Now go through all events till Script End
      piScriptEventPtr = piScriptEventPtr->GetNextLogEvent();
      eventType = (TMS_LOG_EVENT_TYPE) piScriptEventPtr->GetEventType();
      CXMLCDataNode *pDataNode = NULL;
      while (piScriptEventPtr != NULL && (nestedCallScript > 0 || eventType != TMS_LOG_EVENT_TYPE_SCRIPT_END)) {
      TMS_LOG_EVENT_RESULT result = (TMS_LOG_EVENT_RESULT) piScriptEventPtr->GetResult();

      if ((eventType == TMS_LOG_EVENT_TYPE_MANUALSTEP) &&
      (result == TMS_LOG_EVENT_RESULT_COMPLETED)) {
      result = TMS_LOG_EVENT_RESULT_PASS;
      }

      CXMLElementNode *pStepResultNode = new CXMLElementNode();
      pStepResultNode->setNodeName("er:stepResult");

      CString description;
      CString stepType = EXECUTION_ELEMENT_TYPE;
      switch(eventType) {
      case TMS_LOG_EVENT_TYPE_MANUALSTEP:
      case TMS_LOG_EVENT_TYPE_VERIFICATION_POINT:
      if (eventType == TMS_LOG_EVENT_TYPE_VERIFICATION_POINT) {
      description = GetEventPropertyValue(piScriptEventPtr, SZ_TMS_PROPERTY_NAME_VERIFICATION_POINT_NAME);
      stepType = REPORTING_ELEMENT_TYPE;
      } else {
      description = GetEventPropertyValue(piScriptEventPtr, SZ_TMS_PROPERTY_NAME_MANUALSTEP_NAME);
      }
      break;
      case TMS_LOG_EVENT_TYPE_LOGMESSAGE:
      description = "Log Message(";
      description += GetEventPropertyValue(piScriptEventPtr, SZ_TMS_PROPERTY_NAME_ADDITIONAL_INFO) + ")";
      break;
      case TMS_LOG_EVENT_TYPE_APPLICATION_START:
      description = GetEventPropertyValue(piScriptEventPtr, SZ_TMS_PROPERTY_NAME_ADDITIONAL_INFO);
      break;
      case TMS_LOG_EVENT_TYPE_CALL_SCRIPT:
      description = "Call Script (";
      description += GetEventPropertyValue(piScriptEventPtr, SZ_TMS_PROPERTY_NAME_ADDITIONAL_INFO) + ")";
      if (nestedCallScript == 0) {
      pKeywordStepResultsNode = new CXMLElementNode();
      pKeywordStepResultsNode->setNodeName("er:stepResult");
      pStepResultNode->addChild(pKeywordStepResultsNode);
      }
      break;
      case TMS_LOG_EVENT_TYPE_SCRIPT_START:
      // This is a nested call Script's start
      description = "Script Start:";
      description += GetEventPropertyValue(piScriptEventPtr, SZ_TMS_PROPERTY_NAME_SCRIPT_NAME);
      nestedCallScript++;
      break;
      case TMS_LOG_EVENT_TYPE_SCRIPT_END:
      description = "Script End:";
      description += GetEventPropertyValue(piScriptEventPtr, SZ_TMS_PROPERTY_NAME_SCRIPT_NAME);
      nestedCallScript--;
      break;
      default:
      {
      piScriptEventPtr = piScriptEventPtr->GetNextLogEvent();
      eventType = (TMS_LOG_EVENT_TYPE) piScriptEventPtr->GetEventType();
      continue;
      }
      };

      CString rqmResult = MapLogEventToRQMResultId(result);
      // Description
      if (!description.IsEmpty()) {
      CXMLElementNode *pDescriptionNode = new CXMLElementNode();
      pDescriptionNode->setNodeName("er:description");
      description.Replace("&", "&");
      description.Replace("<"<");
      description.Replace(">", ">");

      pDataNode = new CXMLCDataNode(description);
      pDataNode->setNodeType(CXMLNode::TEXT_NODE);
      pDescriptionNode->addChild(pDataNode);
      pStepResultNode->addChild(pDescriptionNode);

      }

      // Result
      CXMLElementNode *pResultNode = new CXMLElementNode();
      pResultNode->setNodeName("er:result");
      pDataNode = new CXMLCDataNode(rqmResult);
      pDataNode->setNodeType(CXMLNode::TEXT_NODE);
      pResultNode->addChild(pDataNode);
      pStepResultNode->addChild(pResultNode);

      // StepType
      CXMLElementNode *pStepTypeNode = new CXMLElementNode();
      pStepTypeNode->setNodeName("er:stepType");

      if (eventType == TMS_LOG_EVENT_TYPE_VERIFICATION_POINT) {
      pDataNode = new CXMLCDataNode(REPORTING_ELEMENT_TYPE);
      } else {
      pDataNode = new CXMLCDataNode(EXECUTION_ELEMENT_TYPE);
      }
      pDataNode->setNodeType(CXMLNode::TEXT_NODE);
      pStepTypeNode->addChild(pDataNode);
      pStepResultNode->addChild(pStepTypeNode);

      CXMLElementNode *pStarttimeNode = new CXMLElementNode();
      pStarttimeNode->setNodeName("er:starttime");
      pDataNode = new CXMLCDataNode(DateToString(piScriptEventPtr->GetEndDateTime()));
      pDataNode->setNodeType(CXMLNode::TEXT_NODE);
      pStarttimeNode->addChild(pDataNode);
      pStepResultNode->addChild(pStarttimeNode);

      CXMLElementNode *pEndtimeNode = new CXMLElementNode();
      pEndtimeNode->setNodeName("er:endtime");
      pDataNode = new CXMLCDataNode(DateToString(piScriptEventPtr->GetEndDateTime()));
      pDataNode->setNodeType(CXMLNode::TEXT_NODE);
      pEndtimeNode->addChild(pDataNode);
      pStepResultNode->addChild(pEndtimeNode);

      // Expected Result
      CString expectedResult = GetEventPropertyValue(piScriptEventPtr, SZ_TMS_PROPERTY_NAME_EXPECTED_RESULT);
      expectedResult.TrimLeft();
      if (!expectedResult.IsEmpty()) {
      CXMLElementNode *pExpectedResultNode = new CXMLElementNode();
      pExpectedResultNode->setNodeName("er:expectedResult");
      expectedResult.Replace("&", "&");
      expectedResult.Replace("<"<");
      expectedResult.Replace(">", ">");
      pDataNode = new CXMLCDataNode(expectedResult);
      pDataNode->setNodeType(CXMLNode::TEXT_NODE);
      pExpectedResultNode->addChild(pDataNode);
      pStepResultNode->addChild(pExpectedResultNode);
      }

      // Actual Result
      CString actualResult = GetEventPropertyValue(piScriptEventPtr, SZ_TMS_PROPERTY_NAME_RESULT_DETAILS);
      actualResult.TrimLeft();
      if (!actualResult.IsEmpty()) {
      CXMLElementNode *pActualResultNode = new CXMLElementNode();
      pActualResultNode->setNodeName("er:actualResult");
      actualResult.Replace("&", "&");
      actualResult.Replace("<"<");
      actualResult.Replace(">", ">");
      pDataNode = new CXMLCDataNode(actualResult);
      pDataNode->setNodeType(CXMLNode::TEXT_NODE);
      pActualResultNode->addChild(pDataNode);
      pStepResultNode->addChild(pActualResultNode);

      }
      // Migrating actual and expected result files will be a costly operation and will flood server with files.
      /*CString expectedResultFile = GetEventPropertyValue(piScriptEventPtr, SZ_TMS_PROPERTY_NAME_EXPECTED_RESULT_FILE);
      if (!expectedResultFile.IsEmpty()) {
      }*/
      /*CString actualResultFile = GetEventPropertyValue(piScriptEventPtr, SZ_TMS_PROPERTY_NAME_RESULT_DETAILS_FILE);
      if (!actualResultFile.IsEmpty()) {
      }*/
      if (eventType != TMS_LOG_EVENT_TYPE_CALL_SCRIPT && pKeywordStepResultsNode != NULL) {
      pKeywordStepResultsNode->addChild(pStepResultNode);
      } else if (eventType == TMS_LOG_EVENT_TYPE_SCRIPT_END && pKeywordStepResultsNode != NULL) {
      pKeywordStepResultsNode->addChild(pStepResultNode);
      pKeywordStepResultsNode = NULL;

      } else {
      pStepResultsNode->addChild(pStepResultNode);
      }
      piScriptEventPtr = piScriptEventPtr->GetNextLogEvent();
      eventType = (TMS_LOG_EVENT_TYPE) piScriptEventPtr->GetEventType();
      }
      }
      }
      }

      pRootElement->addChild(pStepResultsNode);
      return true;
      }
      This is how you can parse each log event
      • SystemAdmin
        SystemAdmin
        1545 Posts
        ACCEPTED ANSWER

        Re: TM API: How to get Test Result.

        ‏2010-12-14T15:49:52Z  in response to SystemAdmin
        Pramod,

        Thanks you so much for sharing this code with me!

        One more question, do you know how to get the test case/script execution date/time info?

        Andrew
        • SystemAdmin
          SystemAdmin
          1545 Posts
          ACCEPTED ANSWER

          Re: TM API: How to get Test Result.

          ‏2010-12-15T06:01:33Z  in response to SystemAdmin
          DATE startDate = piLogEventPtr->GetStartDateTime();

          DATE endDate = piLogEventPtr->GetEndDateTime();
    • SystemAdmin
      SystemAdmin
      1545 Posts
      ACCEPTED ANSWER

      Re: TM API: How to get Test Result.

      ‏2010-12-14T14:41:09Z  in response to SystemAdmin
      To get verdict of the Testcase result

      interpretedResult = (TMS_LOG_EVENT_RESULT) pTestCaseResult->GetInterpretedResult();