cancel
Showing results for 
Search instead for 
Did you mean: 

validating REST response against JDBC response

SOLVED
Highlighted
Contributor

validating REST response against JDBC response

Hi,

 

I have to compare the Rest response with JDBC result set.

I am following the below steps.

 

1. Datasource - JDBC - Run the query and get the values

2. Rest Step - Execute and get the response; Added assertion to get the first (datasource row number) row values and validate it with the datasource values

3. Data loop

 

My Datasource has 30 records and the Rest step is getting executed 30 times to validate the results one by one.

 

Is there any way I can get the complete datasource results as list and compare it with the Rest response?

Can you please help me the groovy script? (I am newbie)

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: validating REST response against JDBC response

9 REPLIES 9
Highlighted
Community Hero

Re: validating REST response against JDBC response

Highlighted
Contributor

Re: validating REST response against JDBC response

Hi Rao,

 

I am able to compare my rest response with the JDBC results referencing the link you provided. 

 

Now, I have the JDBC test step in a different test case. How can i get the JDBC response from that test case? Currently I am using,

 

def jdbcResponse = context.expand('${JdbcStepName#ResponseAsXml}

 

Since, I have this script added to my script assertion, I am not able to use testRunner.

Highlighted
Community Hero

Re: validating REST response against JDBC response

Sorry, it is not really clear. Would you like to describe the structure of the test case with details? or the script that you have problem?


Regards,
Rao.
Highlighted
Contributor

Re: validating REST response against JDBC response

Test case 1 has JDBC test Step which runs select query and gets the response

 

Test case 2 has Rest test step.

 

I have added a script assertion in the Rest test step to compare the response with the Testcase 1-JDBC test step response.

I have referred your groovy script http://stackoverflow.com/questions/31472381/dynamically-compare-rest-xml-json-response-and-jdbc-usin... and implemented here.

 

When I have the JDBC and REST test steps in the same testcase, I am able to successfully compare the responses. 

But when they are in different test case, what should i add instead of def jdbcResponse = context.expand('${JdbcStepName#Response}'

 

 

Highlighted
Community Hero

Re: validating REST response against JDBC response

I see you had another question to find the step type in a different thread.
Did that help you to proceed further in this regard? Do you still need any help? Please update this thread.


Regards,
Rao.
Highlighted
Contributor

Re: validating REST response against JDBC response

I have not solved this issue yet.. 

Highlighted
Community Hero

Re: validating REST response against JDBC response

Not sure use case or exactly the reason behind doing it in two test cases. If I were to do it, I would put into one test case.

 

Because:

It is General Practise that each test case is independent.

 

1. If rest case has problem TC #2 can be failed. If you come to know Jdbc response is the problem in Test Case 2, you can't fail Test Case #1 fail. According to the test execution TC #1 is already passed.

 

2. If Test Case #1 is failed, then there is no point in running Test Case #2. But you can't control it.

 

 

If you still want a do it the way you are doing it:

Not sure what is the error in script assertion of TC #2.

You can use groovy script instead.



Regards,
Rao.
Highlighted
Contributor

Re: validating REST response against JDBC response

Thanks, I got what you are saying.

 

But just want to know, how i can access the response from a different test case in my script assertion?

 

The below is valid in a groovy script test step. but not in assertion.

 

def tc = testRunner.testCase.testSuite.project.testSuites.testCases["external TestCase"]
def ts = tc.testSteps["test step"]

 

Highlighted
Community Hero

Re: validating REST response against JDBC response

Try to use context instead of testRunner object.


Regards,
Rao.
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors