我试图导航到localhost站点上的应用程序,该站点需要使用PhantomJSDriver进行身份验证并将用户名:密码传递到URL。 为了捕获响应代码,我使用了Jim Evan的示例https://github.com/jimevans/WebDriverProxyExamples中的Fiddler代理。
PhantomJSDriver成功导航(使用NTLM / Basic auth),但Fiddler不捕获流量。
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; }当使用具有相同应用程序的ChromeDriver以及不需要使用PhanotmJSDriver进行身份验证的网站时,我能够捕获流量。 它无法使用的唯一场景是PhantomJSDriver +身份验证网站。
更新:感谢Dead Link
http://docs.telerik.com/fiddler/observe-traffic/troubleshooting/notraffictolocalhost/,
我发现了这个问题。 这与身份验证无关,而是从localhost获取流量。
解决方案是使用本地计算机名称代替URL中的localhost。
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.
最满意答案
我发现这个问题归功于http://docs.telerik.com/fiddler/observe-traffic/troubleshooting/notraffictolocalhost/ 。 这与身份验证无关,而是从localhost获取流量。 我不确定为什么,但似乎使用PhantomJSDriver导航到localhost url和Fiddler捕获流量的组合不起作用。
解决方案是使用本地MACHINE NAME代替URL中的“localhost”。
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.
更多推荐
发布评论