2

In the project Structure defined like below,

  • src/main/java -- Config (RunCukesTest.java) -- StepDefinitions
  • src/test/resources -- features/loginenter image description here

When I run from RunCukesTest.java using RunAs --> JUnit Test, Step Definitions cannot be found by runner

When I click find Step, opens the right file. Couldn't understand where the issue is because the code was running few days back. File is downloaded from here

https://drive.google.com/open?id=0B4SgyzyvwKhiVTRmRDZuNXNTSjA

Runner class code

package helpers;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
//features= "src/test/resources/features/navigation",

@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"classpath:features"},
        plugin = {"pretty", "html:target/cucumber-html-report"},
        tags = {"@OnlyOneTime"},
//      dryRun = true,
        monochrome = true
        )
public class RunCukesTest{

}
RamanaMuttana
  • 481
  • 6
  • 22
Nagarjuna Reddy
  • 759
  • 9
  • 19
  • 39
  • Your project structure is not clear, it would be better if you could post a snapshot of your project folder structure. – Kushal Bhalaik May 22 '17 at 06:55
  • @NagarjunaReddy Which version of `cucumber-java`, `junit`, `cucumber-junit` & `selenium-java` are you using? I am not sure if we can place `features/login` feature file within `src/test/resources`. Thanks – undetected Selenium May 22 '17 at 06:55
  • @kushal. added project structure – Nagarjuna Reddy May 22 '17 at 06:59
  • @Dev `cucumber-java: 1.2.5 junit: 4.12 cucumber-junit: 1.2.5 selenium-java: 3.4.0` Added the versions – Nagarjuna Reddy May 22 '17 at 07:01
  • @NagarjunaReddy Can you consider showing us your runner class? Thanks – undetected Selenium May 22 '17 at 07:05
  • @Dev `package helpers; import org.junit.runner.RunWith; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; //features= "src/test/resources/features/navigation", @RunWith(Cucumber.class) @CucumberOptions( features = {"classpath:features"}, plugin = {"pretty", "html:target/cucumber-html-report"}, tags = {"@OnlyOneTime"}, // dryRun = true, monochrome = true ) public class RunCukesTest{ }` In case if you want to download the project, available in the above link – Nagarjuna Reddy May 22 '17 at 07:06
  • @NagarjunaReddy You have provided a tag as `tags = {"@OnlyOneTime"},`. Can you consider showing us the implementation of the tag? Thanks – undetected Selenium May 22 '17 at 07:20
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/144809/discussion-between-nagarjuna-reddy-and-dev). – Nagarjuna Reddy May 22 '17 at 07:21
  • glue={"stepDefinitions"} should work – Kushal Bhalaik May 22 '17 at 08:11
  • @kushal. this doesn't work. if i try to run from feature file, that gives the error **Launch configuration Login.feature references non-existing project s360UIAutomation.** – Nagarjuna Reddy May 22 '17 at 08:21
  • hi @NagarjunaReddy : I downloaded your project as it is from the GDrive and it works well on my machine; if I run it is a Cucumber feature, but if I provide `glue={"stepDefinitions"}` and try running it from runner then NullPointerException is thrown – Kushal Bhalaik May 22 '17 at 14:44
  • Problem is coming from not able to finding hooks – Kushal Bhalaik May 22 '17 at 14:53
  • @kushal.i find debugging little complicated in cucumber compared to selenium+testng. How to debug this – Nagarjuna Reddy May 22 '17 at 14:55
  • Moving previous comment to answer. – Kushal Bhalaik May 22 '17 at 15:02
  • Is it not mandatory to provide the glue path – Nagarjuna Reddy May 22 '17 at 15:03

4 Answers4

1

Glue code is supposed to have path to hooks and step definitions

So modified as glue={"helpers","stepDefinitions"} instead of glue={"helpers","classpath/stepDefinitions", "classpath/stepDefinitions.LogIn","classpath/stepDefinitions.Publish"}

Please refer to this link Similar issue on github

Nagarjuna Reddy
  • 759
  • 9
  • 19
  • 39
0

I figured out your issue, As per your runner class, the glue path is not set. please set glue path.glue={"stepDefinitions"}

package helpers; 
import org.junit.runner.RunWith; 
import cucumber.api.CucumberOptions; 
import cucumber.api.junit.Cucumber; 
//features= "src/test/resources/features"@RunWith(Cucumber.class) @CucumberOptions( 
features = {"classpath:features"}, glue={"stepDefinitions"},plugin = {"pretty", "html:target/cucumber-html-report"}, tags = {"@OnlyOneTime"}, // dryRun = true, monochrome = true ) 
public class RunCukesTest{ }
Mahipal
  • 900
  • 1
  • 5
  • 7
Murthi
  • 5,299
  • 1
  • 10
  • 15
  • i did try using glue code before posting this question which was not running. `glue = {"stepDefinitions.Login"} Or glue = {"stepDefinitions"}` First one shows step definitions are not present. Second one gives null pointer exceptoin. Config is maintained in **config.properties** file – Nagarjuna Reddy May 22 '17 at 07:19
  • second one should work. can you give me stack trace info. – Murthi May 22 '17 at 09:27
  • `java.lang.NullPointerException at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69) at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38) at com.sun.proxy.$Proxy14.sendKeys(Unknown Source) at stepDefinitions.LogIn.SDLogin.inputUserCredentials(SDLogin.java:29) at ✽.When User enter the valid credentials(features/logIn/Login.feature:5)` – Nagarjuna Reddy May 22 '17 at 09:59
  • Dont get this when i user `glue={"classpath:stepDefinitons", "classpath:stepDefinitons.Login","classpath:stepDefinitons.Publish"},` Console shows the message to add steps – Nagarjuna Reddy May 22 '17 at 09:59
0

Running it as a Cucumber feature, it works well, but if I provide glue={"stepDefinitions"} and try running it from runner then NullPointerException is thrown,

This problem is arising from hooks not being found. But If I move @Before and @After to the SDLogin classs, then It works well.

Kushal Bhalaik
  • 3,349
  • 5
  • 23
  • 46
0

In my case , feature files are in src/test/resources/Features/login.feature Step definitions are in com.steps.definitions

So giving like below solved the issue.

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

@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"src/test/resources/Features/login.feature"}, glue={"com.steps.definitions"},plugin = {"pretty", "html:target/cucumber-html-report"})
public class TestRunner {
}

Here is the folder/package structure. enter image description here

Sameera De Silva
  • 1,722
  • 1
  • 22
  • 41