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.
Related
I have requirement that everytime i login, it asking security code in webapp. But it will ask only once since browser stored the cookies.but it is asking again and again in selenium webdriver since driver always opening new browser every time.
So i need to use already opened browser in selenium webdriver java. please help me with example code.
Finally i found solution that using google chrome option in java. It stores cookies in your temp file and reusing it everytime.
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("start-maximized");
options.addArguments("user-data-dir=D:/temp/");
capabilities.setCapability("chrome.binary","res/chromedriver.exe");
capabilities.setCapability(ChromeOptions.CAPABILITY,options);
driver1 = new ChromeDriver(capabilities);
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
I'm trying to convert some Selenium tests from FirefoxDriver to MarionetteDriver, but I'm hitting issues regarding PKI. My solution up to now has been to use various Firefox profiles which only have one custom PKI and automatically choose that for login purposes. However, it seems that the MarionetteDriver constructor doesn't have the capability to launch Firefox with a custom profile. How do I fix this?
I got around this in Python by having Python start Firefox before connecting to it with Marionette, but I don't know if Selenium WebDriver has this capability.
You shouldn't use MarionetteDriver. As it states in the documentation:
/**
* An implementation of the {#link WebDriver} interface that drives Firefox using Marionette interface.
*
* #deprecated One should use FirefoxDriver with capability marionette = true or false respectively.
*/
You should start a FirefoxDriver and enable marionette in the desired capabilities.
DesiredCapabilities dc=DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
dc.setCapability(FirefoxDriver.PROFILE, profile);
dc.setCapability("marionette", true);
Webdriver driver = new FirefoxDriver(dc);
I have implemented selenium web-driver with IE in a java web application.
I am using Apache tomcat 6 to run the application.
All the tests are running fine on local machine,but when i am trying to access it with other machine its opening the browser in the server machine and performing the tests.
My requirement is when any client access my application, the tests should run on the client machine, i mean browser should open on the client machine and do the tests.
my current selenium set up
File file = new File("C:/Jar File/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability("ignoreZoomSetting", true);
caps.setCapability("nativeEvents", false);
driver = new InternetExplorerDriver(caps);
Any help will be appreciated, plz let me know if i am not clear.
If you are using selenium grid, use RemoteWebDriver instead of InternetExplorerDriver.
RemoteWebDriver: https://code.google.com/p/selenium/wiki/RemoteWebDriver
Selenium Grid: https://github.com/SeleniumHQ/selenium/wiki/Grid2
If you already registered a node on your hub, which has a registered Internet Explorer, then you can start your tests on it, if you init your WebDriver like this:
DesiredCapabilities dc = new DesiredCapabilities();
dc = DesiredCapabilities.internetExplorer();
dc.setPlatform(org.openqa.selenium.Platform.WINDOWS);
dc.setVersion("any");
WebDriver driver = new RemoteWebDriver(new URL("http://HUB_IP:HUB_PORT/wd/hub), dc);
I am using Selenium and ChromeDriver 2.43.1 with the latest Chrome (Version 42.0.2311.135 at the time the quetion was asked). My web application generates a PDF. It is being sent with the correct MIME type and it also correctly opens in the Chrome PDF viewer. However when I try to open the PDF using Selenium in Chrome that is started by the WebDriver, it gets downloaded.
I believe it might be some settings that Selenium or WebDriver use to start Chrome.
I've tried settings a few switches, but nothing worked yet. My code:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
// Add ChromeDriver-specific capabilities through ChromeOptions.
ChromeOptions options = new ChromeOptions();
options.addArguments("--please-make-it-work"); // not a real switch
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
webDriver = new ChromeDriver(capabilities);
webDriver.get(url);
What I really need is to start the browser in "normal" mode. It doesn't need any profile settings, just the defaults that will open the PDF.
The problem was caused by the recent change to the behaviour of the --test-type switch. It is described in the ChromeDriver issue tracker.
The workaround is to disable this switch. Here's my code changed:
// Add ChromeDriver-specific capabilities through ChromeOptions.
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", Arrays.asList("test-type"));
webDriver = new ChromeDriver(options);
webDriver.get(url);