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.

Is there a way to write in writable datasource using script

pooja
pooja Posts: 18

Like we can fetch the values using getValues method , can we set the values in writable datasource . Let me know the feasible option to write in datasource by script.
Since I need to manipulate the list of values and later store it , I have to write script for it.

Tagged:

Comments

  • Ireneusz Szmigiel
    Ireneusz Szmigiel Posts: 227 ✭✭✭

    Hi pooja

    I think that the simplest way to achieve such scenario, is to use of additional tools in SOAtest: XML Databank, Writable Data Source and Extension Tool to create simple data source based on CSV.
    Here is a script which I have used in Extension Tool:

            from com.parasoft.api import *
            from sys import *
            from java.util import *
            from java.text import *
    
            def appendToFile(input, context):
                #Create a timesatmp on the CSV filename 
                today = Date()
                cal = GregorianCalendar()
                todayPlus3 = cal.getTime()
                parser = SimpleDateFormat("HH_mm")
                dateField = parser.format(todayPlus3)
    
                #retrieve values from the datasource
                input_one = context.getValue("Writable","id")
                input_two = context.getValue("Writable","total")
                input_three = context.getValue("Writable","user")
    
                #opens files, creates one if it doesn't exists
                f = open('C:\DEV\DataSource\Parabank_'+str(dateField)+'.csv', 'a')
                f.write(str(input_one) + ',' + str(input_two) + ',' + str(input_three))
                f.write('\n')
                f.close()
                return
    
             def addDataSources(context):
                    return "Writable"
    

    I have used Jython to read data from Writable Data Source ( named "Writable" with 3 columns: id,total,user)
    Then I just write such data into external CVS with slight modification of column total.

    I have also attached simple SOAtest v9.10 project with example how to use such script.
    It's using external endpoint parabank.parasoft.com so you should be connected with the Internet to run it.

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    If you can represent your row and column data as XML, simply feed it to an XML Data Bank. In the XML Data Bank, create an extraction for each column in your Writable Data Source.

  • pooja
    pooja Posts: 18

    thanks , able to achieve with write file

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited February 2017

    Another option I wanted to mention, for anyone in the future looking for a similar solution. If scripting with JavaScript, I'd recommending returning the row and column data as a JSON array then return that array as input to a JSON Data Bank. In the JSON Data Bank, create an extraction for each column in your Writable Data Source. Each extraction should be configured to select all of the values for a column. By selecting multiple values in a single extraction, the Data Bank will write that list of values down the rows of a column of the Writable Data Source. This approach could potentially require a lot less scripting and be more natural for anyone scripting in JavaScript.

    I recommending trying to leverage built-in tooling as much as possible as opposed to scripting something. If you were to write a custom script to write out a CSV file then the CSV file would also have to be used by a different tst, not the same tst. This is because CSV and other non-writable data sources are loaded prior to execution of the tst. You would need one tst as a setup, to write out the CSV file, then a second tst that has a CSV data source. If instead you use the Writable Data Source, you could have one suite in the tst that populates the Writable Data Source and then a second suite in the tst that iterates over that Writable Data Source.

  • chinnappa_raju
    chinnappa_raju Posts: 4

    Benken, how do i extract the value from datasource in a Javascript. Referencing the datasource columns in Javascript didn't work. I need to be able to combine datasource value with other values to form an input string

Tagged