Issue: TestRunner with cucumber jvm class getting syntax error

1,466 views
Skip to first unread message

tripti pathak

unread,
Mar 10, 2017, 6:36:43 AM3/10/17
to Cukes


I am new to cucumber and this is first sample I am working on. 

Cucumber set up is done. I ran the cucumberrunner class and feature file was picked and ran gave me the error to add missing implementation.But when I add a class with the detail methods. I get syntax error. Not able to understand the error:

 

Feature file:

Feature: Calculator

 

Scenario: Login

Given user is on home page

When user navigates in home page

And user enters '<Username>' and '<Password>'

Then Message displayed as successful

 

|Username | Password |

| triptitest | sleep345|

 

Cucumber file

import org.junit.runner.RunWith;

 

import cucumber.api.junit.Cucumber;

import cucumber.api.CucumberOptions;

 

@RunWith(Cucumber.class)

@CucumberOptions(

            glue = "stepdefinition"

            ,features = "Feature/calculator.feature"

            )

 

public class cucumberunner {

 

      public static void main(String[] args) {

            // TODO Auto-generated method stub

 

      }

 

}

 

 

POM xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.xxxxxx.bdd</groupId>

  <artifactId>cucumber-test</artifactId>

  <packaging>jar</packaging>

  <version>1.0-SNAPSHOT</version>

  <name>XXXXX</name>

  <url>XXXXX</url>

  <dependencies>

            <dependency>

            <groupId>info.cukes</groupId>

            <artifactId>cucumber-java</artifactId>

            <version>1.2.5</version>

            <scope>test</scope>

        </dependency>

        <dependency>

            <groupId>info.cukes</groupId>

            <artifactId>cucumber-junit</artifactId>

            <version>1.2.5</version>

            <scope>test</scope>

        </dependency>

           

        <dependency>

            <groupId>junit</groupId>

            <artifactId>junit</artifactId>

            <version>4.12</version>

            <scope>test</scope>

        </dependency>   

  </dependencies>

   <build>

        <plugins>

            <plugin>

                <artifactId>

                    maven-compiler-plugin

                </artifactId>

                <version>3.3</version>

                <configuration>

                    <source>1.8</source>

                    <target>1.8</target>

                    <encoding>UTF-8</encoding>

                </configuration>

            </plugin>

        </plugins>

    </build>

</project>

 

 

Testrunner file

package stepdefinition;

 

import cucumber.api.PendingException;

import cucumber.api.java.en.Given;

import cucumber.api.java.en.*;

 

public class stepdefinition_test {

 

      public static void main(String[] args) {

           

            @Given("^user is on home page$")

            public void user_is_on_home_page() throws Throwable {

                // Write code here that turns the phrase above into concrete actions

                throw new PendingException();

            }

 

            @When("^user navigates in home page$")

            public void user_navigates_in_home_page() throws Throwable {

                // Write code here that turns the phrase above into concrete actions

                throw new PendingException();

            }

 

            @When("^user enters '<Username>' and '<Password>'$")

            public void user_enters_Username_and_Password() throws Throwable {

                // Write code here that turns the phrase above into concrete actions

                throw new PendingException();

            }

 

            @Then("^Message displayed as successful$")

            public void message_displayed_as_successful() throws Throwable {

                // Write code here that turns the phrase above into concrete actions

                // For automatic transformation, change DataTable to one of

                // List<YourType>, List<List<E>>, List<Map<K,V>> or Map<K,V>.

                // E,K,V must be a scalar (String, Integer, Date, enum etc)

                throw new PendingException();

            }

 

      }

 

}

 

Thomas Sundberg

unread,
Mar 10, 2017, 10:51:00 AM3/10/17
to Cukes
Hi!

I don't see any reference to an error message in your mail.

But I do see a main method in the class annotated @RunWith(Cucumber.class)
The Cucumber runner will fail if the runner class has any methods
implemented. This may the problem you are facing.

The idea behind this behaviour is that you should separate your steps
from the test class running Cucumber. This is implemented in such a
way that the runner class is not allowed to have any methods at all.

HTH
Thomas

On 9 March 2017 at 10:04, tripti pathak <trips....@gmail.com> wrote:
>
>
> I am new to cucumber and this is first sample I am working on.
>
> Cucumber set up is done. I ran the cucumberrunner class and feature file was picked and ran gave me the error to add missing implementation.But when I add a class with the detail methods. I get syntax error. Not able to understand the error:
>
>
>
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google Groups "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.




--
Thomas Sundberg
M. Sc. in Computer Science

Mobile: +46 70 767 33 15
Blog: http://www.thinkcode.se/blog
Twitter: @thomassundberg

Better software through faster feedback
Reply all
Reply to author
Forward
0 new messages