Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

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_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    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)
    }
    
  • jakubiak
    jakubiak Posts: 795 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_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    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_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    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.

  • tsworld
    tsworld Posts: 14

    @benken_parasoft

    String requestHeader = input.get(SOAPUtil.HTTP_HEADERS_REQUEST)

    how can we get a single header string from the one you wrote above?

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    how can we get a single header string from the one you wrote above?

    I'd recommend using a Header Data Bank to extract header values as opposed to trying to parse the HTTP header yourself from a script. Perhaps you can extract the header you desire with a Header Data Bank tool then simply read the Header Data Bank column from your script?

  • ashwini
    ashwini Posts: 11

    How to read data from Header Data Bank in a Diff. Datasource ?

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    I explain in this other thread. Let's keep discussion there:
    Pattern check in request header field

  • Aloknanda
    Aloknanda Posts: 8

    In order to create a custom report , I am looking for code which will capture the server response time, test case status post execution , request & response xml and any error which test case has thrown. My application is a REST based API. Can anyone help with sample code here.

  • jakubiak
    jakubiak Posts: 795 admin

    SOAtest produces XML reports that contain that information. You can write a XSL transformation or your own code to create a custom report based on information in the XML report.

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    I am looking for code which will capture the server response time, test case status post execution , request & response xml and any error which test case has thrown.

    This information is all available in the SOAtest XML report. The SOAtest HTML report already represents the information from the SOAtest XML report in a nice way. If you need to generate your own custom report then you will need to write your own code to translate the information in the SOAtest XML report into whatever custom format or representation you require.

    Can anyone help with sample code here.

    If you are asking about how to parse XML, there are XML parsing libraries available for different programming languages. There are also technologies like XPath and XSLT which can be used to extract and translate XML. So, the code you need to write would be very specific to what technologies you choose as well as your specific requirements around what how the data from the SOAtest XML report needs to be translated into whatever format and structure is required for your particular custom report.

  • Aloknanda
    Aloknanda Posts: 8

    Do you mean for this first step would be post execution right click on the .tst node and get the structured report and based on that create a custom report using any language.

  • Aloknanda
    Aloknanda Posts: 8

    I need to run a test based on the execution flag(which is set as Yes or No) which is parameterized from a datasource(excel). If yes execution to be continued else to be skipped. I could not find it working if configured directly on the tool? Alternatively I tried with an Extension tool with groovy script which I wrote before the Test and I am able to read the value from excel but not sure how to pass that value to my test in order to validate and proceed. Kindly advice

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited April 2021

    Do you mean for this first step would be post execution right click on the .tst node and get the structured report and based on that create a custom report using any language.

    No, the test structure report only contains information about the test structure and configuration settings, not anything about execution results. Please see Generating Reports. It is common to generate reports when running tests as part of automation, like when using soatestcli with the "-report" argument. The XML report is generated along side the HTML report. If generating an HTML report from the workbench UI then I recall the XML report only being available if your license also includes the "Command Line" feature.

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    If yes execution to be continued else to be skipped. I could not find it working if configured directly on the tool?

    In the test suite configuration, you can define a boolean variable on the Variables tab. Next, click the Test Execution > Test Flow Logic tab, click the test, then select your new boolean variable as a Variable Condition. From an Extension Tool, you can set the variable to true or false to make the test execute or be skipped. Your script would call the "setValue(variableName, value)" method on the com.parasoft.api.ScriptingContext object that is passed to your script.

  • Aloknanda
    Aloknanda Posts: 8

    Please advice then from where the input will come from to get the Test status so that it can be used to create custom report

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited April 2021

    Please advice then from where the input will come from to get the Test status so that it can be used to create custom report

    As mentioned, the SOAtest XML report includes this info, all the items you asked about (status, request, response, timing, etc.). This is the report that contains the test results, not the test structure report. See my previous comment for detail which also included a link to the user documentation.

  • Aloknanda
    Aloknanda Posts: 8

    Thanks for your response. I have visited the link for Generating reports but I could not find the xml report which you are mentioning having the details of execution. I could find the HTML report. Could you please share the detailed step to retrieve the XML report so that I can create an XSL out of it.

  • jakubiak
    jakubiak Posts: 795 admin

    The XML report shows up in the same directory as the HTML report - but it requires that your SOAtest license include the Command Line license feature. Otherwise it won't appear.

  • Aloknanda
    Aloknanda Posts: 8

    How to access the variable in order to update in extension tool using groovy script which is declared in variable tab. I tried with context.setvalue(variable,value) as adviced in the chain above but that did not work. Kindly advice.

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    How to access the variable in order to update in extension tool using groovy script which is declared in variable tab

    To get a value you call context.getValue(variableName).
    To set a value you call context.setValue(variableName, value)

    The arguments are strings, both "variableName" and "value".

  • Aloknanda
    Aloknanda Posts: 8

    As adviced in this chain, in order to create a customised report we need to create xsl or parse XML using any language based on the XML report what we get. I have one query around this. If we have used data source(excel) for parameterising then the XML report refers the excel row as test data row 1,2 but it does not hold any data from data source(ex test case name) . Is there any configuration where we can send and atleast one data from excel(atleast the test case name) gets reflected in XML report in order to use in the xsl or custom report.kindly advice

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    By default, the XML/HTML report doesn't include all information. To include more information, you do two things. First, enable the option in the test configuration to "Report traffic for all tests". Second, in the Parasoft preferences under Reports, enable "Overview of checked files and executed tests" and disable "Only top-level test suites". This way, the XML/HTML reports will include individual test case detail with traffic.

  • Aloknanda
    Aloknanda Posts: 8

    Need to know how we get the source for XML report file or the execution context data on the fly in order to pass the data into my custom code (for ex Java custom code) for creating a custom report. Kindly advice.

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    Need to know how we get the source for XML report file

    Automation is supported with soatestcli and the "Command Line" license feature. On the command line to soatestcli, you would pass a "-report" argument to tell SOAtest where to write the XML report. So, you have full control of the file name and can pass that same file name to your custom Java code which would be parsing the XML file.