0

I new to Selenium Cucumber , trying to setup basic Selenium Cucumber JVM using Eclipse, but when I run Testrunner as JUnit, annotations are missing and I need to manually add test steps in step definition. Below are my Feature & JUnit test runner

Feature: Gmail Login
@Scenario1
Scenario: User logs into GMail
Given Open Browser 
When Enter gmail link
Then Enter login details

TestRunner.java

package cucumberTest;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features = "C:\\XXXX-PATH\\Feature"
    ,glue={"stepDefinition"},
        tags={"@Scenario1"},
        monochrome=true
        )
public class TestRunner {

}

When I execute the TestRunner.java as JUnit, snippet is missing annotation , hence step definition needs to be written manually 1 Scenarios (1 undefined) 4 Steps (4 undefined) You can implement missing steps with the snippets below:

Given("^Open Browser$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});

When("^Enter gmail link$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});

Can some one help me

    <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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>cucmber_test</groupId>
    <artifactId>cucmber_test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <fork>true</fork>
                 <executable>C:\Program Files\Java\jdk1.8.0_111\bin\javac.exe</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.3</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>1.2.3</version>
    <scope>test</scope>
</dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
<dependency> 
   <groupId>info.cukes</groupId> 
   <artifactId>cucumber-junit</artifactId> 
   <version>1.0.2</version> 
   <scope>test</scope> 
</dependency>
<dependency> 
   <groupId>org.seleniumhq.selenium</groupId> 
   <artifactId>selenium-java</artifactId> 
   <version>2.47.1</version> 
</dependency>
    </dependencies>
</project>
Gayathri
  • 25
  • 2
  • 9
  • So whats the actual/real issue/error/difficulty which you are facing? `annotations` of `JUnit` are replaced by feature description in `feature` file in Cucumber. Thanks – undetected Selenium May 30 '17 at 10:55
  • you need to to define @given and "@when" method in your stepDefinition class file; by copying the exact syntax as suggested – Kushal Bhalaik May 30 '17 at 14:21
  • Thanks for response, Am not getting exact syntax as suggested in testrunner , @given is not created, only given is created, hence i need to manually add @ syntax in StepDefinition . Guess I am missing any version – Gayathri May 30 '17 at 15:21
  • In my feature file i added annotations, @ but while executing test runner, I am not getting exact syntax as suggested in testrunner , @ is missing , @given is not created, only given is created, hence i need to manually add @ syntax in StepDefinition . – Gayathri May 30 '17 at 15:25

1 Answers1

0

It may be because of you are using Java 8 lambda style step definition. In Java 8 style step definition, the @ symbol is not needed. Also it is not a issue. You can run the script and it will not affect the execution. Please check the link https://cucumber.io/docs/reference/jvm for more details.

Murthi
  • 5,299
  • 1
  • 10
  • 15