Forum Discussion

juicejylee's avatar
juicejylee
New Contributor
14 years ago

How can I get values from Data Source in Script Assertion?

Hi,

I have a Data source. I want to using the property name as 'result' in script assertion

I want to compare response status with property in data source.

How can I access the Data Source in script assertion?


Thanks
  • Hi,

    To get the data from the property value in DataSource use the following in the xPath assertion of the teststep which is between the data source test step & data source loop test step.
    ${DataSource#PropertyName}

    Now since u want to match specific field from the response (use xPath to select the same) with the value in data source.
    Put xPath expression which will fetch the data from the response in the xPath expresison field.
    And in the expected result, put the data source property : ${DataSource#PropertyName}

    Example to show the hierarchy of the project, which can be used : add xPath assertion in test step 2
    testsuite
    - testcase
    - - test step1
    - - data source
    - - test step 2
    - - data source loop

    I hope this information would be of some help. Do update us all if it works or if it doesn't :-)

    ~~ Pradeep Bishnoi ~~
  • juicejylee's avatar
    juicejylee
    New Contributor
    Thank you for your answer.

    I want to use property in Scipt Assertion.
    First time I would use Xpath assertion. But I couldn't use it.
    Because I compare response code with property...


    I want to use this way..
    example in Script Assertion>

    if (messageExchange.responseStatusCode = [from DataSource property])
    ....




    Is it possible

    the hierarchy of my projecttestsuite :test step1 script assertion
    - testcase
    - - data source
    - - test step 1
    - - data source loop

    thanks for your time
  • juicejylee's avatar
    juicejylee
    New Contributor
    Oh, I got it!


    Sorry,
    I didn't know about the drop-down edit menu(the right-click popup) in script Editors............ !!!!!!!
    I used the popup-menu that contains a "Get Data".

    auto generated this code : def result = context.expand( '${DataSource#result}' )


    Thaks for comment ...
  • Hi,

    the scenario what you have mentioned would be used to just verify the status code of your response with DataSource values.
    Yes, you can do it.
    Just use the expression
    def tempVar = context.expand( '${#DataSource#PropertyName}' )

    and use tempVar for comparison purpose.
    To put the same, you can right click in the script assertion window (where u write code) and use GetData... from the context menu. It will automatically generate the code for you.

    Hope this will help

    ~~ Pradeep Bishnoi ~~