Multiple browser windows opening automatically in cucumber


March 2019


1.1k time


I don't know why I am getting 2 firefox browsers opened for the follwoing example. Can some one please tell me what is wrong in below code. I am new to cucumber and I am trying to develop cucumber poc with page object model.

Feature file:

    Scenario: Smoke test for application
      Given I am on home page

Step Defination file:

public class HomePageSteps {

CustomerDetails customerDetails;

HomePage homePage=new HomePage();

public HomePageSteps(CustomerDetails customerDetails){

public void environmentSteup(){

@Given("^I am on home page$")
public void i_am_on_home_page() throws Throwable {

Actual implementation of Step definition file:(

public class HomePage extends BasePage{

public void openURL() {
    System.out.println("I am on home page executed");

public void envSetup() {
    driver=new FirefoxDriver();

public abstract class BasePage {
protected WebDriver driver=new FirefoxDriver();

public class CustomerDetails {
private String mdn=null;

private String Fname=null;

private String Lname=null;

public String getMdn() {
    return mdn;

public void setMdn(String mdn) {
    this.mdn = mdn;

2 firefox browsers are opened: First it opens a blank browser. Later it opens another browser and in this browser it opens the application URL.

2 answers


You have two calls to open browser windows...

Once in the sub-class in envSetup() - driver=new FirefoxDriver();

And in the super class driver variable declaration with initialization - protected WebDriver driver=new FirefoxDriver();

You have to remove one of them, no need for the super class one... This is the one giving you the blank window


Refer to this page. Your maximize() call in envSetup() might be doing more than you think

In selenium webdriver what is manage() [driver.manage()]


You also do not need to instantiate a new FirefoxDriver() outside of BasePage as you have already instantiated a driver field with that object. Anything extending BasePage will have access to that driver field. It is not a problem that you're doing this, it is just extraneous code that doesn't need to be there