Unable to add desired capabilities for remote web driver - selenium

I am unable to compile my code when I try to add the following to enable selenium node on my machine.
URL hubUrl = new URL("");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("firefox");
capabilities.setPlatform(Platform.LINUX);
RemoteWebDriver driver = new RemoteWebDriver(hubUrl, capabilities);

probably you forgot to add the Hub url.
Try this:
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
or another variant:
URL hubUrl = new URL("http://hubIP:hubPort/wd/hub");
DesiredCapabilities capability = DesiredCapabilities.firefox();
capabilities.setPlatform(Platform.LINUX);
RemoteWebDriver driver = new RemoteWebDriver(hubUrl, capabilities);

Related

How to handle untrusted certificate in firefox using Selenium Web Driver?

I'm facing some issues while handling "Untrusted Certificate" in firefox.
We can't use FirefoxDriver(new FirefoxProfile) as it is deprecated
I used the following code but couldn't achieve it.
FirefoxProfile profile=new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
FirefoxOptions options=new FirefoxOptions().setProfile(new FirefoxProfile());
WebDriver driver=new FirefoxDriver(options);
driver.get("Web Link");
Could anyone suggest me the solution to achieve in Selenium 3.
Try this in Firefox
DesiredCapabilities handlSSLErr = DesiredCapabilities.firefox ();
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new FirefoxDriver (handlSSLErr);
driver.get("Your URL link");
For chrome
DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome ();
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new ChromeDriver (handlSSLErr);
driver.get("Your URL link");
Below works fine for me
DesiredCapabilities cap = new DesiredCapabilities().merge(DesiredCapabilities.firefox());
cap.acceptInsecureCerts();
FirefoxDriver driverF = new FirefoxDriver(cap);
driverF.get("https://expired.badssl.com/");

Selenium Grid test Error

I have a hub with 2 nodes. My tests are not running with the error
Unable to cast object of type 'System.String' to type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]
This is my tests and my browser...
DesiredCapabilities capabilities = DesiredCapabilities.Chrome();
ChromeOptions options = new ChromeOptions();
options.AddArguments("test-type");
options.BinaryLocation = #"C:\Users\ebrahimpour.l\Documents\Visual Studio 2015\Projects\FirstPackage\FirstPackage\bin\Debug\chro‌​medriver.exe";
capabilities.SetCapability("chrome.binary", #"C:\Users\ebrahimpour.l\Documents\Visual Studio 2015\Projects\FirstPackage\FirstPackage\bin\Debug\chro‌​medriver.exe");
capabilities.SetCapability(ChromeOptions.Capability, options);
System.Environment.SetEnvironmentVariable("webdriver.chrome.‌​driver",
#"C:\Users\ebrahimpour.l\Documents\Visual Studio 2015\Projects\FirstPackage\FirstPackage\bin\Debug\chro‌​medriver.exe");
driver = new ChromeDriver(#"C:\Users\ebrahimpour.l\Documents\Visual Studio 2015\Projects\FirstPackage\FirstPackage\bin\Debug");
capabilities.SetCapability(capabilities.Platform.ProtocolPlatformType, "WebDriver");
capabilities.SetCapability(CapabilityType.BrowserName, "chrome");
capabilities.SetCapability(capabilities.Version, "57");
capabilities.SetCapability(CapabilityType.Platform, "WinNT");
capabilities.SetCapability(ChromeOptions.Capability, options);
RemoteWebDriver rw = new RemoteWebDriver(new Uri("http://localhost:4444/grid/console"), capabilities);
driver = rw;
baseURL = "http://192.168.10.173:8080/";
verificationErrors = new StringBuilder();
Change
RemoteWebDriver rw = new RemoteWebDriver(newUri("**http://localhost:4444/grid/console**"), capabilities);
to
http://localhost:**8888**/**wd/hub**

Migrating from Firefox WebDriver to Marionette

I am trying to switch from FireFoxDriver to MarionetteDriver.
I managed to run firefox with MarionetteDriver by running:
public void runMarionnete(){
DesiredCapabilities dc = DesiredCapabilities.firefox();
OSUtils.setProperty("webdriver.firefox.bin", "C:\\Firefox\\firefox.exe");
OSUtils.setProperty("webdriver.gecko.driver","C:\\Drivers\\wires-0.6.2-win.exe"));
_driver = new MarionetteDriver(dc);
}
But I have 2 things I am not sure how to do:
1.How to add XPI extensions to the driver ?
in the old way I used:
FirefoxProfile.addExtension ...
2.How to configure all the firefox properties , like I used to do , for example:
profile.setPreference("browser.startup.homepage;about:home","about:blank");
profile.setPreference("startup.homepage_welcome_url","about:blank");
profile.setPreference("browser.usedOnWindows10.introURL","about:blank");
profile.setPreference("devtools.devedition.promo.url","");
profile.setPreference("xpinstall.signatures.required",false);
Thank you!
You can use the same FirefoxProfile class, just add it to the DesiredCapabilities in the following way:
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.startup.homepage;about:home","about:blank");
firefoxProfile.setPreference("startup.homepage_welcome_url","about:blank");
firefoxProfile.setPreference("browser.usedOnWindows10.introURL","about:blank");
firefoxProfile.setPreference("devtools.devedition.promo.url","");
firefoxProfile.setPreference("xpinstall.signatures.required",false);
DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
desiredCapabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);

getting error with chromedriver using RemoteWebdriver

Getting error:
FAILED CONFIGURATION: #BeforeMethod setUp
org.openqa.selenium.WebDriverException: The path to the driver
executable must be set by the webdriver.chrome.driver system property;
for more information, see
http://code.google.com/p/selenium/wiki/ChromeDriver. The latest
version can be downloaded from
http://chromedriver.storage.googleapis.com/index.html
My code :
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
String strChromePath = System.getProperty("user.dir")
+ "\\webdrivers\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", strChromePath);
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
capability);
On the above code chromedriver it self is not getting invoked.
Then i tried with code:
ChromeDriverService chromeService = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("webdrivers/chromedriver.exe"))
.usingAnyFreePort().build();
chromeService.start();
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
capability);
On executing above code the executable is launched but chrome is not invoked. It throws the same error. Code is working fine for firefox. Any help please?
Download the relevant Chrome driver as per your system(32-bit/64-bit), from here . Try setting the property of ChromeDriver first, like this:
File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
Then use this code:-
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
WebDriver driver = new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),capability);
If there is no need of using "RemoteWebDriver", you can code just use this below :
File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
WebDriver driver = new ChromeDriver();
Try below :
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "properties/chromedriver.exe");
driver = new ChromeDriver();
driver.get("www.google.com");
Put chrome driver in properties folder.

RemoteWebDriver Chrome - start maximized

I need chrome to start maximized when running via the selenium grid.
This is how do I initialize it now:
Selenium selenium = new DefaultSelenium("localhost", 4444, "*googlechrome", "http://www.google.com");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Chrome does come up, but not maximized. In usual ChromeDriver I did it like this
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
But I dont know how to pass it to RemoteWebDriver. Can anybody help?
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
That's how I do it.
Ok, I found it, so lets answer my own question :)
Selenium selenium = new DefaultSelenium("localhost", 4444, "*googlechrome", "http://www.google.com");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
should work :}
The above solutions did not work for me but this did
ChromeOptions options = new ChromeOptions();
options.AddArguments("--start-maximized");
DesiredCapabilities capabilities = options.ToCapabilities() as DesiredCapabilities;
capabilities?.SetCapability(CapabilityType.BrowserName, "chrome");
Driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capabilities);
Hope this helps someone.