0
import package org.test.launch;
import static junit.framework.Assert.*;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import cucumber.annotation.After;
import cucumber.annotation.Before;
import cucumber.annotation.en.Given;
import cucumber.annotation.en.Then;
import cucumber.annotation.en.When;

public class GoogleSearch {

private WebDriver driver;

@Before
public void setup(){
    driver = new FirefoxDriver();
}

@After
public void teardown(){
    driver.quit();      
}

@Given("^Search for different inputs in google$")
public void OpenGooglePage(){
    driver.get("http://www.google.com.au");
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.findElement(By.id("gbqfq")).sendKeys("Planit");
}

@When("^I search for (.*) in google search$")
public void search(String input){
    WebElement searchfield = driver.findElement(By.id("gbqfq"));
    searchfield.sendKeys(input);
    this.driver.findElement(By.id("gbqfba")).submit();
}

@Then("^I should be able to see (.*) in search results$")
public void result(String output){
    WebElement searchresult = driver.findElement(By.cssSelector(".l"));
    assertEquals(searchresult.getText(), output);
}

}

============
Feature file
============
Feature: Search for string

Scenario: Search

Given Search for any string in google
When I search for stackoverflow in google search
Then I should be able to see stackoverflow in search results

=========
Glue Code
=========

package org.test.launch;

import cucumber.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
public class SearchTest {
}

Only @Given statement is running @When and @Then statement are not executing.

On the Console Output i am able to see following error

java.lang.NullPointerException at ?.When I search for Plan in google search(org\test\launch\GoogleSearch.feature:6)

user1917213
  • 1
  • 1
  • 1

1 Answers1

0

Found the problem:

Issue was with @Given statement.

feature file Given statement and @Given statement in step definition were not same therefore code was not running.

user1917213
  • 1
  • 1
  • 1