I'm curious if there is a way to make a post with JSON data attached to it in test studio? This would make it easy for me to departmentalize some of my testing and feature sets.
3 Answers, 1 is accepted
Test Studio does not have a built-in feature to do a POST with any random JSON data. Test Studio was designed to drive the browser, let it do all the GET's and POST's and the validate what is loaded in the browsers DOM contains the expected results.
You could write code in a coded step to do this. Normally this would be beyond our ability to help (other than pointing you in the right direction) but I happened to work on a project recently that required this. Here's the code I used in that project:
/// Sends a JSON object to a JIRA server using an HTTP POST
/// and gets the JSON response from the server.
/// <param name="server"></param>
/// <param name="path">The REST path send the request to e.g. /rest/api/2/project</param>
/// <param name="username">The user ID required for authentication. null or empty will use anonymous access.</param>
/// <param name="password">The password required for authentication. null or empty will use anonymous access.</param>
/// <param name="json_request">The JSON object to include in the POST</param>
username, Base64String password, JToken json_request,
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(server + path);
httpWebRequest.ProtocolVersion = HttpVersion.Version11;
httpWebRequest.UserAgent = agent;
httpWebRequest.Proxy = WebRequest.GetSystemWebProxy();
// Add the required authentication header
.IsNullOrEmpty(username) && !
Base64String authInfo = password.prefix(username +
(StreamWriter streamWriter =
HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
(JsonTextReader streamReader =
result = JToken.ReadFrom(streamReader);
error = e.Message;
and send us your feedback!
Thanks for the code! I had it working within a few minutes. =D
So in attempts to better compartmentalize our tests, I'm trying to use this post to skip a page on UI testing. Taking from your response, I assume I may be out of luck... I'm going to give you my scenario, to make sure I'm on the same page.
I have a page that contains a AJAX requested list of items, essentially each list posts to redirect the browser with an item ID. This ID signifies what you clicked on. So if I have a list of people, Adam, Bob, Alice, and I click on Alice with ID 3, it will POST with that ID to the manageuser page. What I'm trying to do is manually POST so that I don't have to go through the process of waiting for the page to load, waiting for the AJAX, looking for the object and clicking the object to make the POST and have the browser redirect.
Currently it looks like I won't be able to drive the browser this way.
Anyway thanks again for the response! I appreciate it!
and send us your feedback!