HP Service Test 11.1 - Using Variables on REST Service input (2345 Views)
Reply
Regular Advisor
swami_1
Posts: 99
Registered: ‎07-10-2008
Message 1 of 16 (2,345 Views)

HP Service Test 11.1 - Using Variables on REST Service input

So far have been using SOAP UI to verify the REST Services. There we had an url like this:

 <server link>/location/memberid

 

memberid, is a variable in the URL and in soap ui I make this as a variable and pass the parameter and execute the service. In Service Test how do I implement the above?

 

I have such 20-25 REST services, is there any way to automate these with a click on Run button like what could be done in QTP.

 

Thanks, appreciate any help on this.

Trusted Contributor
Yaron_Naveh
Posts: 113
Registered: ‎05-28-2010
Message 2 of 16 (2,343 Views)

Re: HP Service Test 11.1 - Using Variables on REST Service input

hi swami_1

 

you have two ways to call rest services:

 

1. if you drag an http activity to the canvas you can set any of its properties. when you see the url property you can click the linking (chain) icon near it and formulate its structure anyway you want such that part of it is fixed and part is dynamically taken from a previous call / data / etc.

 

2. if you want to reuse this http call a few times you can model rest services under the "rest" node in the toolbox. Each leaf is an abstraction over what you did in suggestion #1. so you define the input and output arguments (e.g. bookId) and then you do as in #1 by linking the url to the newly created input argument. When you drag the activity to the flow you can set the values of the abstracted in/out params w/o the need to dig in the url structure again.

 

The documentation contains more info

 

Yaron

Web services testing blog

 

thanks,

yaron

Regular Advisor
swami_1
Posts: 99
Registered: ‎07-10-2008
Message 3 of 16 (2,341 Views)

Re: HP Service Test 11.1 - Using Variables on REST Service input

Thanks for a quick reply Yaron.

 

Since the documentation for Service Testing suggested to use REST Services for testing 'REST Service' on the top left and I created one and I could get the expected result when the URL is : <http:/xxxx.com/location/123456789.

 

I tried your method of using the chain on the URL part, where in the whole parameter is taken from the datafile. How do I make a part of the URL dynamic? Can you please elaborate on this.

 

In case if these REST services are to be used only once every regression test, should I create a http or a RESTService type?

 

Thanks.

 

Trusted Contributor
Yaron_Naveh
Posts: 113
Registered: ‎05-28-2010
Message 4 of 16 (2,338 Views)

Re: HP Service Test 11.1 - Using Variables on REST Service input

I would say it is best practice if you get used to modeling rest like in method #2. It does not realy matter if you use it once.

 

In the linking dialog you hav a button "more". Then in the text box that opens write the static url and click the "add" button when you are ready to add the dynamic part.

Regular Advisor
swami_1
Posts: 99
Registered: ‎07-10-2008
Message 5 of 16 (2,335 Views)

Re: HP Service Test 11.1 - Using Variables on REST Service input

Thank you Yaron, this helps a lot.

 

One more question on this,I have few rest services with initial URL kinda same and I would like to break them into different RESORUCE and Method (like in Soap UI) with only the end url being different. This is how it's been implemented in Soap UI

 

In this case, where does the intial part of the URL(which is kinda static), go in HP Service test? I mean in the Service or Resource or Method? In which parameter should I add?

 

thanks.

Trusted Contributor
Yaron_Naveh
Posts: 113
Registered: ‎05-28-2010
Message 6 of 16 (2,330 Views)

Re: HP Service Test 11.1 - Using Variables on REST Service input

I'm not sure if it is possible. Maybe you can create an environment variable with the resource prefix and then make all url's for this resource linked to it, but not sure. You should raise it as an enhancement request.

Regular Advisor
swami_1
Posts: 99
Registered: ‎07-10-2008
Message 7 of 16 (2,326 Views)

Re: HP Service Test 11.1 - Using Variables on REST Service input

Thanks Yaron. I think there is work around for what I was asking. The URL need to be parameterized as I might have to validate in different environments if not it can be directly shared in the data.

 

I have like 20 REST services at least, and I'm trying to build them like a flowchart (the intention is to execute all these services at once), one after the other, a normal flow without any conditions. Is there any way that I could make them to pick first row in Data source for the first block in the canvas and next row for the next block?

 

Also another question, what is the difference between having the HTTP (REST service) within the 'Test Service' block (The one between start and stop) and having it outside just before the stop block.

Trusted Contributor
Yaron_Naveh
Posts: 113
Registered: ‎05-28-2010
Message 8 of 16 (2,324 Views)

Re: HP Service Test 11.1 - Using Variables on REST Service input

What you put before or after the "test flow" is executed once. What you put inside is executed once per data row in your data sources. You can also configure the test flow to run X times per your own logic.

 

as for the other question do all rest calls require the same parameters? If no then its not a matter of rows, you need a separate data source for each one anyway, or you can build someutility that flattens your many excels into one big where each rest call will use different columns.

 

If yes then have only one rest call on the canvas and in each iteration of the loop give it the different url / data / etc from the excel.

 

 

Regular Advisor
swami_1
Posts: 99
Registered: ‎07-10-2008
Message 9 of 16 (2,320 Views)

Re: HP Service Test 11.1 - Using Variables on REST Service input

Thanks Yaron, I have made it to loop by using For-Each condition.

 

I'm stuck at one other thing. So I decided to created one http block into canvas and make my URL fully dynamic and then execute that for all rows in the data file. URL property is like this: 

 {DataSource.Event_Data!Sheet1.Envt}{DataSource.Event_Data!Sheet1.Start_Url}

 

Eg:

https:sample.link.com/xxxxx/location/memberid, here in this the link part is stored in one column in excel and the remaining I have put in another column.

 

The second part of the above is dynamic by itself it will have details like "/xxxxxx/location/{DataSource.Event_Data!Sheet1.Member_Id}. I wrote this datasource part in the excel column so that  while executing it picks it from there and the URL becomes generic at a high level.

 

The output is always a failure for such REST services (I tried for 3 of them) and the output shows that it's an Invalid format.

 

Can you throw some light on this? Is there any other way to implement this?

Trusted Contributor
Yaron_Naveh
Posts: 113
Registered: ‎05-28-2010
Message 10 of 16 (2,318 Views)

Re: HP Service Test 11.1 - Using Variables on REST Service input

you cannot have data link inside another data link text.

 

try your template to be http://{something}/...

 

and then use the string replace activity to replace {something} with a value from the data source

 

Regular Advisor
swami_1
Posts: 99
Registered: ‎07-10-2008
Message 11 of 16 (2,315 Views)

Re: HP Service Test 11.1 - Using Variables on REST Service input

Thanks Yaron, I was using a different method (though is not a good practice) but the string replace is better even though it consumes more time and writes tedious logs.

 

Is there any way to add different values in checkpoints or just limited to 4-5 that's there?

Trusted Contributor
Yaron_Naveh
Posts: 113
Registered: ‎05-28-2010
Message 12 of 16 (2,313 Views)

Re: HP Service Test 11.1 - Using Variables on REST Service input

what do you mean by values? the operators (><=)?

you have an event "on code checkpoint" where you can add c# code that arbitrarly validates what you want.

Regular Advisor
swami_1
Posts: 99
Registered: ‎07-10-2008
Message 13 of 16 (2,311 Views)

Re: HP Service Test 11.1 - Using Variables on REST Service input

Oops I must not have mentioned as values, but the properties. I see that there are options to check input properties like HTTP version, Status code & description...etc.

 

I would like to verify the few more like part of the values in (XML output) ResponseBody, Message...etc.

 

You mean I could use the "Custom Code" from Misc?

 

Where do the normal verifications lie in the file so that I can modify the code and customize it. I could see that are lot of files in the ServiceTest folder, not sure where to change.

Trusted Contributor
Yaron_Naveh
Posts: 113
Registered: ‎05-28-2010
Message 14 of 16 (2,308 Views)

Re: HP Service Test 11.1 - Using Variables on REST Service input

the http activity (rest) property sheet has a few tabs (the little icons on the property sheet in the right part of the screen). when you click on the input/output tab you have a chance to load the expected xml document so you can verify it or parts of it. as for the code I mean one of the tabs I mentioned is called events.
Regular Advisor
swami_1
Posts: 99
Registered: ‎07-10-2008
Message 15 of 16 (2,307 Views)

Re: HP Service Test 11.1 - Using Variables on REST Service input

Ah, found the checkpoints.cs file and I'm making changes to it. Will see if it works or not.
Trusted Contributor
Yaron_Naveh
Posts: 113
Registered: ‎05-28-2010
Message 16 of 16 (2,306 Views)

Re: HP Service Test 11.1 - Using Variables on REST Service input

I beleive this file is regenerated every time you save the test.

do not change it. Instead, follow the procedure I explained before. there is a lightning icon on the property sheet above where you put the url / input / etc. click it and then implement the code checkpoint event.

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.