My test cases involve export/download the excel files from web pages. For which I am using Firefox profile to accept the downloads when the download dialog popup on windows. The following code is working when I execute my test on local windows.
ProfilesIni profile = new ProfilesIni();
FirefoxProfile fProfile = profile.getProfile("Selenium");
fProfile.setPreference("browser.download.folderList", 2);
fProfile.setPreference("browser.download.manager.showWhenStarting", false);
fProfile.setPreference("browser.download.dir", "C:\\temp\\reports\\");
fProfile.setPreference("browser.helperApps.neverAsk.openFile", "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
fProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
fProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
fProfile.setPreference("browser.download.manager.alertOnEXEOpen", false);
fProfile.setPreference("browser.download.manager.focusWhenStarting", false);
fProfile.setPreference("browser.download.manager.useWindow", false);
fProfile.setPreference("browser.download.manager.showAlertOnComplete", false);
fProfile.setPreference("browser.download.manager.closeWhenDone", false);
fProfile.setAcceptUntrustedCertificates(true);
fProfile.setAssumeUntrustedCertificateIssuer(true);
fProfile.setPreference("security.insecure_field_warning.contextual.enabled", false);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, fProfile);
capabilities.setCapability("marionette", true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setAcceptInsecureCerts(true);
driver = new FirefoxDriver(capabilities);
I want to run the tests on Jenkins and I have been running into the issues. I receive Nullpointer exception on the line right after I initialize the firefox profile. Which means the firefox profile did not pickup. Following is the error.
I am wondering if Jenkins is not understanding the firefox profile "Selenium" which I created through Firefox Profile section.
Note: I can run my tests from the windows command line but not through the Jenkins.
Any help is highly appreciated.
Instead of using capabilities, use FirefoxOptions
FirefoxOptions options = new FirefoxOptions();
options.addArgument("--headless");
WebDriver driver = new FirefoxDriver(options);
Related
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
ProfilesIni profile2 = new ProfilesIni();
FirefoxProfile profile3 = profile2.getProfile("AutoProfile");
profile3.setPreference("browser.popups.showPopupBlocker", false);
profile3.setPreference("browser.download.dir", "D:\\WebDriverDownloads");
profile3.setPreference("browser.download.folderList", 2);
profile3.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;");
profile3.setPreference( "browser.download.manager.showWhenStarting", false );
profile3.setPreference( "pdfjs.disabled", true );
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(profile3);
WebDriver driver = new FirefoxDriver(firefoxOptions);
The most probhable reason you are seeing a java.lang.NullPointerException is because the Firefox Profile which you are trying to use i.e. AutoProfile doesn't exist (yet to be created) on your local system.
Solution
Before you start using the Firefox Profile AutoProfile ensure that this Firefox Profile exists in your local system. You can create a Firefox Profile manually following the instructions at Creating a new Firefox profile on Windows.
To configure auto downloads setPreference("browser.popups.showPopupBlocker", false) is not required so you can remove it.
Execute your #Test.
Here you can find a detailed discussion on how to use a new/existing Firefox Profile for your tests
I'm trying to use webdrivermanager library to load firefox driver in my selenium tests. I'm unable to load a specific firefox profile using this library. Here is what i'm trying to do:
FirefoxDriverManager.getInstance().setup() // To instantiate the firefox driver
ProfilesIni Prof = new ProfilesIni();
FirefoxProfile profile = Prof.getProfile("C:\\Users\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\6xv9ndwh.SELENIUM");
WebDriver driver = new FirefoxDriver(profile);
But this instantiates a new driver and does not force the driver instantiated by firefoxdrivermanager to use the specific profile.
I tried using default gecko driver too that does not load the profile either. Here is the code that i'm trying:
System.setProperty("webdriver.gecko.driver", "C:\\geckodriver\\geckodriver-v0.20.0-win64\\geckodriver.exe");
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile Profile = allProfiles.getProfile('default');
Profile.setAcceptUntrustedCertificates(true);
Profile.setAssumeUntrustedCertificateIssuer(false);
driver = new FirefoxDriver(Profile);
Can someone help me on this please?
First of all create a new firefox profile
steps for it are
1. Run this command firefox.exe -p in run window
It will show this dialog box create profile with new name and exit the window.
After that perform this command in webdriver
System.setProperty("webdriver.firefox.marionette", "Path to the exe of firefox driver");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("UrProfile Name which u created");
WebDriver driver = new FirefoxDriver(myprofile);
driver.get("http://www.google.com");
Hope it may help u...
This worked for me (though not using webdrivermanager) for instantiating webdriver using Gradle:
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
capabilities.setCapability("acceptInsecureCerts", true);
driver = {new FirefoxDriver(capabilities)}
I have a regression pack created in Selenium 2.45.0 that I recently upgraded to Selenium (seleniump-java 3.4.0 and selenium server 3.7.1). Currently I have Firefox ESR v52.3.0 on my system. After upgrading to selenium 3.4.0 window.maximize() is failing with below error -
org.openqa.selenium.WebDriverException: Failed to find width field
If i try to set the dimension by
driver.manage().window().setSize(new Dimension(1920, 1080));
it gives me following error -
org.openqa.selenium.WebDriverException: setWindowRect
I have set path to geckodriver and also set FirefoxProfile with following options,
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.dir", System.getProperty("user.dir") + "\\downloads");
profile.setPreference("browser.helperApps.neverAsk.openFile","text/csv,application/x-msexcel,application/excel,application/x-excel,"
+ "application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv,application/x-msexcel,"
+ "application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);
profile.setPreference("browser.download.manager.useWindow", false);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.closeWhenDone", false);
profile.setPreference("browser.tabs.remote.autostart", false);
profile.setPreference("browser.tabs.remote.autostart.1", false);
profile.setPreference("browser.tabs.remote.autostart.2", false);
profile.setPreference("browser.tabs.remote.force-enable", "false");
Please let me know how to maximize window on Firefox browser v52.3.0.
Many thanks
While working with Selenium 3.x releases the line of code to maximize the Browser Window is :
driver.manage().window().maximize();
As you mentioned of using Firefox ESR v52.3.0 possibly Firefox Browser variants does gets initialized with the Browser Window being maximized. Hence there should be no additional requirement to call driver.manage().window().maximize(); or driver.manage().window().setSize(new Dimension(1920, 1080));.
Web Browsers which are still OSS compliant e.g. Chrome , PhantomJS , etc a couple of them still doesn't opens being maximized. A couple of Chromium issues suggested to use ChromeOptions class to maximize the Web Browser as an alternative as follows :
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
Here you can find a couple of discussions on the same :
driver.manage().window().maximize() issue with ChromeDriver 2.33
Chrome Browser-org.openqa.selenium.WebDriverException: unknown error: cannot get automation extension
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
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.