Question: Our system under test is a GUI application.
It appears beneficial to have test cases isolated, i.e. their execution does not depend on each other. For example, a later test case should not rely on objects created in a prior test case. By isolating them, there are no implicit dependencies and it becomes easier to maintain them (rearrange them, rewrite them, etc.).

The following options to implement isolation come to my mind:

* objects created during a test case are deleted explicitly at the end of it; global settings that were changed are restored to their defaults explicitly
* restart the SUT and reset it to its defaults by deleting the application's data store (e.g. directory in Windows' %appdata%)
* if your application allows the import of settings, import a defined settings file (e.g. the defaults after installation) at the beginning of a test case

Are there other options? Do you know of any literature? Or is isolation not so important, or even undesireable?

Answer: 
The problem seems to be in the declaration and usage of the variable `driver`. Although there is a **class-scope** variable `driver`, the `Login()` method stores the created `WebDriver` object in a **method-scope** variable. This means, that the class-scope variable `driver` is never set, resulting in NullPointerException when it is referenced.

To fix this, change the beginning of the `Login()` method:

```
//Launch Browser
driver = new ChromeDriver();

```
this worked for me too i declared driver outside of the method and again in method that why it through me nullpointer exception after removing duplicate element it worked for me.

package TestNGPackage;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;

public class BasicTestNG {

WebDriver driver;

```
@BeforeMethod

```

public void setup() throws InterruptedException
{
 System.setProperty("webdriver.chrome.driver", "Tools/chromedriver.exe");
 driver= new ChromeDriver();
 driver.get("<https://www.google.com/>");
 Thread.sleep(1000);
 driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
}

```
@Test
public void mytest()
{
    String S1= driver.getTitle();
    System.out.println("Title of page"+ S1);
}
@AfterMethod
public void teardown()
{
    driver.close();;
    //driver.manage().deleteAllCookies();

}

```

}