Extract Text from Response Body in Coded Webtest u

2019-09-21 05:23发布

I have a Web performance Script in Visual Studio. I have turned this into Coded Webtest in VB by clicking on the Generate Code button.

In my web test there are a 5 functions. Apart from the 1st the others are for SQL Procedures.

Among a few things, I need a web request that does a certain action. Based on that action, In the response body - it generates a Unique Id.

I need this Id to make it accessible across all the functions.

The Response body is something like this :

0x00000000  7B  22  69  64  22  3A  36  35  33  30  36  36  33  7D            {"id":2133221}  

Now I wanted to know, how do I do it. I just need 2133221.

I tried using the Context Parameter name and appending it to a .to string...it did not work. I tried doing by looking over the net and trying out a few options. I'm lost now. Can anyone help.

2条回答
我只想做你的唯一
2楼-- · 2019-09-21 05:51

See access the response from a web coded performance test for how to access the response ina coded test. While it is in C# the VB style is similar.

For your case the displayed string shows a hex dump of the actual body. Th ebody does not include the 0x00000000 7B 22 69 64 22 3A 36 35 33 30 36 36 33 7D part.

A simple approach to getting the wanted Id string is to use a Extract text extraction rule with a Start with of "id": and an Ends with of ". This will need to be done on the ".webtest" file.

I strongly recommend against converting web tests to coded tests. It loses all the high level structure of the ".webtest" format. The Web Test Editor has many facilities for easily enhancing and changing tests, all of them are lost when changing to a coded test. A little learning about extraction and validation rules gives you many facilities. If you are happy working with the VB of a coded test then you should also be happy to write plugins so look at web test request plugins and web test plugins.

查看更多
成全新的幸福
3楼-- · 2019-09-21 06:01

The simplest solution is the below one.

str = "0x00000000 7B 22 69 64 22 3A 36 35 33 30 36 36 33 7D {""id"":2133221}"

arr = Split(str, ":")
strID = Left(arr(1), len(arr(1)) - 1)

msgbox strId

However, If you still need a more robust one, try regex

查看更多
登录 后发表回答