My requirement is for opening my project site it requires two different proxies.
How to handle it with Selenium Webdriver?
Please help me.
You haven't mentioned what driver you are using(Firefox, Chrome, ..)but this is how you do it for Firefox:
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
profile.setPreference("network.proxy.http_port", proxyPort);
profile.setPreference("network.proxy.ssl", proxyHost);
profile.setPreference("network.proxy.ssl_port", proxyPort);
FirefoxDriver driver = new FirefoxDriver(profile);
Related
I am running my test case using browsermob proxy.I am running my test case in selenium grid.Using Browsermob proxy i am getting ssl error.
When I am running the test on chrome, Chrome shows unsecured massage.
For Firefox, it shows Potential Security Risk Ahead
Here is my code
nodeUrl = Configuration.dockerurl;
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName(Configuration.browsername);
capabilities.setPlatform(Platform.getCurrent());
proxy = getProxyServer(); //getting browsermob proxy
Proxy seleniumProxy = getSeleniumProxy(proxy);
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
proxy.setHostNameResolver(ClientUtil.createDnsJavaResolver());
driver = new RemoteWebDriver(new URL(nodeUrl), capabilities);
proxy.setHarCaptureTypes(CaptureType.REQUEST_HEADERS, CaptureType.RESPONSE_HEADERS);
driver.get("https://www.google.com")
//Rest of the code here
You could adjust the profile to completely ignore SSL warnings :)
FirefoxProfile profile=new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
I am coming from Ruby background, I know how to do this in Ruby Selenium Binding, but I don't know how to do it Java Selenium Binding,
I have this code to create Firefox profile
FirefoxProfile firefoxProfile = new FirefoxProfile(pathToProfile);
WebDriver driver=new FirefoxDriver(firefoxProfile);
It works in selenium 2.53 but it's throws error in very recent selenium binding 3.11.0, Can anyone tell me what's the alternative?
And also I wanted to switch off the marionette to connect to Legacy Firefox driver, I can do this with the following code
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", false);
WebDriver driver=new FirefoxDriver(capabilities);
But if I use the above line, then it gives the FirefoxDriver is deprecated. Can anyone guide me how to create profile as well as how to switch off the marionette?
Yes FirefoxDriver(desiredCapabilities) is deprecated.
Alternate way would be to go with options:
FirefoxOptions foptions = new FirefoxOptions(capabilities);
WebDriver driver=new FirefoxDriver(foptions);
Update : [In order]
FirefoxOptions foptions = new FirefoxOptions();
FirefoxProfile firefoxProfile = new FirefoxProfile(pathToProfile);
foptions.setProfile(firefoxProfile);
foptions.setCapability("marionette", false);
foptions.setBinary("C:\\Program Files\\Mozilla Firefox 52\\firefox.exe");
WebDriver driver = new FirefoxDriver(foptions);
To use an existing Firefox Profile for your Test Execution first you have to create a Firefox Profile manually following the instructions at Creating a new Firefox profile on Windows. Now you have to pass the Firefox Profile to a FirefoxOptions class object. Additionally as you would be using the Legacy Firefox Browser
you have to set marionatte to false through a DesiredCapabilities class object which you need to merge() into the FirefoxOptions class object as follows :
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("debanjan");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(testprofile);
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("marionatte", false);
options.merge(dc);
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.com");
Update
I am not sure about your usecase and why you want to use Legacy Firefox Driver. But as per the GitHub discussion Unable to Start Firefox Using the Legacy Driver on a 3.5.3 Grid #jimevans clearly mentions :
The legacy Firefox driver won't work with Firefox 53 or so. You might get the browser to launch, but the language bindings will be entirely unable to communicate with the driver (because Firefox will refuse to load the browser extension that is the legacy Firefox driver).
#barancev also mentions :
A binding should not pass OSS capabilities in W3C-compliant parts of payload, in "capabilities" block. They are allowed in "desiredCapabilities" block only. Perhaps, Mozilla broke Selenium compatibility in Firefox 48 in release channel, but restored it in version 52 in esr channel. It was unexpected, but it's true.
It's all upto you to take a informed descission.
I need to set my Browser's proxy with Automatic Proxy configuration URL as shown in the screenshot below.
I am trying to achieve this using Selenium and Browserstack as test environment.
Set the proxy as shown below.
Proxy proxy = new Proxy();
proxy.setProxyAutoconfigUrl("http://pokgsa.ibm.com/gsa/pokgsa/home/j/m/jmit/web/public/proxy.pac");
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(CapabilityType.PROXY, proxy);
caps.setCapability("browser", "Chrome");
caps.setCapability("browser_version", "63.0");
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "7");
caps.setCapability("resolution", "1366x768");
Tried to set the proxy configuration locally and it works however it does not work on browserstack. I think the proxy is not getting set on the virtual browser.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 2);
profile.setPreference("network.proxy.autoconfig_url", "http://pokgsa.ibm.com/gsa/pokgsa/home/j/m/jmit/web/public/proxy.pac");
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
You need to pass the pac file details using Firefox profile.
Similarly for chrome, you may refer the following link: https://github.com/SeleniumHQ/docker-selenium/wiki/Corporate-Proxies#setting-a-proxy-for-running-chrome
Also please ensure proxies in the pac file do not need machine based authentication/entries since this may not work as your proxies would be required to be authenticated on all browserstack IPs
This is my java code below. I use firefox profile settings. The problem is, I try to click a button, but the firefox tracking protection prevent the click. I tried to disable tracking protection, but if I turn off tracking protection mode, when the selenium driver open the browser, the browser forget my settings. I don't know why, and it's very annoying. How can I solve this problem?
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("permissions.default.stylesheet", 2);
profile.setPreference("permissions.default.image", 2);
System.setProperty("webdriver.gecko.driver", "F:\\path\\geckodriver.exe");
driver = new FirefoxDriver(profile);
You can use
FirefoxProfile profile = new FirefoxProfile();
profile .setPreference("browser.private.browsing.autostart", false)
profile.setPreference("permissions.default.stylesheet", 2);
profile.setPreference("permissions.default.image", 2);
System.setProperty("webdriver.gecko.driver", "F:\\path\\geckodriver.exe");
driver = new FirefoxDriver(profile);
I have updated the web driver to selenium 3.0.1
When i use firefox browser and try to open the https website I get Your connection is not secure exception.
With selenium 2.53.1 web driver below code was working fine.
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("acceptSslCerts", "true");
driver = new RemoteWebDriver(new URL(hubUrl), caps);
As selenium 3.0.1 uses marionette to run latest firefox browsers i tried below 2 code. but both did work
1.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("acceptSslCerts", "true");
caps = DesiredCapabilities.firefox();
caps.setCapability("marionette", true);
caps.setCapability(FirefoxDriver.PROFILE, profile);
driver = new RemoteWebDriver(new URL(hubUrl), caps);
2.
caps = DesiredCapabilities.firefox();
caps.setCapability("marionette", true);
caps.setCapability("acceptSslCerts", "true")
driver = new RemoteWebDriver(new URL(hubUrl), caps);
Here is the screenshot
Anyone tried to access https websites using seleniumGrid/selenium 3.0/marionette
Can someone point-out how to overcome this issue. I have multiple selenium grids with 20+nodes. Installing the certificate on each is not feasible. I this we need a proper solution to this when used.
Thanks
Shankar KC