title: How to handle multiple step definition file in Cucumber with Selenium
body: <p>I have two step definition files and in future, there will be multiple, I am unable to execute my code for logout, its working fine for login and one step definition file, and it continuously open chrome browser.</p>
  
  <p>I have created a framework using page factory, below is my code:</p>
  
  <p>Login Page: </p>
  
  <pre><code>public class LoginPage {
  
      WebDriver driver;
  
      public LoginPage(WebDriver driver) {
          //this.driver=driver;
          PageFactory.initElements(driver, this);
  
      }
  
      @FindBy(how=How.ID,using="username")
      public WebElement usernametexbox;
  
      @FindBy(how=How.ID,using="pass")
      public WebElement passwordtextbox;
  
      @FindBy(how=How.ID,using="submit")
      public WebElement signin;
  
      @FindBy(how=How.XPATH,using="//button[@class='btn']")
      public WebElement acceptbutton;
  
     public void enter_username(String username) {
  
      usernametexbox.clear();
      usernametexbox.sendKeys(username);
      usernametexbox.getText();
      }
  
      public void enter_password(String password) {
  
          passwordtextbox.clear();
          passwordtextbox.sendKeys(password);
      }
  
      public void clickToSigninbutton() {
          signin.click();
      }
  
      public void clickToAcceptbutton() {
  
  
      acceptbutton.click();
  
      }
  
  public void fill_LoginDetails() {
  
      enter_username("abc");
      enter_password("def45");
  
    }
  
  }
  </code></pre>
  
  <p>Logout Page: </p>
  
  <pre><code>public class LogoutPage {
  
      WebDriver driver;
  
      public LogoutPage(WebDriver driver) {
          //this.driver=driver;
          PageFactory.initElements(driver, this);
  
      }
  
      @FindBy(how=How.XPATH,using="//*[@class='icon']")
      public WebElement chevron;
  
      @FindBy(how=How.XPATH,using="//a[@class='logout-link']")
      public WebElement logoutlink;
  
      public void clickTochevron() {
          chevron.click();
      }
  
      public void clickToLogoutLink() {
  
  
          link.click();
      }
  }
  </code></pre>
  
  <p>Property file reader:</p>
  
  <pre><code>public class PropertiesFileReader {
  
      public Properties getproperty() throws IOException {
      FileInputStream inputstream=null;
      Properties properties=new Properties();
      try {
          properties.load(new FileInputStream("resources/config.properties"));
      }catch(Exception e) {
          System.out.println("Exception " +e);
      }
  
          return properties;
      }
  }
  </code></pre>
  
  <p>Browser utility:</p>
  
  <pre><code>public class BrowserUtility {
  
      public static WebDriver openBrowser(WebDriver driver, String browserName, String url) throws InterruptedException {
  
          if(browserName.equals("chrome")) {
  
              System.setProperty("webdriver.chrome.driver", "D:\\chromedriver\\chromedriver.exe");
              driver=new ChromeDriver();
              driver.manage().window().maximize();
              driver.get(url);
              driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
              return driver;
  
          }else if(browserName.equals("IE")) {
          System.setProperty("webdriver.chrome.driver", "D:\\chromedriver\\chromedriver.exe");
          driver=new ChromeDriver();
          driver.manage().window().maximize();
          driver.get(url);
          Thread.sleep(5000); 
          return driver;
      }else if(browserName.equals("Firefox")) {
          System.setProperty("webdriver.chrome.driver", "D:\\chromedriver\\chromedriver.exe");
          driver=new ChromeDriver();
          driver.manage().window().maximize();
          driver.get(url);
          Thread.sleep(5000); 
          return driver;
      }
          return driver;
  
  }
  }
  </code></pre>
  
  <p>Login Stepdef:</p>
  
  <pre><code>public class StepDefinition {
  
      public static WebDriver driver;
  
  //  public LoginPage loginpage;
  
  //  Properties properties=new Properties();
      PropertiesFileReader obj=new PropertiesFileReader();
  
      @Given("^Open browser and enter url$")
      public void open_browser_and_enter_url() throws Throwable {
  
      Properties properties=obj.getproperty();
      driver= BrowserUtility.openBrowser(driver, properties.getProperty("browser.Name"), properties.getProperty("URL"));
  
      }
  
      @Then("^Enter username and password$")
      public void enter_username_and_password() throws Throwable {
  
      LoginPage loginpage=new LoginPage(driver);
      loginpage.fill_LoginDetails();  
              }
  
      @Then("^click on sign in button$")
      public void click_on_sign_in_button() throws Throwable {
  
          new LoginPage(driver).clickToSigninbutton();
          System.out.println("Sign-In successfully");
  
      }
  
      @Then("^Terms and conditions page open and click on Accept button$")
      public void terms_and_conditions_page_open_and_click_on_Accept_button() throws Throwable {
  
  
          new LoginPage(driver).clickToAcceptbutton();
      }
  
  }
  </code></pre>
  
  <p>Logout stepdef:</p>
  
  <pre><code>public class Logoutstepdef {
  
      public static WebDriver driver;
      PropertiesFileReader obj=new PropertiesFileReader();
  
      @Given("^Chevron near username$")
      public void chevron_near_username() throws Throwable {
  
          Properties properties=obj.getproperty();
          driver= BrowserUtility.openBrowser(driver, 
   properties.getProperty("browser.Name"), properties.getProperty("URL"));
  
          LogoutPage logoutpage=new LogoutPage(driver);
          logoutpage.clickTochevron();
      }
  
      @Then("^click on chevron and it should get expands$")
      public void click_on_chevron_and_it_should_get_expands() throws 
   Throwable {
  
          System.out.println("when user click on checvron it should 
             further expands a window");
  
      }
  
      @Then("^click on Logout link$")
      public void click_on_Logout_link() throws Throwable {
  
          new LogoutPage(driver).clickToLogoutLink();
  
      }
  
  }
  </code></pre>
  
  <p>Expected Results: Application should get automated successfully for different step definition files and only one browser should get opened at a time.</p>
  
  <p>Actual Results: I have two step definition file and in future there will be multiple, I am unable to execute my code for logout, its working fine for login and one step definition file, and it continuously open chrome browser.</p>