My Thoughts: Configure browser proxy settings using Selenium WebDriver

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 :)


19 comments:

  1. HI Vamshi,
    your post are very helpful and it will be nice if u write a post on Ghost driver .

    ReplyDelete
  2. Hey Hi,


    I know I am little to reply.
    You must switch to the popup (overlay) before performing drag and drop operation.

    ReplyDelete
  3. Hi Vamshi,


    Can i select text from the document using selenium webdriver?


    Thanks,
    Akash Gupta

    ReplyDelete
  4. vamshi sir,
    hi

    i had follow ur mention abow step but still error is coming plz help me
    Error : Exception in thread "main" java.lang.UnsatisfiedLinkError: no AspriseOCR in java.library.path

    ReplyDelete
  5. giving me error org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"draggable"}
    Command duration or timeout: 251 milliseconds
    For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
    Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
    System info: host: 'admin-HP', ip: '192.168.1.146', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0'
    Session ID: 722d5004-5abd-41f8-9c22-e9e5926902a8
    Driver info: org.openqa.selenium.firefox.FirefoxDriver
    Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=23.0, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=false, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]

    ReplyDelete
  6. Did you add AspriseOCR.dll file at C:\Windows\System32 ?

    ReplyDelete
  7. Hi Akash,

    Right now I don't have any thing in mind using which will just highlight the text on webpage using webdriver.


    But if you want to verify a particular text from document in the webpage , you can always do it by checking the source code of webpage .

    ReplyDelete
  8. Hi Vamshi,


    No problem i will manage it.
    And thank you so much for giving me your best time.


    Thanks,
    Akash Gupta.

    ReplyDelete
  9. Hey
    If you happened to find any work around share with me .

    ReplyDelete
  10. Is it possible to get text from captcha image using above method

    ReplyDelete
  11. Madiraju Krishna ChaitanyaTuesday, February 25, 2014

    Hi Vamsi Kurra,I was searching for information on testng.xml information and I found this article.Thank You.Wonderful Stuff.One small favor though.Can you provide us more details about testng.xml file with detailed description(like,

    in beforeSuite,in beforeTest,in beforeClass,in beforeMethod...etc) and an example with the order of execution of the testng Annotations.Thank You.

    ReplyDelete
  12. Hi vamshi,
    All together is a nice stuff................i am unable to read .png image but i can able to read .jpg image........so please help me out with your idea.

    ReplyDelete
  13. Can you share the image you are trying ?

    ReplyDelete
  14. Hi Vashmi,

    Thankz for nice post. I am verifying the text of .png image. The problem with my script is that it is getting stopped at image =ImageIO.read(url);
    String s = new OCR().recognizeCharacters((RenderedImage) image);
    and taking too much time to execute forward. Please suggest if you have any solution.

    ReplyDelete
  15. Hi Pankaj,

    Just want to confirm did you copy all the DLL files ( ASpireOCr.dll , DEVIL and iLU DLL) to system32 folder ?
    Also did you add the aspireOCr jar file to eclipse external jar?

    ReplyDelete
  16. Oh , also as we are using free version , we will get external alert while running the script. Just confirm that alert so that the script will go smooth.

    ReplyDelete
  17. Hi Vamshi,

    I added the "AspriseOCR.dll" at "C:\Windows\System32", but it also point out "java.lang.UnsatisfiedLinkError: no AspriseOCR in java.library.path" Exception.

    I also tried many methods but all failed.
    1. I tried add all the dll files in the asprise file to system32, but failed.
    2. I also added the location of asprise to "environment variables".
    3. Add vmargs to Eclipse.ini, such as "launcher.library" and "-Djava.library.path".

    Finally, I import the dll files into the project in Eclipse, then it works.

    Could you please tell me how to resolve it with the "system32"?
    Thank you.

    ReplyDelete
  18. hai,
    can i select the image displayed on the gmail account creating page .ie, the security image that is displayed on the account creation page? using this code?

    ReplyDelete
  19. Thank for your post,
    I follow your post, but it doesn't work, when I go to http://www.whatismyip.com/, my ip doesn't change

    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);

    driver.get("http://www.whatismyip.com/");

    ReplyDelete