Selenium WebDriver proxy authentication

1,392 views
Skip to first unread message

Luiz Gustavo Schroeder Vieira

unread,
Sep 8, 2011, 1:32:39 PM9/8/11
to selenium-...@googlegroups.com

Hi,


I would like to know how can I authenticate on Proxy automaticaly using Selenium WebDriver.

I already could set my host and port using FirefoxProfile, but I could not set my proxy user and password.

Afterwards, I have made a research on web and I got this code:

package org.openqa.selenium.example;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider;
import com.gargoylesoftware.htmlunit.WebClient;

public class Script_001  {
   
    static String PROXY_USER = "prog17";
    static String PROXY_PASS = "045278";
    static String PROXY_HOST = "ironport";
    static int PROXY_PORT= 80;
    static String PROXY_WORKSTATION = "tavo-notebook.";
   
    public void runTest001 () {
        WebDriver driver = new HtmlUnitDriver() {
              protected WebClient modifyWebClient(WebClient client) {
                // This class ships with HtmlUnit itself
                DefaultCredentialsProvider creds = DefaultCredentialsProvider();

                // Configurações da proxy
                creds.addCredentials(PROXY_USER, PROXY_PASS, PROXY_HOST, PROXY_PORT, PROXY_WORKSTATION);               

                // And now add the provider to the webClient instance
                client.setCredentialsProvider(creds);

                return client;
              }

            private DefaultCredentialsProvider DefaultCredentialsProvider() {
                // TODO Auto-generated method stub
                return null;
            }
           
            };
                       
        // And now use this to visit Google       
        driver.get("http://www.google.com/");
        //driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
      
        // Find the text input element by its name
        WebElement element = driver.findElement(By.name("q"));

        // Enter something to search for
        element.sendKeys("LUGATI IT Services");

        // Now submit the form. WebDriver will find the form for us from the element
        element.submit();

        // Check the title of the page
        System.out.println("Page title is: " + driver.getTitle());
    }
   
    public static void main(String[] args) throws Exception {
        Script_001 script = new Script_001();
        script.runTest001();
    }
}


Does anyone knows how to get there?


Best regards,
Luiz Gustavo Schroeder Vieira, FCE, CTAL-TA
Consultor de Testes
BSTQB TAG Member
+55 (48) 9994-3569
Skype: luizgsvieira
luizgustavo@LUGATI.com.br
http://testavo.blogspot.com
http://www.LUGATI.com.br

Walter Gorlitz

unread,
Sep 8, 2011, 2:15:23 PM9/8/11
to selenium-...@googlegroups.com
On 2011-09-08 10:32 AM, Luiz Gustavo Schroeder Vieira wrote:
>
> Hi,
>
>
> I would like to know how can I authenticate on Proxy automaticaly
> using Selenium WebDriver.
>
> I already could set my host and port using FirefoxProfile, but I could
> not set my proxy user and password.

Can the proxy user and password be stored?
If so, run the Profile Manager and sign-in as the Selenium profile and
store it there.
You don't always have to do things programmatically =)

Walter

Reply all
Reply to author
Forward
0 new messages