learning BDD cucumber Framework project and trying to run this code in Junit 4 and getting this error. getting failed at line 31 and then all other test is going skipped code
2 Answers
You have declared 'driver' variable 2 times, at line number 15 and at line number 22. Line number 15's 'driver' has access at class level and line number 22's 'driver' has access only at method level. At line number 30, the 'driver' used is class variable which has not been instantiated. Simple solution to make it work is use only one driver variable.
Change the code at line number 22 as below:
driver = new FirefoxDriver();
Good luck, try this and if it solves your issue, upvote and accept the answer.

- 4,064
- 2
- 11
- 23
You have got one instance of WebDriver at class level as:
WebDriver driver;
and another instance of Firefox driver at method level as:
FirefoxDriver driver = new FirefoxDriver();
initialized in your program by the same name.
Hence you see the error.
Solution
An ideal solution would be to use the same driver
variable created from WebDriver at class level, which can be accesed from any method. So effectively you have to:
driver = new FirefoxDriver();

- 183,867
- 41
- 278
- 352