Selenium browsermob proxy says "Warning: Potential Security Risk Ahead" - java

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);

Related

Use a proxy with username and password in Selenium

I'm trying to test my web app with different connections and proxies, but i only have authenticated HTTP proxies.
I cannot figure out how to authenticate my proxy before opening the connection.
Proxy proxy = new Proxy();
proxy.setHttpProxy("127.0.0.1:3128");
ChromeOptions options = new ChromeOptions();
options.setCapability("proxy", proxy);
driver = new ChromeDriver(options);
driver.get("https://www.myip.com/");
For the ones that are searching for an answer, i use multipass, chrome extensions filling via selenium the field necessary

PAC file proxy setup using Selenium -Browserstack

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

Getting Your connection is not secure with marionette firefox selenium 3.0 grid

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

Disable system proxy from java

My test script uses Selenium WebDriver with BrowserMob proxy server to simulate slow connection. Starting of the Internet Explorer WebDriver with BrowserMob proxy turns on system proxy. It affects to all connections to the internet (eclipse plugins update, mail corresponding and other apps). Therefore I need to disable system proxy at the end of test script. How to do this from java?
Note: stopping of BrowserMob proxy server doesn't disable system proxy settings.
I found solution in Internet Explorer WebDriver.
There is need to start web driver with IE specific desired capabilities like this:
BrowserMobProxy server = new BrowserMobProxyServer();
server.start();
Proxy proxy = ClientUtil.createSeleniumProxy(server);
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.IE_USE_PRE_PROCESS_PROXY, true);
capabilities.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new InternetExplorerDriver(capabilities);
More info here https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities

How to set multiple proxies in Selenium Webdriver Java

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);

Categories

Resources