RemoteWebDriver generate "Secure Connection Failed" with firefox 43 and above - selenium

when I do the following line
driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), oCapabilities, TimeSpan.FromSeconds(timeout));
Firefox generate the error "Secure Connection Failed". I'm guessing the proxy is blocked, how can I prevent it?
I'm following this page without success:
http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp

1-) Had to update selenium drivers.
2-) Also that firefox was always opening as if it was the first use. to prevent this:
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("browser.startup.homepage_override.mstone", "ignore");
DesiredCapabilities capabilities = DesiredCapabilities.Firefox();
capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile.ToBase64String()); // profile MUST be converted to this type
driver = new RemoteWebDriver(new Uri(remoteAddress), capabilities, TimeSpan.FromSeconds(timeout));

Related

selenium RemoteWebDriver opens but ChromeOptions are not passed to Selenium Grid

I have been trying to resolve a few issues with RemoteWebDriver and ChromeOptions using docker and selenium grid. The main issue is with the proxy but I half resolved that with a proxy pac file passing the pac file url as an arg into ChromeOptions. The below code runs great in docker debug and standalone locally but as soon as I try with the grid or deploy and run with bamboo the driver opens and I can see that ChromeOptions are not being passed because the poxy pac file is not being used and it's just frozen at org.openqa.selenium.remote.ProtocolHandshake createSession. I have been researching for a few weeks now and I am at a hard blocker with this now. I have seen some posts that DesiredCapabilities is deprecated but I have not found a way to implement ChromeOptions without it.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--disable-infobars");
options.addArguments("--proxy-pac-url= http://ProxyPacURL.com");
DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setCapability(ChromeOptions.CAPABILITY, options);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc);
Update to latest Selenium Jars, make sure your java is version 1.8 or greater, then you can pass ChromeOptions into the driver because DesiredCapabilities is deprecated. I am now able to run selenium docker nodes with selenium grid and all ChromeOptions arguments are now being passed to the containers.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--disable-infobars");
options.addArguments("--proxy-pac-url=http://myPacFile.com");
options.addArguments("--no-sandbox");
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);
I was facing same issue and I have found the solution as below:
We need to set "goog:chromeOptions" instead of "chromeOptions".
In your Java code, following line is present:
dc.setCapability(ChromeOptions.CAPABILITY, options);
If you navigate to ChromeOptions.CAPABILITY, you will notice that it is a constant with value "chromeOptions". This works fine for local web driver, but not for remote web driver (i.e. selenium grid).
Just change above line to this:
dc.setCapability("goog:chromeOptions", options);
Now when you execute your Java code, it will work fine and all your options will show their effect too.
I came across other pages, such as this, which referred to above solution.
Try this:
const GRID_HOST = 'http://localhost:4444/wd/hub';
var options = new chrome.Options();
options.addArguments("--start-maximized");
options.addArguments("--disable-infobars");
options.addArguments("--proxy-pac-url=http://myPacFile.com");
options.addArguments("--no-sandbox");
driver = new webdriver.Builder()
.usingServer(GRID_HOST)
.forBrowser("chrome")
.setChromeOptions(options)
.build()

How to accept Insecure Connection error in Firefox c#

I wrote the below code but it doesn't work in Firefox 53.0, Selenium 3.3.1
DesiredCapabilities opt= DesiredCapabilities.Firefox();
opt.SetCapability("acceptInsecureCerts", true);
opt.SetCapability("marionette", true);
driver = new FirefoxDriver(opt);
If your are using Java and the issue is with SSL Certificate, you need to add ACCEPT_SSL_CERTS as true to the DesiredCapabilities. The following code will solve your issue:
System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe");
DesiredCapabilities cap= new DesiredCapabilities();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new FirefoxDriver(cap);
driver.get("http://www.your_url.org/");
Let me know if this helps you.
Best way to handle SSL error in Firefox browser is to accept untrusted certificate:
ProfilesIni prof = new ProfilesIni();
FirefoxProfile ffProfile= prof.getProfile("myProfile");
ffProfile.setAcceptUntrustedCertificates(true);
ffProfile.setAssumeUntrustedCertificateIssuer(false);
WebDriver driver = new FirefoxDriver(ffProfile);
For details on other browsers:
http://www.guru99.com/ssl-certificate-error-handling-selenium.html#6

Disable Google Chrome password bubble for WebDriver tests

Given the following code snippet:
case "CHROME":
System.setProperty("webdriver.chrome.driver", DriverPaths.CHROMEPATH);
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
options.addArguments("--disable-notifications");
options.addArguments("--start-maximized");
options.addArguments("--disable-web-security");
options.addArguments("--no-proxy-server");
options.addArguments("--enable-automation");
options.addArguments("--disable-save-password-bubble");
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
return new ChromeDriver();
Why am I still seeing:
And:
Any ideas?
You will have to use the following commands:
options is your chrome options.
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
By passing the capabilities to the chrome driver they will be loaded into chrome.
The DesiredCapabilities.chrome(); will select the correct browser, in this case Chrome.
Chrome asks for the password when your account is set for autologin.
Doing this makes it so that the keyring doesn't load when you
reset/reboot your system.
Chrome is asking for the password to the keyring so it can access
stored information in the keyring. You can view the keyring on your
system by running the command seahorse from a terminal window. You can
also just bypass the asking by closing the window and still get to
your sites without a problem. Some of the security may not load
properly.
However, you can use the following command from a terminal window to
bypass the keyring asking:
google-chrome-stable --password-store=basic
Hope this helps!
YOU CAN SET IT FOR YOUR CHROME LAUNCHER TOO
Courtesy of #Terrance

Browser Plugin Testing With Selenium

I am writing a webapp that has a browser plugin component for both firefox and chrome. My current testing system uses a series of Selenium tests created through Selenium IDE.
Is it possible to also have selenium install, activate, and delete browser plugins for firefox and chrome (possibly other browsers as well)?
I think the biggest concern is that installing/enabling the browser plugin requires a browser restart, and I'm not sure if that would through selenium off.
The acquisition of the plugin is easily handled by visiting an internal site-link to a php-script that detects your browser.
The answer is Yes, Selenium 2 supports (remote) installation of browser extensions.
The Chrome and Firefox WebDriver support the installation of extensions, remotely. Here's sample code for Chrome and Firefox:
Chrome
File file = new File("extension.crx"); // zip files are also accepted
ChromeOptions options = new ChromeOptions();
options.addExtensions(file);
// Option 1: Locally.
WebDriver driver = new ChromeDriver(options);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Firefox
File file = new File("extension.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
// Option 1: Locally
WebDriver driver = new FirefoxDriver(firefoxProfile);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
I have also implemented automated installation of Opera and Safari extensions, and they have been merged upstream:
OperaDriver: https://github.com/operasoftware/operadriver/pull/93
SafariDriver: https://github.com/SeleniumHQ/selenium/pull/87
Opera
This API is similar to the FirefoxDriver.
File file = new File("extension.oex"); // Must end with ".oex"
OperaProfile operaProfile = new OperaProfile();
operaProfile.addExtension(file);
// Option 1: Locally
WebDriver driver = new OperaDriver(operaProfile);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setCapability("opera.profile", operaProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Safari
This API is similar to the ChromeDriver.
File file = new File("extension.safariextz");
SafariOptions options = new SafariOptions();
options.addExtensions(file);
// Option 1: Locally.
WebDriver driver = new SafariDriver(options);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.safari();
capabilities.setCapability(SafariOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Internet Explorer
Good luck.
Short answer: no
Installing a browser extension is outside of the scope of handling in Selenium.
In Chrome, it displays a modal window that is not "clickable" with Selenium when you want to add a plugin or app. Chrome does not require restarting.
Firefox has the same kind of behaviour to prompt for extension permissions.
You can try something that resides outside of the browser to do what you want. Sikuli might do the trick.

Using Selenium to test Safari gives GridException

I am using the code from this site (http://darrellgrainger.blogspot.com/2011/02/using-selenium-20-with-webdriver-and.html) to run Selenium tests in Safari 5. The code goes like this:
Selenium sel = new DefaultSelenium("localhost", 4444, "*safari", baseURL);
CommandExecutor executor = new SeleneseCommandExecutor(sel);
DesiredCapabilities dc = new DesiredCapabilities();
WebDriver browser = new RemoteWebDriver(executor, dc);
browser.get("http://www.google.com");
WebElement input = browser.findElement(By.name("q"));
input.sendKeys("Selenium");
So I start a Selenium server standalone version on the localhost machine and I register a test node (also on localhost) to the Selenium hub. Then I start the test. I then get the following exception: org.openqa.selenium.WebDriverException: Could not start Selenium session: org%2Eopenqa%2Egrid%2Ecommon%2Eexception%2EGridException%3A+Error+forwarding+the+new+session+The+server+returned+an+error+%3A+
I don't know what error. There is no server output on the console. Does anyone have ideas? I used the newest version (2.17.0) of Selenium.
EDIT: I just tried "firefox" instead of safari and it outputs the same exception. So actually it's not the fault of safari. Maybe there is something wrong with executing Selenium 1 code via the grid?
Try This:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("safari");
capabilities.setJavascriptEnabled(true);
CommandExecutor executor = new SeleneseCommandExecutor(new URL("http://localhost:5555/"), new URL("http://www.google.com/"), capabilities);
WebDriver driver = new RemoteWebDriver(executor, capabilities);
driver.get("http://google.com");
Don't create DefaultSelenium object. The above code works well for me with Safari browser.