开发者

Accessing Response Packet from within C# code, using an existing instance of Web Browser

I am writing C# Coded UI Tests in Visual Studio 2010. To enhance the testing, I need to access all the responses coming back from the server. For instance, I am testing the Add New Member use case, if user’s attempt to add a new member fails, and the UI doesn’t show neither the success or failure massage, I want to be able to get more detail from the http response and show the appropriate respond to the tester.

My code first open an instance of SHDocVw.ShellWindows allBrowsers = new SHDocVw.ShellWindows(); if (allBrowsers.Count > 1) { MessageBox.Show("Number active browsers = " + allBrowsers.Count + "." + " Please close all windows and try again..."); 开发者_开发知识库 throw new Exception("Multiple IE Instances not allow "); }

            p = Process.Start("iexplore.exe", "http://bing/");
            BrowserWindow win = new BrowserWindow();


            current.SearchProperties[BrowserWindow.PropertyNames.Name] = "Bing";
           if (p == null) throw new Exception("Could not launch IE");

Now, I need to somehow capture all the responses that server sends back to requests going out from the instance of win object?

I am not sure if there is any way to do with HttpContext or such.


To track responses from web server you need to setup your HTTP proxy that you can control from the tests. See How do I automate a web proxy in .NET for unit tests (including set up and tear down)? , search for something like "fiddler automation unit test" for more articles.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜