Skip to main content

Run your first Cucumber TestNG scenario

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.

Submitted by tgoswami on February 17, 2021

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

About

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.