Skip to main content

Launch browser using Selenium Cucumber

To launch browser in Selenium with Cucumber is same as launching it in Selenium itself.

Steps to Launch a Chrome Browser in Selenium Cucumber

Step 1: Add below code to your Base File or Steps Class File. Here Path for Chrome driver is defined in my Constants.Java file. I have also added code for implicit wait and to maximize browser windows here.

public static WebDriver driver;
public void setDriver()
    System.setProperty("", Constants.MAC_CHROME_DRIVER);  
    driver = new ChromeDriver();  
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

Step 2: Call setDriver() method in @Before hook if you want to open browser before every scenario or you can also call it in open home page step definition directly.

public void bf()
    TestBase tb = new TestBase();

Step 3: Use driver inside steps definitions

@Given("^(?:I am|User is) on the home page$")
public void i_am_on_the_homepage()

Step 4: Quit browser in @after hook, to close browser after every scenario.

public void af()

Submitted by tgoswami on August 29, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.