Run your first Cucumber TestNG scenario

Profile picture for user devraj

In previous lecture we have discussed how to integrate Cucumber with TestNG and Selenium, if you have not configured click here to read article. Now it's time to run our first test scenario, for that, let's first create scenario in Login.feature

Feature: Registration, Login and MyAccount 

Background: Login Background 
	Given I am on the home page 
	And I follow "Sign in" link 
	
@SmokeTest
Scenario: Verify Login Functionality 
	When I fill in username with "goswami.tarun777@gmail.com" 
	And I fill in password with "123456" 
	And I click on Sign in button 

Tag your scenario with @SmokeTest or any other tag, Now we need to generate step definitions for that we can use TidyGherkin plugin or you can copy below code.

@Given("^I am on the home page$")
public void i_am_on_the_home_page() throws Throwable 
{
    driver.get("http://www.automationpractice.com");
}

@And("^I follow \"([^\"]*)\" link$")
public void i_follow_something_link(String strArg1) throws Throwable 
{
    driver.findElement(By.linkText("Sign in")).click();
}

@When("^I fill in username with \"([^\"]*)\"$")
public void i_fill_in_username_with_something(String strArg1) throws Throwable 
{
    driver.findElement(By.cssSelector("input[id='email']")).sendKeys("goswami.tarun77@gmail.com");
}

@And("^I fill in password with \"([^\"]*)\"$")
public void i_fill_in_password_with_something(String strArg1) throws Throwable 
{
    driver.findElement(By.cssSelector("input[id='passwd']")).sendKeys("123456");
}

@And("^I click on Sign in button$")
public void i_click_on_sign_in_button() throws Throwable 
{
    driver.findElement(By.cssSelector("button[id='SubmitLogin']")).click();
}

To execute code Run your TestRunner class using TestNG.