unable to launch FireFox custom profile with geckodriver in java - java

I'm trying to launch a Firefox profile with add-ons in it, with selenium v3.12 and gecko-driver v2.10 and Firefox version 60.0, how-ever it seems that the custom profile is not working. below is my code
static WebDriver driver;
ProfilesIni profile = new ProfilesIni();
myprofile = profile.getProfile("AutoProfile");
System.setProperty("webdriver.gecko.driver",
"E:\\Library\\geckodriver-v0.21.0-win32\\geckodriver.exe");
driver = new FirefoxDriver(myprofile);
the acutal error is on the line
driver = new FirefoxDriver(myprofile);
as
The constructor FirefoxDriver(FirefoxProfile) is undefined

You have to pass it through firefox options.
System.setProperty("webdriver.gecko.driver", "E:\\Library\\geckodriver-v0.21.0-win32\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("AutoProfile");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(myprofile);
WebDriver driver = new FirefoxDriver(firefoxOptions);
If the below solution causes a java heap error, you could try DesiredCapabilities, like this:
System.setProperty("webdriver.gecko.driver","E:\\Library\\geckodriver-v0.21.0-win32\\geckodriver.exe");
File file = new File(path_to_your_firefox_profile);
DesiredCapabilities dc = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile(file);
dc.setCapability(FirefoxDriver.PROFILE, profile);
FirefoxDriver driver = new FirefoxDriver(dc);

Related

Unable to execute Headless Geckodriver with TestNG

Since I implemented the Headless configuration on my Test I received this issue: java.lang.NullPointerException
I tried to to switch to other types of implemantation for the Gecko Headless, but none of them worked
#BeforeTest
public static void OpenBrowser () {
System.setProperty("webdriver.gecko.driver","binaries/geckodriver");
FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("-headless");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(firefoxBinary);
FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
driver.get(...
}
Once the test is executed I receive th3 following error: java.lang.NullPointerException
The commands to get it running in headless mode are as follows:
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
WebDriver driver = new FirefoxDriver(options);
You'll probably want to have the WebDriver driver part defined outside the test so that you can perform the following in your #BeforeTest like so:
WebDriver driver;
#BeforeTest
public static void OpenBrowser() {
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
driver = new FirefoxDriver(options);
}

WebDriver to disable SEC_ERROR_UNKNOWN_ISSUER in Firefox

WebDriver opens browser window, but I get SEC_ERROR_UNKNOWN_ISSUER.
I tried to add this site as an exception in browser, but when new browser window opened I get the same message again instead of the website.
FirefoxProfile profile = new FirefoxProfile();
FirefoxOptions options = new FirefoxOptions();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(true);
options.setLogLevel(Level.ALL);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
WebDriver driver = new FirefoxDriver(capabilities);
You need to set setAcceptInsecureCerts Capabilities as true
This simple code work for me :-
System.setProperty("webdriver.gecko.driver", "D:\\Workspace\\StackOverlow\\src\\lib\\geckodriver.exe");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setAcceptInsecureCerts(true);
WebDriver driver = new FirefoxDriver(desiredCapabilities);
driver.get("https://self-signed.badssl.com/");
OR
System.setProperty("webdriver.gecko.driver", "D:\\Workspace\\StackOverlow\\src\\lib\\geckodriver.exe");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("acceptInsecureCerts", true);
WebDriver driver = new FirefoxDriver(desiredCapabilities);
driver.get("https://self-signed.badssl.com/")
Change your gecko path in first line of code. Update gecko driver and firefox

Selenium WebDriver Load both a Capability and Profile

Looking to load both DesiredCapabilities and a FirefoxProfile, can't figure it out and can't find an answer for it
There is the FirefoxDriver.PROFILE capability for RemoteWebDriver.
For example,
FirefoxProfile yourProfile = new FirefoxProfile("path_to_your_profile");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, yourProfile);
Create your firefox profile, i.e: "profileFF"
DesiredCapabilities cap = new DesiredCapabilities();
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("profileFF");
cap.setCapability(FirefoxDriver.PROFILE, myprofile );
OR
DesiredCapabilities cap = new DesiredCapabilities();
File firefoxProfileFolder = new File("/path/to/your/firefox/profile/profileFF");
FirefoxProfile myprofile = new FirefoxProfile(firefoxProfileFolder);
cap.setCapability(FirefoxDriver.PROFILE, myprofile );

How to override useragent in firefox browser on saucelabs

Saucelabs:-
https://saucelabs.com/
Am creating the firefox driver on saucelabs using the following:-
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("version", "5");
capabilities.setCapability("platform", Platform.XP);
// Create the connection to Sauce Labs to run the tests
this.driver = new RemoteWebDriver(
new URL("http://YOUR_USERNAME:YOUR_ACCESS_KEY#ondemand.saucelabs.com:80/wd/hub"),
capabilities);
}
I want to use the mobile user agent using firefox driver. How can i do it.
Have you tried creating a new profile and setting the user agent string on the profile?
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "UA-STRING");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);

How to set Proxy setting for Chrome in Selenium Java

I am able to set proxy settings for Firefox as below.
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setProxyType(ProxyType.MANUAL);
proxy.setHttpProxy(CONFIG.getProperty("hostname"));
proxy.setSslProxy(CONFIG.getProperty("hostname"));
proxy.setFtpProxy(CONFIG.getProperty("hostname"));
proxy.setSocksUsername(CONFIG.getProperty("username"));
proxy.setSocksPassword(CONFIG.getProperty("password"));
FirefoxProfile fp = new FirefoxProfile();
fp.setProxyPreferences(proxy);
driver = new FirefoxDriver(fp);
builder = new Actions(driver);
bckdbrowser = new WebDriverBackedSelenium(driver, ConfigReader.ENVIRONMENT_URL);
But I need to setup for Chrome as well.. Can any one assist me how to do ?
Thanks
Raj
You can try using the DesiredCapabilities class, like this:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--proxy-server=http://user:password#proxy.com:8080"));
WebDriver driver = new ChromeDriver(capabilities);
Try this code:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", ProxyType.AUTODETECT.ordinal());
WebDriver driver = new FirefoxDriver(profile);
here we have one more solution....it's worked for me

Categories

Resources