get Data From Traffic Viewer Object

Wanted to retrieve Header Info, Request Body & Response from Traffic Viewer Object from each test. I want to perform this task by writing code since I have 250+ scenarios in my suite and it is not possible to add Header DataBank for each test. My Suite is in REST.

Comments

  • benken_parasoftbenken_parasoft Posts: 522 ✭✭✭

    It is true that the "Traffic Object" holds both the request and response. The traffic object can be consumed by the Traffic Viewer for displaying the traffic. However, you can also use an Extension Tool. The traffic object is passed to the Extension Tool as a java.util.Map object. This Map has keys for getting various values. For example, look at this Groovy script:

    import com.parasoft.api.*
    import soaptest.api.*
    import java.util.*
    
    void getTraffic(Map input, ScriptingContext context) {
        Date requestTime = input.get(SOAPUtil.REQUEST_TIME)
        String requestHeader = input.get(SOAPUtil.HTTP_HEADERS_REQUEST)
        String requestBody = input.get(SOAPUtil.XML_REQUEST)
        Date responseTime = input.get(SOAPUtil.RESPONSE_TIME)
        String responseHeader = input.get(SOAPUtil.HTTP_HEADERS_RESPONSE)
        String responseBody = input.get(SOAPUtil.XML_RESPONSE)
        Application.showMessage("requestTime: " + requestTime)
        Application.showMessage("requestHeader: " + requestHeader)
        Application.showMessage("requestBody: " + requestBody)
        Application.showMessage("responseTime: " + responseTime)
        Application.showMessage("responseHeader: " + responseHeader)
        Application.showMessage("responseBody: " + responseBody)
    }
    
  • jakubiakjakubiak Posts: 360 admin

    FYI you can add a single tool (like an Extension Tool with the script that benken described) to multiple tests at once, by selecting a test suite that contains multiple tests, or by selecting multiple individual tests, and then right-clicking and choosing "Add Multiple Outputs".

  • thank you benken & jakubiak. I have the following code to get the test suite and all the tests. Can you please tell me how to get traffic input from each test.

    Context myTestSuite=ctx.getParentContext().getParentContext();
    Now myTestSuite has all my tests and myTestSuite.getTest(Index) will get single test. Now I want to know how to get traffic from each test from this code :smile:
    myTestSuite.getTest(Index).

  • benken_parasoftbenken_parasoft Posts: 522 ✭✭✭

    If you are trying to get traffic from all tests from a script this is not the right away of going about it.

    What I originally described to you was how to extract the traffic messages from an Extension Tool chained to a Traffic Object output. The Traffic Object is passed from the parent test to the chained Extension Tool at runtime. In contrast, it sounds like you are asking how to somehow retrieve traffic from the test suite and tests themselves. What you are describing will never work. Those things don't log traffic in themselves. Traffic is only passed along to output tools in the Traffic object or logged in the SOAtest XML/HTML reports.

    What you should be doing is saving traffic in the SOAtest XML/HTML reports. To enable this, open the Parasoft preferences, click Reports, enable "Overview of checked files and executed tests" and disable "Only top-level test suites". Additionally, enable the "Report traffic for all tests" option in the Test Configuration you are running.

    I don't understand your requirements. If having the traffic in the SOAtest XML/HTML reports isn't entirely sufficient, and you still need to do something special with the traffic messages after the fact, then you should write a script to extract the traffic from the XML report. The SOAtest XML report is intended for any custom reporting needs, where raw test result and traffic information needs to be extract and used in some special way.

  • benken_parasoftbenken_parasoft Posts: 522 ✭✭✭
    edited October 2017

    Now myTestSuite has all my tests and myTestSuite.getTest(Index) will get single test. Now I want to know how to get traffic from each test from this code :smile: myTestSuite.getTest(Index).

    I should also mentoin that the "getTest" method you mention here is undocumented, internal API. There are no interfaces in our public Java API for working with test and test suite objects. Even if there was, this would be for retrieving test configuration information, similar to REST APIs we do expose for working with test and test suite configuration.

    All test result information, including any traffic messages generated by tests for a particular test run, are logged in the SOAtest reports. You must parse the SOAtest XML report if you need to extract the traffic messages if you really need do something special or custom with the traffic after you tests are done running.

Sign In or Register to comment.