1

Can anyone tell me how to create an extraction rule that will allow me to pull an ID from an MVC querystring?

Scenario:

User hits site, and clicks "Add new"

Request: www.site.com/item/create
Response: www.site.com/item/view/2143

The site will instantly create a new item and redirect them to the viewitem page. The id i would like to extract lives within the response after item/view/####

Current recorded code for webtest:

var request4 = new WebTestRequest((Context["WebServerAddress"] + "/Item/Create"));
request4.Method = "POST";
var request4Body = new FormPostHttpBody();
request4.Body = request4Body;
yield return request4;
request4 = null;

//server redirect response happens now

var request5 = 
  new WebTestRequest((Context["WebServerAddress"] + "/Item/Edit/?needIdForHere"));
yield return request5;
request5 = null;

Any ideas?

Many thanks,
Kohan

4imble
  • 13,979
  • 15
  • 70
  • 125

1 Answers1

1

you may get more mileage setting the value from the WebTestContext.LastResponse.ResponseUri as an extraction rule is designed for iterating over the response body.

Nat
  • 14,175
  • 5
  • 41
  • 64
  • Sorry, I am not sure how to use this. Can you give me an example please? – 4imble Feb 21 '12 at 11:57
  • 1
    Ahh i got it. The webtest has a context so : var response1 = this.Context.LastResponse.ResponseUri; gives me the string i need. – 4imble Feb 21 '12 at 12:20