use of io.github.bonigarcia.wdm.HttpClient in project webdrivermanager by bonigarcia.
the class PhantomJsFilterTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
phatomJsManager = PhantomJsDriverManager.getInstance();
Field field = WebDriverManager.class.getDeclaredField("httpClient");
field.setAccessible(true);
field.set(phatomJsManager, new HttpClient());
Method method = WebDriverManager.class.getDeclaredMethod("getDrivers");
method.setAccessible(true);
driversUrls = (List<URL>) method.invoke(phatomJsManager);
}
use of io.github.bonigarcia.wdm.HttpClient in project webdrivermanager by bonigarcia.
the class ProxyTest method testProxyCredentialsScope.
@Test
public void testProxyCredentialsScope() throws Exception {
WebDriverManager.config().setProxy("myproxy:8081").setProxyUser("domain\\me").setProxyPass("pass");
HttpClient wdmClient = new HttpClient();
Field field = HttpClient.class.getDeclaredField("closeableHttpClient");
field.setAccessible(true);
CloseableHttpClient client = (CloseableHttpClient) field.get(wdmClient);
field = client.getClass().getDeclaredField("credentialsProvider");
field.setAccessible(true);
BasicCredentialsProvider provider = (BasicCredentialsProvider) field.get(client);
assertThat(provider.getCredentials(new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, NTLM)), instanceOf(NTCredentials.class));
assertThat(provider.getCredentials(new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, BASIC)), instanceOf(UsernamePasswordCredentials.class));
assertThat(provider.getCredentials(new AuthScope(ANY_HOST, ANY_PORT)), instanceOf(UsernamePasswordCredentials.class));
assertThat(provider.getCredentials(new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, KERBEROS)), instanceOf(UsernamePasswordCredentials.class));
}
use of io.github.bonigarcia.wdm.HttpClient in project webdrivermanager by bonigarcia.
the class ProxyTest method getProxy.
private Optional<Proxy> getProxy(WebDriverManager browserManager) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, MalformedURLException {
Field httpClientField = WebDriverManager.class.getDeclaredField("httpClient");
httpClientField.setAccessible(true);
httpClientField.set(browserManager, new HttpClient());
Field configField = WebDriverManager.class.getDeclaredField("config");
configField.setAccessible(true);
Config config = (Config) configField.get(browserManager);
String proxy = config.getProxy();
HttpClient wdmHttpClient = (HttpClient) httpClientField.get(browserManager);
return wdmHttpClient.createProxy(proxy);
}
use of io.github.bonigarcia.wdm.HttpClient in project webdrivermanager by bonigarcia.
the class ProxyTest method testProxyCredentials.
@Test
public void testProxyCredentials() throws Exception {
WebDriverManager.config().setProxy("myproxy:8081").setProxyUser("domain\\me").setProxyPass("pass");
HttpClient wdmClient = new HttpClient();
Field field = HttpClient.class.getDeclaredField("closeableHttpClient");
field.setAccessible(true);
CloseableHttpClient client = (CloseableHttpClient) field.get(wdmClient);
field = client.getClass().getDeclaredField("credentialsProvider");
field.setAccessible(true);
BasicCredentialsProvider provider = (BasicCredentialsProvider) field.get(client);
NTCredentials ntcreds = (NTCredentials) provider.getCredentials(new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, NTLM));
assertThat(ntcreds.getDomain(), equalTo("DOMAIN"));
assertThat(ntcreds.getUserName(), equalTo("me"));
assertThat(ntcreds.getPassword(), equalTo("pass"));
UsernamePasswordCredentials creds = (UsernamePasswordCredentials) provider.getCredentials(new AuthScope(ANY_HOST, ANY_PORT));
assertThat(creds.getUserName(), equalTo("domain\\me"));
assertThat(creds.getPassword(), equalTo("pass"));
}
Aggregations