To load test an ASP.NET web application I created a Console Application that simulated the process one user would go through to complete adding a new order, from automatic login, to product selection, to logout.
The Console Application
- Create a thread to host an instance of System.Windows.Forms.WebBrowser in.
See WebBrowser Control in a new thread
- Create the URL that the user navigation will start from. The included single sign on details that would establish the Session.
- Register for the DocumentCompleted event from the WebBrowser so I can detect when the page has been completely loaded.
- Call WebBrowser.Navigate() with the URL.
- Start the STA Thread running.
- When the DocumentCompleted event fires check if the event args URL matches the browsers URL.
- If the URLs match the navigation has been completed and the browser can be transitioned to the next step.
- Keep checking the DocumentCompleted event until the WebBrowser reaches a page that indicates the process is complete. When it is, exit the thread to return to the main program. System.Windows.Forms.Application.ExitThread();
- The Console Application would close with and Exit Code of 0 if the process was successful. Otherwise the Exit code would correspond to a enum flag indicating what issue was encountered.
Why use a WebBrowser instance rather than HttpWebRequest/HttpWebResponse and a CookieContainer?
I started down this path but there were a couple of issues.
Using loadUI to start and monitor the Console Application
- Create a Fixed Rate Generator
- Connect it to a Process Runner