2010-05-22 19 views
32

¿hay alguna forma de establecer la configuración proxy de Firefox? Encontré información sobre FoxyProxy aquí, pero cuando funciona Selenium, los complementos no están activados en la ventana.Webdriver y servidor proxy para firefox

Respuesta

14

Mira the documentation page.

Afinando un perfil existente Firefox

necesita cambiar "network.proxy.http" & "network.proxy.http_port" configuración del perfil.

FirefoxProfile profile = new FirefoxProfile(); 
profile.addAdditionalPreference("network.proxy.http", "localhost"); 
profile.addAdditionalPreference("network.proxy.http_port", "3128"); 
WebDriver driver = new FirefoxDriver(profile); 
+6

Esto podría haber sido correcto en 2010, pero el método addAdditionalPreference ya no existe en FirefoxProfile setPreference tendría que utilizarse para hacer esto a través de FirefoxProfile. Además, para que firefox realmente use el proxy, "network.proxy.type" debe establecerse en 1, ya que la respuesta de Praveen menciona o 2 si se muestra un PAC como Saik0. Utilizo la manera DesiredCapabilities de hacer esto como lo muestra la respuesta de Dan Seibert. – EGHM

-4

Preferencias -> Avanzado -> Red -> Conexión (configure con qué Firefox se conecta a Internet)

+0

Sé esto. Cuando Selenium ejecuta la ventana de Firefox para el trabajo, la pestaña de conexión con proxies está vacía. – Ockonal

8

La API de WebDriver se ha modificado. El fragmento actual para configurar el proxy es

FirefoxProfile profile = new FirefoxProfile(); 
profile.setPreference("network.proxy.http", "localhost"); 
profile.setPreference("network.proxy.http_port", "3128"); 
WebDriver driver = new FirefoxDriver(profile); 
+3

¿qué ocurre con la autenticación proxy? –

43

valor para network.proxy.http_port debe ser un número entero (sin comillas deben utilizarse) y network.proxy.type se debe establecer como 1 (ProxyType.MANUAL, la configuración manual del proxy)

FirefoxProfile profile = new FirefoxProfile(); 
profile.setPreference("network.proxy.type", 1); 
profile.setPreference("network.proxy.http", "localhost"); 
profile.setPreference("network.proxy.http_port", 3128); 
WebDriver driver = new FirefoxDriver(profile); 
+5

Si alguien me dice cómo configuro "user: [email protected]: 2874" en el perfil de firefox, sería muy apreciado. He intentado 'profile.setPreference (" network.proxy.http "," user: [email protected]: 2874 ")' pero obviamente NO funciona. – Shane

+4

¿qué ocurre con la autenticación proxy? –

+2

@Shane: profile.setPreference ("network.proxy.http", "http: // usuario: [email protected]"), luego profile.setPreference ("network.proxy.http_port", 2874) debería funcionar. – learnJQueryUI

0

Hay es otra solución, busqué porque a había problemas con código como este (que s Ajustar el proxy sistema en Firefox):

FirefoxProfile profile = new FirefoxProfile(); 
profile.setPreference("network.proxy.http", "localhost"); 
profile.setPreference("network.proxy.http_port", "8080"); 
driver = new FirefoxDriver(profile); 

Prefiero esta solución, fuerza la configuración manual del proxy en firefox. Para ello, utiliza el objeto de configurar Firefox org.openqa.selenium.Proxy:

FirefoxProfile profile = new FirefoxProfile(); 
localhostProxy.setProxyType(Proxy.ProxyType.MANUAL); 
localhostProxy.setHttpProxy("localhost:8080"); 
profile.setProxyPreferences(localhostProxy); 
driver = new FirefoxDriver(profile); 

si pudiera ayudar ...

4

para las direcciones URL

Proxy proxy = new Proxy(); 
proxy.setProxyType(Proxy.ProxyType.PAC); 
proxy.setProxyAutoconfigUrl("http://some-server/staging.pac"); 
DesiredCapabilities capabilities = new DesiredCapabilities(); 
capabilities.setCapability(CapabilityType.PROXY, proxy); 
return new FirefoxDriver(capabilities); 

espero basados ​​PAC esto podría ayudar.

+0

¿Cómo autenticar en este proxy? Lo intento como 'http: // code: Blue% 4019 @ proxypath.pac'. Pero no puedo cargar ninguna página. – codeomnitrix

0
FirefoxProfile profile = new FirefoxProfile(); 
String PROXY = "xx.xx.xx.xx:xx"; 
OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy(); 
proxy.HttpProxy=PROXY; 
proxy.FtpProxy=PROXY; 
proxy.SslProxy=PROXY; 
profile.SetProxyPreferences(proxy); 
FirefoxDriver driver = new FirefoxDriver(profile); 

Es para C#

17

acabo de tener diversión con este tema durante un par de días y era difícil para mí encontrar una respuesta para HTTPS, así que aquí está mi opinión, para Java:

FirefoxProfile profile = new FirefoxProfile(); 
    profile.setPreference("network.proxy.type", 1); 
    profile.setPreference("network.proxy.http", "proxy.domain.example.com"); 
    profile.setPreference("network.proxy.http_port", 8080); 
    profile.setPreference("network.proxy.ssl", "proxy.domain.example.com"); 
    profile.setPreference("network.proxy.ssl_port", 8080); 
    driver = new FirefoxDriver(profile); 

Gotchas aquí: introducir sólo el dominio y no http://proxy.domain.example.com, el nombre de propiedad es .ssl y no .https

ahora estoy teniendo aún más fu n tratando de conseguir que se acepte mi auto firmado certificados ...

+2

gracias, HTTPS solo funciona con estas configuraciones – AdamSkywalker

5

En caso si usted tiene una dirección URL de configuración automática -

 FirefoxProfile firefoxProfile = new FirefoxProfile(); 
     firefoxProfile.setPreference("network.proxy.type", 2); 
     firefoxProfile.setPreference("network.proxy.autoconfig_url", "http://www.etc.com/wpad.dat"); 
     firefoxProfile.setPreference("network.proxy.no_proxies_on", "localhost"); 
     WebDriver driver = new FirefoxDriver(firefoxProfile); 
4

Aquí está un ejemplo de Java utilizando DesiredCapabilities. Lo usé para bombear pruebas de selenio en jmeter.(Sólo estaba interesado en las solicitudes HTTP)

import org.openqa.selenium.Proxy; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.remote.CapabilityType; 
import org.openqa.selenium.remote.DesiredCapabilities; 

String myProxy = "localhost:7777"; //example: proxy host=localhost port=7777 
DesiredCapabilities capabilities = new DesiredCapabilities(); 
capabilities.setCapability(CapabilityType.PROXY, 
          new Proxy().setHttpProxy(myProxy)); 
WebDriver webDriver = new FirefoxDriver(capabilities); 
1

Firefox Proxy: JAVA

String PROXY = "localhost:8080"; 

org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy(); 

proxy.setHttpProxy(PROXY)setFtpProxy(PROXY).setSslProxy(PROXY); 

DesiredCapabilities cap = new DesiredCapabilities(); 

cap.setCapability(CapabilityType.PROXY, proxy); 

WebDriver driver = new FirefoxDriver(cap); 
5

Sólo para añadir a las soluciones dadas anteriormente,

Adición de la lista de posibilidades (valores enteros) para. el "network.proxy.type".

0 - Direct connection (or) no proxy. 

1 - Manual proxy configuration 

2 - Proxy auto-configuration (PAC). 

4 - Auto-detect proxy settings. 

5 - Use system proxy settings. 

Por lo tanto, la base de nuestra requisito, el valor "network.proxy.type" se debe establecer como se menciona a continuación.

FirefoxProfile profile = new FirefoxProfile(); 
profile.setPreference("network.proxy.type", 1); 
WebDriver driver = new FirefoxDriver(profile); 
Cuestiones relacionadas