How to fix a Deprecation Warning, Firefox ProfilesIni has been deprecated in java

Viewed 244

I want to use my custom Firefox profile and I'm getting a Deprecation Warning on

ProfilesIni myProfile = new ProfilesIni();

@SuppressWarnings. How do I fix this issue.

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.firefox.FirefoxProfile;

//System.setProperty("C:\\driver\\geckodriver.exe");

ProfilesIni myProfile = new ProfilesIni();

FirefoxProfile test = myProfile.getProfile("selenium 1");

WebDriver driver = new FirefoxDriver(test);

driver.manage().window().maximize();

driver.get("https://www.google.com");
2 Answers

Just use the newer class as mentioned in the javadoc:

Deprecated. Use org.openqa.selenium.firefox.ProfilesIni instead.

Instead of org.openqa.selenium.firefox.internal.ProfilesIni use org.openqa.selenium.firefox.ProfilesIni.

Be aware there are two classes named ProfilesIni

org.openqa.selenium.firefox.ProfilesIni
org.openqa.selenium.firefox.internal.ProfilesIni

You can suppress the warning on class:

@SuppressWarnings("deprecation")
public class YourClass {
   ...
}

or on method:

@SuppressWarnings("deprecation")
public void foo() {
   ...
}

@SuppressWarnings("deprecation")
public WebDriver startGeckoDriver() {
   WebDriver driver = ...;
   return driver;
}

or on myProfile:

@SuppressWarnings("deprecation")
ProfilesIni myProfile = new ProfilesIni();

In Eclipse you can add the annotation using the yellow warning icon: on class

on method

Related