I use maven CLI cmd to provide the BROWSER value in real-time while execution
mvn -DBROWSER=firefox install
and I use the below snippet to automatically fetch the BROWSER value as firefox
from terminal cmd; but, when I try to match the condition with manual String value, browser=="firefox"
, it fails to match and returns to else part.
String browser = System.getProperty("BROWSER");
if(browser=="chrome")
{
System.out.println("CHROME initiated");
System.setProperty("webdriver.chrome.driver", "./libs/chromedriver");
driver = new ChromeDriver();
} else if (browser=="firefox") {
System.out.println("FIREFOX initiated");
System.setProperty("webdriver.gecko.driver", "./libs/geckodriver");
driver = new FirefoxDriver();
} else {
System.out.println("Skipped and CHROME initiated");
System.setProperty("webdriver.chrome.driver", "./libs/chromedriver");
driver = new ChromeDriver();
}
However, I want the test to move into else if (browser=="firefox")
part matching browser=="firefox"
. Is this due to the format issue; I have also used .toString()
but it didnt work for me.