NullPointerException while trying to run my tests from testng.xml NullPointerException while trying to run my tests from testng.xml selenium selenium

NullPointerException while trying to run my tests from testng.xml


There are two things-

  1. You are trying to get a browser property using System.getProperty("browser") but you haven't set it anywhere before, so, browser variable will always be null. Please set the property elsewhere first.
  2. You are passing a parameter browser but your setUp() function is not accepting any arguments, and thus your browser variable remains null and gives you the NullPointerException error. You should use it like below
    @Parameters("browser")    @BeforeMethod(alwaysRun = true)    public void setUp(String browser) {        System.out.println("Current browser is " + browser); 

and now your browser variable will have the value which is passed by the testng.xml to your code and should not give the NullPointerException anymore.

If you still facing any issue then I recommend you to please share the stack trace which can be helpful in further debugging.