How can you use a specific row from a writable datasource in a subsequent test?

BrianQuantumBrianQuantum Posts: 20

I created a writable datasource that is populated with anywhere from 5 to 20 rows of data in a REST GET command. In the next test, I would like to always use row number 5 of the datasource as a parameterized value in a POST command. Is there a way to do this. I have searched the help and have not been successful in finding a way to do this. Thanks

Comments

  • Thomas MooreThomas Moore Posts: 56 admin
    edited August 2017

    Hi Brian,

    If you want to use a specific row from the datasource, the best way to do this that I can think of is to use a scripted value instead of parameterized.

    When you click the Edit script button when script is selected, paste this in with Groovy as the selected language:

    import com.parasoft.api.*;
    
    public String getFifth(ScriptingContext context)
    {
        return context.getValues("New Datasource", "test").get(4);
    }
    

    In your case, "New Datasource" should be the name of your writable and "test" should be the column name.

    Hope this helps!

  • BrianQuantumBrianQuantum Posts: 20

    Yes, this helps immensely, thank you

  • kamit2733kamit2733 Posts: 16

    Hi

    context.getValues("New Datasource", "test").get(4);

    in "New Datasource" we have to provide the absolute path of the excel workbook

    Please correct me if i am wrong.

  • Thomas MooreThomas Moore Posts: 56 admin

    Hi Kamit,

    For "New Datasource," you do not have to provide the absolute path. Instead, provide the name of the Excel Datasource that you are using for that specific test. In a similar script for the example screenshot below, the line would be

    context.getValues("Books", "title").get(4);

    Hope this helps!

  • benken_parasoftbenken_parasoft Posts: 397 ✭✭✭
    edited October 2017

    in "New Datasource" we have to provide the absolute path of the excel workbook

    In data sources, you do not have to provide an absolute file path to an Excel/CSV file. You can use variables. Here are the examples I found in the SOAtest User's Guide:

    ${project_loc:MyProject}/DataSource/${soa_env:CVS_DIR}/my_csv_file.csv
    ${test_suite_loc}/../${soa_env:XLS_DIR}/my_excel_file.xls
    

    However, this is something you configure in the data source itself. As Thomas mentioned, in your script you only refer to the data source by name.

Sign In or Register to comment.