简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM