public void CanConfigureProxyThroughAutoConfigFile() { StringBuilder pacFileContentBuilder = new StringBuilder(); pacFileContentBuilder.AppendLine("function FindProxyForURL(url, host) {"); pacFileContentBuilder.AppendFormat(" return 'PROXY {0}';\n", proxyServer.BaseUrl); pacFileContentBuilder.AppendLine("}"); string pacFileContent = pacFileContentBuilder.ToString(); using (ProxyAutoConfigServer pacServer = new ProxyAutoConfigServer(pacFileContent)) { proxyServer.EnableContentOverwriteOnRequest(); Proxy proxyToUse = new Proxy(); proxyToUse.ProxyAutoConfigUrl = string.Format("http://{0}:{1}/proxy.pac", pacServer.HostName, pacServer.Port); InitLocalDriver(proxyToUse); localDriver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("simpleTest.html"); Assert.That(localDriver.FindElement(By.TagName("h3")).Text, Is.EqualTo("Hello, world!")); } }
public void CanUseAutoConfigFileThatOnlyProxiesCertainHosts() { StringBuilder pacFileContentBuilder = new StringBuilder(); pacFileContentBuilder.AppendLine("function FindProxyForURL(url, host) {"); pacFileContentBuilder.AppendFormat(" if (url.indexOf('{0}') != -1) {{\n", EnvironmentManager.Instance.UrlBuilder.HostName); pacFileContentBuilder.AppendFormat(" return 'PROXY {0}';\n", proxyServer.BaseUrl); pacFileContentBuilder.AppendLine(" }"); pacFileContentBuilder.AppendLine(" return 'DIRECT';"); pacFileContentBuilder.AppendLine("}"); string pacFileContent = pacFileContentBuilder.ToString(); using (ProxyAutoConfigServer pacServer = new ProxyAutoConfigServer(pacFileContent)) { proxyServer.EnableContentOverwriteOnRequest(); Proxy proxyToUse = new Proxy(); proxyToUse.ProxyAutoConfigUrl = string.Format("http://{0}:{1}/proxy.pac", pacServer.HostName, pacServer.Port); InitLocalDriver(proxyToUse); localDriver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("simpleTest.html"); Assert.That(localDriver.FindElement(By.TagName("h3")).Text, Is.EqualTo("Hello, world!")); localDriver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIsViaNonLoopbackAddress("simpleTest.html"); Assert.That(localDriver.FindElement(By.TagName("h1")).Text, Is.EqualTo("Heading")); } }