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.

How to write DB Response to Internal Spread sheet table ?

bharatbarz
bharatbarz Posts: 44

My Requirement is to Query table 1 which may return N rows. For Each of the row, I have to query 3 other tables and do some assertions. I wrote the Table 1 response to a CSV file and created a data source out of that and used that as an input to my other 3 tables. But I have been asked now instead of writing to a CSV file, write into an internal table and use that to drive the other 3 table queries. Please guide me if this can be done?

Tagged:

Best Answers

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited November 2022 Answer ✓

    How to access the table fields inside Extension Tool?

    By "table" I assume you are referring to a SQL result set which the DB tool returns as XML. You have various options, depending on where you want your Extension Tool positioned in your suite:

    • You could chain your Extension tool directly to the output of your DB tool. The first argument to the script is the tool's "input" which would be the result set XML.
    • If you need your Extension tool to read values from data source columns, like columns from the Writable data source, then you can use com.parasoft.api.ScriptingContext.getValue(String dataSourceName, String columnName).
    • You could chain an XML Data Bank to the output of the DB to save the result or whatever values are of interest to your Extension tool. A script can read custom data bank columns using the same "getValue" method using "Generated Data Source" for the "dataSourceName" argument. If your Data Bank is writing to a Writable data source then you would use the actual name of the Writable data source for "dataSourceName".
    • ScriptingContext also has a "getValues" (plural) method. It works the same as "getValue" but returns a List of all values in a data source column. This can be useful in case you need your script to read all values in a data source as opposed to the values for the current row.

    String Operations Using Extracted Values shows how to use "getValue".

  • bharatbarz
    bharatbarz Posts: 44
    Answer ✓

    Hi Benken, Thanks for detailed explanation. I am using context.getValue (,). I am able to access the fields, but i am getting 'Content is not allowed in Prolog'. Not sure, what is the mistake. I have created a separate post for this query. Thanks again for helping me.

Answers

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    My Requirement is to Query table 1 which may return N rows

    Put a Writable data source at the top of your tst. Add a DB Tool to perform your query. Chain an XML Data Bank to the DB Tool. Configure the XML Data Bank with extractions to write to one or more columns of the Writable data source.

    For Each of the row, I have to query 3 other tables and do some assertions.

    Create a new test suite after your DB Tool. Add whatever tests you need in there, parameterized against the values from the Writable data source.

  • bharatbarz
    bharatbarz Posts: 44

    Hi Benken, Thanks. I did the same. Now after 3 Tables are queried. I am trying to do an Asserter using Extension Tool and I need to give the Writable Data source as Data Source. How to access the table fields inside Extension Tool?

Tagged