Udemy REST Assured free

How to launch browser using Selenium with Cucumber

To launch browser in Selenium with Cucumber is same as launching it in Selenium itself. Check below steps:

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("webdriver.chrome.driver", 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()

Video Tutorial: How to launch browser using Cucumber with Selenium