I am trying to navigate to an application on a localhost site that requires authentication using PhantomJSDriver and passing username:password into the URL. In order to capture response codes I'm using a Fiddler proxy from Jim Evan's example https://github.com/jimevans/WebDriverProxyExamples.
PhantomJSDriver navigates successfully (using NTLM/Basic auth) but Fiddler doesn't capture the traffic.
public static int NavigateTo(this IWebDriver driver, string targetUrl, TimeSpan timeout, bool printDebugInfo)
{
int responseCode = 0;
DateTime endTime = DateTime.Now.Add(timeout);
SessionStateHandler responseHandler = delegate(Session targetSession)
{
if (targetSession.responseCode >= 300 && targetSession.responseCode < 400)
{
targetUrl = targetSession.GetRedirectTargetURL();
}
else
responseCode = targetSession.responseCode;
};
// Attach the event handler, perform the navigation, and wait for
// the status code to be non-zero, or to timeout. Then detach the
// event handler and return the response code.
FiddlerApplication.AfterSessionComplete += responseHandler;
driver.Url = targetUrl;
while (responseCode == 0 && DateTime.Now < endTime)
{
System.Threading.Thread.Sleep(100);
}
FiddlerApplication.AfterSessionComplete -= responseHandler;
return responseCode;
}
I was able to capture the traffic when using ChromeDriver with the same application and also for a website that didn't require authentication using PhanotmJSDriver. The only scenario it doesn't work in is PhantomJSDriver + authentication website.
Update:
I discovered the issue thanks to Dead Link
http://docs.telerik.com/fiddler/observe-traffic/troubleshooting/notraffictolocalhost/. It was nothing to do with authentication rather getting traffic from localhost.
The solution was to use the local machine name in place of localhost in the URL.
I discovered the issue thanks to http://docs.telerik.com/fiddler/observe-traffic/troubleshooting/notraffictolocalhost/. It was nothing to do with authentication rather getting traffic from localhost. I'm not sure why, but it seems the combination of using PhantomJSDriver to navigate to a localhost url and Fiddler to capture the traffic did not work.
The solution was to use the local MACHINE NAME in place of 'localhost' in the URL.