2012-08-29 56 views
6

Cuando configura el parámetro del servidor proxy en el siguiente código si su servidor proxy requiere autenticación, FireFox mostrará el cuadro de diálogo Autenticación y básicamente no podrá completarlo automáticamente. Entonces, ¿hay alguna manera de establecer NOMBRE DE USUARIO y CONTRASEÑA?C# Selenium WebDriver FireFox Profile - usando proxy con Autenticación

FirefoxProfile profile = new FirefoxProfile(); 
String PROXY = "192.168.1.100:8080"; 
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); 

Si intenta formatear cadena de proxy a algo así http://username:[email protected]:8080 obtiene el error de que la cadena no es válido. Entonces me pregunto si debe haber una forma de lograr esto.

Cualquier ayuda sería apreciada.

+0

Todavía no he encontrado una respuesta a esta, por el momento desactivé la autenticación en mi servidor proxy y lo permití por rango de IP, así que por el momento funciona de alguna manera. – Tim

+0

qué referencia necesito para 'ProfilesIni' obteniendo el error' El tipo o el nombre del espacio de nombres 'ProfilesIni' no se pudo encontrar' –

Respuesta

0

Lo que puede hacer es crear un perfil y guardar los datos de autenticación en él. Si su perfil se llama "WebDriver" se puede seleccionar desde el código en la inicialización:

ProfilesIni allProfiles = new ProfilesIni(); 
FirefoxProfile profile = allProfiles.getProfile("WebDriver"); 
profile.setPreferences("foo.bar",23); 
WebDriver driver = new FirefoxDriver(profile); 
+0

Eso es muy interesante, debería intentar informar si eso funciona – Tim

+0

¡Genial! Por favor, mantenme informado :) –

+0

¿En qué espacio de nombres está ProfilesIni? :/... –

2
 String PROXY = "http://login:[email protected]:port"; 
     ChromeOptions options = new ChromeOptions(); 

     options.AddArguments("user-data-dir=path/in/your/system"); 

     Proxy proxy = new Proxy(); 

     proxy.HttpProxy = PROXY; 
     proxy.SslProxy = PROXY; 
     proxy.FtpProxy = PROXY; 

     options.Proxy = proxy; 

     // Initialize the Chrome Driver 
     using (var driver = new ChromeDriver(options)) 
0

hice con MS UI Automation sin AutoIt:

public void AuthInProxyWindow (string login, string pass) 
    { 
     var proxyWindow = AutomationElement.RootElement 
      .FindFirst(TreeScope.Subtree, 
       new PropertyCondition(AutomationElement.ClassNameProperty, "MozillaDialogClass")); 

     var edits = proxyWindow.FindAll(TreeScope.Subtree, 
      new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)); 

     var unamePoint = edits[1].GetClickablePoint(); 
     Mouse.MoveTo(new Point((int) unamePoint.X, (int) unamePoint.Y)); 
     Mouse.Click(MouseButton.Left); 

     SendKeys.SendWait(login); 
     var pwdPoint = edits[2].GetClickablePoint(); 
     Mouse.MoveTo(new Point((int) pwdPoint.X, (int) pwdPoint.Y)); 
     Mouse.Click(MouseButton.Left); 
     SendKeys.SendWait(pass); 

     Keyboard.Press(Key.Return); 
     Logger.Debug("Authefication in Firefox completed succesfully"); 
    } 

ratón se mueve por Microsoft.TestApi

Cuestiones relacionadas