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.brhttp://testavo.blogspot.comhttp://www.
LUGATI.
com.br