Search code examples
javaseleniumproxyphantomjs

How to make sure that my application is using Proxy server and not my IP address in selenium?


I am using Selenium with PhantomJS browser. I have set up proxy as below:

DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
capabilities.setJavascriptEnabled(true);
System.setProperty("phantomjs.binary.path", "../Drivers/phantomjs.exe");

ArrayList<String> cliArgsCap = new ArrayList<String>();
cliArgsCap.add("--proxy=hostname:port");
cliArgsCap.add("--proxy-auth=username:password");
cliArgsCap.add("--proxy-type=http");
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);

driver = new PhantomJSDriver(capabilities);

My application is running fine. But how to validate if my application is using the proxy that I have set up?


Solution

  • Before running your main script, make request to http://api.ipify.org/ that shows client's current IP and check in the code if it's your IP or the proxy IP.