My Thoughts: December 2013

Sunday, December 29

Configure browser proxy settings using Selenium WebDriver

Most of software testers are familiar with the term "Changing proxy settings" :P .
The only reason ( atleast for me :P ) we change browser proxy settings is to verify "multilingual" and "multi-regional" websites .
  • A multilingual website is any website that offers content in more than one language (Facebook) .
  • A multi-regional website is one that explicitly targets users in different countries (Bwin).

If business is happened to spread in multiple countries then website has to offer content in more than one language.But it is always not so easy to test "multi-regional" websites.Sometimes we have to change the proxy settings of browser to verify the functionality.

Say if you directly access the bwin.com from India then we will get redirecte to http://help.bwin.com/closed   and we will see the below page.


But if you access the same bwin.com site from United States then you will see the below page.


Manually if we want to test this functionality then we will get proxy server details from online and change our browser proxy settings , before accessing the site from our browser.

But if we want to verify the same functionality through automation , then we must know way using which we can modify the proxy server settings of browser . And here is the sample program to do that  :)
import java.io.IOException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class ProxySettings {
 
  WebDriver driver;
    String serverIP=199.201.125.147;
String port=199.201.125.147;   

@BeforeTest
    public void setUpDriver() {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("network.proxy.type",1);
    profile.setPreference("network.proxy.ftp",serverIP);
    profile.setPreference("network.proxy.http",serverIP);
    profile.setPreference("network.proxy.socks",serverIP);
    profile.setPreference("network.proxy.ssl",serverIP);
    profile.setPreference("network.proxy.ftp_port",port);
    profile.setPreference("network.proxy.http_port",port);
    profile.setPreference("network.proxy.socks_port",port);
    profile.setPreference("network.proxy.ssl_port",port);
    driver = new FirefoxDriver(profile);
    }
   
   
   @Test
   public void start() throws IOException{
    driver.get("https://www.bwin.com/");
    driver.findElement(By.id("username")).sendKeys("MyUserName");
    driver.findElement(By.id("password")).sendKeys("MyTestPassword");
    driver.findElement(By.name("submit")).click();
   }
   

}

And last but not the least  ,
Advance Happy New Year ..!! Have fun :)