Let's say if your application work with proxy values on your browser, so you need to set the proxy server and port number before invoking the application so here is the code.
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;
import org.testng.annotations.Test;
public class ProxyTest {
@Test
public void testMethod(){
WebDriver driver;
String usedProxy = "IPAddress:port";
Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(usedProxy).setFtpProxy(usedProxy).setSslProxy(usedProxy);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
driver = new FirefoxDriver(cap);
driver.get("yoursite.com/");
}
}
No comments:
Post a Comment