0

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();
    }

enter image description here enter image description here

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.

Prashanth Sams
  • 19,677
  • 20
  • 102
  • 125
  • That is because you don't compare strings with == in Java; you have to use equals(). And for the record: if you dont know about such basics, you better spend some time studying those basics before getting into such kind of advanced topics. – GhostCat Nov 12 '16 at 10:29
  • Thanks @GhostCat ; I use Javascript tats y confused in this :) – Prashanth Sams Nov 12 '16 at 10:32

0 Answers0