by Nataliia Vasylyna | March 28, 2011 8:00 am
One of the parts of Selenium 1.0 that I never enjoyed was debugging automation that didn’t work. I had to faff about creating custom Firefox profiles with Firebug installed and set to go through a proxy.
Selenium 2 makes all of that so much easier. With the code below, my test runs through a proxy server on port 8081 and has Firebug installed so that I can breakpoint my test and then go debugging around in the browser DOM, debug the JavaScript to make sure events get fired, etc. etc.
I found most of the information to do this on the Selenium Forums.
The code should be easy enough to follow if you are already using Selenium 2
import java.io.File;
import java.io.IOException;
import org.junit.Test;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
@Test
public void FirefoxUseExtensions() throws IOException{
// setup the firefox proxy to point to Burpsuite
// on port 8081
Proxy localhostProxy = new Proxy();
localhostProxy.setProxyType(Proxy.ProxyType.MANUAL);
localhostProxy.setHttpProxy("localhost:8081");
// Prior to running the test
// Download the firebug extension file
// to a local folder
String extensionPath = System.getProperty("user.dir")
+ "/"
+ "firefoxExtensions/firebug-1.6.2.xpi";
// create a custom profile
FirefoxProfile profile = new FirefoxProfile();
// set the profile to use the proxy settings
profile.setProxyPreferences(localhostProxy);
// stop firebug showing the first run
// screen by setting the 'last version'
// to the current one downloaded
// try without this and see what happens!
profile.setPreference("extensions.firebug.currentVersion", "1.6.2");
// add the extension to firefox
profile.addExtension(new File(extensionPath));
// start firefox with the custom profile
WebDriver driver = new FirefoxDriver(profile);
// go to your favourite testing web site
driver.get("http://www.eviltester.com");
}
Source: http://www.eviltester.com/index.php/2011/03/23/selenium-2-makes-automation-debugging-easier/
Source URL: https://blog.qatestlab.com/2011/03/28/selenium-2-makes-automation-debugging-easier/
Copyright ©2025 QATestLab Blog unless otherwise noted.