How to add proxy setting to webdriver

I had to run the Webdriver scripts on a Firefox and I had to use a particular proxy to get access to the QA/Dev environment. Here is the code that you can use to change the proxy settings.

FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("network.proxy.type", 1);
firefoxProfile.setPreference("network.proxy.http", "100.00.100.100");
firefoxProfile.setPreference("network.proxy.http_port", 80);
firefoxProfile.setPreference("network.proxy.ssl", "100.00.100.100");
firefoxProfile.setPreference("network.proxy.ssl_port", 80);
firefoxProfile.setPreference("network.proxy.no_proxies_on", "");
driver = new FirefoxDriver(firefoxProfile);

Make changes to the PROXY_HOST – “100.00.100.100” and the PROXY_PORT – 80. The PROXY_PORT is an Integer and PROXY_HOST is a String.

The constructor DefaultSelenium(String, String, String, String) is undefined

I was creating a script in Java and wanted to run the script using TestNG and Eclipse. I was getting the following error when running the script.
The constructor DefaultSelenium(String, String, String, String) is undefined
To solve the issue you will have to make change to the setUp method.
My code was something like this selenium = new DefaultSelenium(“localhost”, “4444”, “*iexplore”, “http://www.google.com/”); having 4444 as a string. I then changed the code to selenium = new DefaultSelenium(“localhost”, 4444, “*iexplore”, “http://www.google.com/”);

Sample Selenium RC Script using TestNG Eclipse

Here is a sample Selenium RC TestNG script that you can use to create selenium scripts in java and debug or run the test scripts using TestNG.
Before you do that you will have to add the TestNG Eclipse plugin; Please have a look at the details given below:
You can download TestNG here.

For the Eclipse plug-in, we suggest using the update site:

* Select Help / Software updates / Find and Install.
* Search for new features to install.
* New remote site.
* For Eclipse 3.4 and above, enter http://beust.com/eclipse.
* For Eclipse 3.3 and below, enter http://beust.com/eclipse1.
* Make sure the check box next to URL is checked and click Next.
* Eclipse will then guide you through the process.

However, should this method fail, you can also download the TestNG Eclipse plug-in directly and extract it in your dropins/ directory.


import com.thoughtworks.selenium.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;

public class GoogleSearchTestNG {
public Selenium selenium;
@BeforeClass
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com.au/");
selenium.start();
}

@Test
public void testUntitled() throws Exception {
selenium.open("/");
selenium.type("q", "seleniumwiki.com");
selenium.click("btnG");
selenium.waitForPageToLoad("30000");
assertTrue(selenium.isTextPresent("Selenium"));
}

@AfterClass
public void tearDown() throws Exception {
selenium.stop();
}
}