Its working after making the changes that you mentioned above, but program is getting terminated after every run. Have to call the functions every time in Main method to run the program each time. Can you please help with this

Getting this Exception "java.lang.Exception: Test class should have exactly one public zero-argument constructor" for the above code . Program is running successfully with a run time exception. Can you please look on this.

There are two different ways to execute this code.
1. Using public static void main method.
2. Using @Test annotation using TestNG or JUnit

The solution that I gave you was to use your code with the Main method.

To execute tests using @Test method, you will have to go for different class structure.
e.g. replace your Main method in FirefoxDemo like given below.

public class firefoxDemo {

@Test
public void myTest() {

WebDriver driver = new FirefoxDriver();

LoginPage login = new LoginPage(driver);

CreateTask task = new CreateTask(driver);

try {

login.loginAs();

task.addTask();

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

Now to explain you the exception, you are trying to start a test through a class where you have a constructor that requires a parameter. This will fail as JVM will not be able to initiate a test class. So, you are seeing the above error.

You are right! It will not make any difference or give you any exception. But, there are two reasons to remove it.
1. It will make your code look neater. As unused annotation will drive questions in future.
2. The JVM will have to load those methods as Test methods and map it to TestNG/JUnit tests tree. It does not really affect your performance, but, it's good to not to have them as per coding standards.