Methods of easily debugging/fixing the scripts with known facts - Part1

Network proxy issue in the Firefox browser – we can handle the proxy issue in two ways
a)       Fixing the issue outside the script – i.e., creating the Firefox Profile and set the proxy how we need and map it to the Selenium web driver script. By saying it looks easy. But the problem will start,
Firefox profile Java class not able to get the correct intended Profile. This issue will happen if we have installed our Firefox browser outside the “c:/program files” folders.

How we can resolve this issue?

Yes, I do have workaround for this problem. We can achieve this by doing Method overriding. Here we need to override the method getPofiles of the class profileIni. Let see the code implementations,

//Setting the firefox.exe file path
File pathToBinary = new File (“<Firefox.exe file path>”);
FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);

//overriding the profilepath
ProfilesIni profile = new ProfilesIni() {
@Override
public FirefoxProfile getProfile(String profileName) {

File appData = new File("<FireFoxProfilePath>");
                Map<String, File> profiles = readProfiles(appData);
                File profileDir = profiles.get(profileName);
                if (profileDir == null)
                                return null;
                return new FirefoxProfile(profileDir);
                }
};

FirefoxProfile firefoxProfile = profile.getProfile(“<FireFoxProfileName>");
driver = new FirefoxDriver(ffBinary, firefoxProfile);

                                                This will invoke the firefox brower J
                               
                                b) Handling the proxy within the script using Desiredcaptabilites

                                                String proxyUrl = “<ProxyHost>" + ":" +”<ProxyPort>";
                               
                                                Proxy proxy = new Proxy();
                                                proxy.setProxyType(ProxyType.MANUAL);
                                                proxy.setHttpProxy(proxyUrl);
                                                proxy.setFtpProxy(proxyUrl);
                                                proxy.setSslProxy(proxyUrl);
                               
                                                DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
                                                desiredCapabilities.setCapability(CapabilityType.PROXY, proxy);

driver = new FirefoxDriver(desiredCapabilities);



                Note: chrome browser – we can use either Chromeoptions or desired capabilities

Popular posts from this blog

Selenium Webdriver Interview Questions with Answer

Selenium IDE Interview Questions with Answer

DLL to Jar file conversion