I am running a code in Selenium Grid. I have a class named TestBase as follows and I want to quit all the threads when I click on a button,but when I click on the button a NullpointerException is thrown.
public class TestBase {
protected ThreadLocal<RemoteWebDriver> threadDriver = null;
Button b;
Frame f;
static boolean flag = true;
@BeforeMethod
public void setUp() throws MalformedURLException {
if(flag)
{
JFrame calcFrame = new JFrame();
flag = false;
calcFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button1 = new JButton("1");
button1.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent ae) {closure();}
});
calcFrame.add(button1);
calcFrame.setVisible(true);
}
threadDriver = new ThreadLocal<RemoteWebDriver>();
DesiredCapabilities dc = new DesiredCapabilities();
FirefoxProfile fp = new FirefoxProfile();
dc.setCapability(FirefoxDriver.PROFILE, fp);
dc.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
threadDriver.set(new RemoteWebDriver(new URL("http://192.168.3.7:4444/wd/hub"), dc));
}
public WebDriver getDriver() {
return threadDriver.get();
}
public void closure()
{
getDriver().quit();
}
@AfterMethod
public void closeBrowser() {
// log.info("In closeBrowser...");
getDriver().quit();
}
}
I guess it is not able to find the thread which it has to quit. help please.. :)