How to share same Webdriver with different Step Definitions in Cucumber

0
0

I am new to Cucumber and I want to use same Webdriver in different Step Definitions. Below is my code

public class ContextSteps {

private static boolean initialized = false;

private WebDriver driver;

@Before
public void setUp() throws Exception {
if (!initialized) {
// initialize the driver
System.setProperty("webdriver.chrome.driver", GlobalVariables.browserfilepath+"chromedriver.exe");
driver =new ChromeDriver();
driver.manage().window().maximize();
initialized = true;
}
}

public WebDriver getDriver() {
return driver;
}
}

Calling of above class in Step Definition as

private ContextSteps contextSteps;
// PicoContainer injects class ContextSteps
public LoginToApplication (ContextSteps contextSteps) {
this.contextSteps = contextSteps;
}
@Given("^User should have access to Cadence$")
public void Open_the_Browser() throws Throwable
{
WebDriver driver =contextSteps.getDriver();
}

I am getting “java.lang.NullPointerException”

  • You must to post comments
Showing 0 results
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website