Cucumber Java - No features found at file <location> - maven

I am getting the following error while running the maven command "mvn clean verify". I have placed the "feature" file at "C:/Users/304090/eclipse-workspace/evms-qa-testautomation/src/test/resources/". However, its unable to identify the file. Please suggest.
Apr 21, 2020 7:19:43 PM io.cucumber.core.runtime.FeaturePathFeatureSupplier get
WARNING: No features found at file:/C:/Users/304090/eclipse-workspace/evms-qa-testautomation/src/test/resources/
0 Scenarios
0 Steps
0m
0.000s
Folder structure:

check your test runner class where you have provided path to featch your feature files.currently its looking for C:/Users/304090/eclipse-workspace/evms-qa-testautomation/src/test/resources/ folder for a .feature files.
cucumber.api.CucumberOptions imports the #CucumberOptions annotation and it wwll tell where to look for feature files
You need to create features folder into the src/test/resources and past your .feature file in it. After that just update your runner class
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
features = "src/test/resources/features/featurefileanme.feature",
glue={"path of glue package"}
)
public class TestRunner {
}
with serenity:
import cucumber.api.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
import org.junit.runner.RunWith;
#RunWith(CucumberWithSerenity.class)
#CucumberOptions(
features = "src/test/resources/CreatePreVioltReport.feature",
glue = "stepsDef"
)
public class RunTests {}

Related

java.lang.ClassNotFoundException: org.jsoup.Jsoup at runtime

I have a webapp: grails + groovy + gradle (vscode 1.59 as editor)
I get these errors at runtime:
Caused by: java.lang.NoClassDefFoundError: org/jsoup/Jsoup
Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup
build.gradle:
implementation 'org.jsoup:jsoup:1.13.1'
class file:
import org.apache.poi.ss.usermodel.*
import static org.apache.poi.ss.usermodel.Cell.*
import org.apache.poi.ss.usermodel.CellType
import java.io.File
import java.text.SimpleDateFormat
import groovy.sql.Sql
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.*
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import org.jsoup.select.Elements
Error line:
Document doc = Jsoup.parse(file.getInputStream(), "UTF-8")
Things I tried (none worked):
Make a fat jar.
Disable gradle offline mode.
Copy jsoup jar to lib dir.
Any ideas?
Thanks a lot.
It seems like gradle files were corrupted.
I downloaded same version(5.1.1) for a "clean" install.
I set GRAILS_GRADLE_HOME system variable to the new clean gradle folder.
Now it works!

tell cucumber how to use camelCase

I am using Maven and cucumber in test automation.
How can I use camelCase while writing my codes as cucumber is using snakeCase by default.
Is there a way to manage it in pom.xml file in maven?
btw, my IDE is VS Code.
Tnx
If you are using cucumber-junit you can add #CucumberOptions to your JUnit4 runner class.
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
import static io.cucumber.junit.CucumberOptions.SnippetType.CAMELCASE;
#RunWith(Cucumber.class)
#CucumberOptions(snippets = CAMELCASE)
public class RunCucumberTest {
}
You can also create a cucumber.properties file in src/test/resources containg:
cucumber.snippet-type=camelcase
If you're using cucumber-junit-platform-engine this file should be name junit-platform.properties.
The step definitions are using snake case rather than camel case. We just need to tell Cucumber that's what we want:
java -cp "jars/*" cucumber.api.cli.Main -p pretty --snippets camelcase features
Now when we run ./cucumber it generates snippets with method names that conform t the Java standard
from The Cucumber for Java book

Spring Boot #RunWith(SpringRunner.class) results in InitializationError

I have had this problem for a few days, checked similar questions on this forum and Googled in various ways but could not find an answer.
This is a Spring Boot starter project: I have a class Graphs which is annotated by #Component in a package under "src/main/java":
#Component
public class Graphs {
}
Then, I created test classes under "src/test/java". One of them (to test Graphs):
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.example.demo.Graphs;
#RunWith(SpringRunner.class)
#SpringBootTest
public class GraphsTest {
#Test
public void testRun () {
Graphs graph = new Graphs();
}
}
Then I ran testRun in Eclipse (right-click on "testRun"--> Run As --> Junit Test). The result I got was:
initializationError [Runner: Junit 4] (0.0001s)
The Failure Trace in Eclipse shows the following:
java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=testRun], {ExactMatcher:fDisplayName=testRun(com.example.demoTest.GraphsTest)], {LeadingIdentifierMatcher:fClassName=com.example.demoTest.GraphsTest,fLeadingIdentifier=testRun]] from org.junit.internal.requests.ClassRequest#1f7030a6
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:74)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:49)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:525)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
I made a few tweaks without any luck:
I bought my Eclipse Oxygen up-to-date, also tried in Eclipse 2018-12 edition, the same result.
If I remove #RunWith annotation and run testRun, it produced expected results.
I added a Public static void main and ran it as "Java Application", it produced expect results. I guess running it as a Java app bypassed #RunWith(SpringRunner.class).
Where did I do wrong?

Java 8 and Cucumber don't run the step files with lambdas methods

I have a great problem and I have tried to solve this problem, but all time is the same.
I have this scenario with cucumber
feature file
And this is the steps' file
steps' file
Finally I run with
package Steps;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
features = {"./src/test/java/features"},
glue = {"./src/test/java/Steps"},
plugin = {"pretty", "html:reports/cucumber-html-report","json:cucumber.json"}
)
public class Orquestador {
}
And the consolo of intellij appear this:
ans
these are all my files
Files
I am using Mac OS
Thanks :)
Cucumber is not finding your step definitions. Provide the correct "glue" to the location of your step definitions when running the feature file.

Spring JUnit test getting NullPointerException with TestContext.retrieveContextLoaderClass(TestContext .java:197)

Using Helios, spring 3.0.5 (TestContext Framework) and JUnit 4.7. I am getting an initialization error indicating that it cannot find the ContextConfiguration. I ran ProcMon in the background and determined it is not apparently looking at all. I have tried the logical locations for the xml file to no avail. I am unclear of what I am doing incorrectly. Here is the code:
package com.hwcs.veri.agg.dao;
import static org.junit.Assert.assertEquals;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;
import com.hwcs.veri.jpa.License;
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = { "/JpaIntegrationTests-context.xml" })
#TransactionConfiguration( transactionManager = "transactionManager",
defaultRollback = true )
#Transactional
public class JpaIntegrationTests
extends AbstractTransactionalJUnit4SpringContextTests
{
#Autowired
protected LicenseDao licenseDao;
#Test
public void getLicenses()
{
List<License> licenses = this.licenseDao.getLicenses();
assertEquals( "Expecting 1 license from the query",
super.countRowsInTable( "product_schema.license" ),
licenses.size() );
}
}
Is there some particular step that needs to be done to run this as a JUnit test inside Eclipse?
First and foremost, set the log level for org.springframework.test.context to DEBUG. That should tell you everything that the Spring TestContext Framework (TCF) is doing.
Note that with your above configuration, the TCF will attempt to load your application context from classpath:/JpaIntegrationTests-context.xml (i.e., in the root of your classpath). So make sure that the JpaIntegrationTests-context.xml file in fact exists in the root of the classpath (e.g., /src/test/resources/JpaIntegrationTests-context.xml for a Maven project layout). For the Maven project layout, you need to make sure that /src/test/resources is configured as a source folder in your IDE.
If this doesn't help you solve your problem, post the DEBUG output from the log.
Regards,
Sam (author of the Spring TestContext Framework)
Quoting Java Project: Failed to load ApplicationContext
"From the Sping-Documentation: A plain path, for example "context.xml", will be treated as a classpath resource from the same package in which the test class is defined. A path starting with a slash is treated as a fully qualified classpath location, for example "/org/example/config.xml".

Resources