ignoring features in cucumber-jvm - cucumber-jvm

I know you can specify tags for features and then ignore them when running cucumber on the command line. But I'm using cucumber-jvm and running it from maven. #ignore doesn't work and I wouldn't know how to pass the to-be-ignored tags to the runner that executes the Gherkin tests.
The work-around is to move feature that are done to another directory while developing and testing new ones, but that's not how it should be. How do other users deal with this deficiency?

You can tell runner skip #ignore
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#Cucumber.Options(features = {"classpath:my_feature.feature"},
tags = {"~#ignore"})
public class RunCukesTest {
}

You can tag your scenarios as #ignore which will be ignored.
If you want to run only selective scenarios then mark your every new feature that you want to test as #new_test. Tell the Cukes Runner to run only tags = #new_test
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#Cucumber.Options(features = {"classpath:my_feature.feature"},
tags = {"#new_test"})
public class RunCukesTest {
}
Anything that you don't want to test should not have a tag or should have some other tag name

Related

Cucumber.class error: cannot convert from class cucumber to calls runner

I'm getting an error in Cucumber.class saying
cannot convert from class cucumber to calls runner
Here's my code:
package testRunners;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
//import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features="resources/features", glue="StepDefinition")
public class Login {
}
It happens when you have dependency mismatch in your project. More details can be seen after digging in pom.xml. Please share it.
For now you should be knowing that #Runwith takes something which extends ParentRunner Class, so make sure the Cucumber.class that you are using here is extending ParentRunner.

How to run Karate from java application not from JUnit test

I managed to run Karate tests using Junit. But what I want is to run Karate from java application instead of Junit runner.
Currently I'am running from JUnit:
import com.intuit.karate.cucumber.CucumberRunner;
import com.intuit.karate.cucumber.KarateStats;
import cucumber.api.CucumberOptions;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
#CucumberOptions(tags = {"~#ignore"})
public class TestParallel {
#Test
public void testParallel() {
KarateStats stats = CucumberRunner.parallel(getClass(), 5, "target/surefire-reports");
assertTrue("scenarios failed", stats.getFailCount() == 0);
}
}
I tried calling the Junit class from my application main using the code below:
JUnitCore junit = new JUnitCore();
Result result = junit.run(TestParallel.class);
But I have this error:
java.lang.NoClassDefFoundError: com/intuit/karate/cucumber/CucumberRunner
Yes, please use the Java API, documented here: https://github.com/intuit/karate#java-api
Note that you won't get reports if you go down this path.
I solved the problem by removing the test scope from the karate dependencies in the pom.
Everything works fine including the reports and the output.

Cucumber Test runner issue

I have below format for test runner but it is giving no feature file found while running the junit runner.Please attached the screenshot of locations of the step definition and feature file
import org.junit.runner.RunWith;
import cucumber.junit.Cucumber;
#RunWith(Cucumber.class)
#Cucumber.Options(
features ={"C:\\Users\\workspace\\Project3\\src\\qa2qe\\Features\\shipping.feature"},
format = {"pretty"},
tags = {"#testscenario1"}
)
public class ShippingTest {
}

How to implement and run cucumber test files using testng

Trying to implement selenium + Cucumber + Testng instead of Junit.
My queries are
What is the alternate for #Runwith(Cucumber.class) in testng
How to run the class file which contains the path to feature file
package runner;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
#CucumberOptions(features="src/main/java/testCases/Cucumber/Login_Cucumber.Feature",glue="")
public class TestRunner extends AbstractTestNGCucumberTests {
}
TestNg uses #CucumberOptions tag to declare parameters
#CucumberOptions(plugin = "json:target/cucumber-report.json")
public class RunCukesTest extends AbstractTestNGCucumberTests {
}
or
#CucumberOptions(features = "src/test/resources/features/Download.feature",
glue = "uk.co.automatictester.jwebfwk.glue",
format = {"pretty"})
Check this out: https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-calculator-testng
Also a possible dup of :How to integrate the cucumber in testNG?
Install TestNG Eclipse Plugin. Afterwards you should be able to run TestNG Test.
First of all, Cucumber have .feature files and not test files.
Answer to your first question: 1. What is the alternate for #Runwith(Cucumber.class) in testng? "You don't need #RunWith while running with TestNG"
I didn't understand your second question but you need to understand that Cucumber runs end execute the Runner class by default and you have already defined feature files in #CucumberOptions section.
To make it more clear you can easily implement and Run Cucumber project using TestNG. The whole game is in your pom.xml file and Runner class.
Following detail also explains that you can run each scenario in cucumber as a test using TestNG.
How? It's explained below:
First of all, update your Cucumber Maven dependencies from info.cukes to io.cucumber dependencies
Following Java code in Cucumber Runner Class worked perfectly for me to run each scenario as TestNG test in feature files:
#CucumberOptions(features = "src/test/resources", plugin = "json:target/cucumber-report-feature-composite.json")
public class TestRunner {
private TestNGCucumberRunner testNGCucumberRunner;
#BeforeClass(alwaysRun = true)
public void setUpClass() throws Exception {
testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
}
#Test(groups = "cucumber scenarios", description = "Runs Cucumber
Scenarios", dataProvider = "scenarios")
public void scenario(PickleEventWrapper pickleEvent, CucumberFeatureWrapper
cucumberFeature) throws Throwable{
testNGCucumberRunner.runScenario(pickleEvent.getPickleEvent());
}
#DataProvider
public Object[][] scenarios() {
return testNGCucumberRunner.provideScenarios();
}
#AfterClass(alwaysRun = true)
public void tearDownClass() throws Exception {
testNGCucumberRunner.finish();
}
}
Run with mvn clean test command and see the magic :)
I would be happy to see your problem resolved. Please let me know if this issue is still not resolved.
Reference: https://github.com/cucumber/cucumber-jvm/blob/master/testng/README.md
I followed this approach: https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator-testng/src/test/java/cucumber/examples/java/calculator/RunCukesByCompositionTest.java
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
#CucumberOptions(features="src/test/resources/features",glue="stepDefinitions",tags="#Test01",plugin= {"pretty", "html:target/cucumber-reports" },monochrome=true)
public class RunnerTest extends AbstractTestNGCucumberTests{
}
It will work for sure.
This perfectly worked for me
package com.shyom.cucumberOptions;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
#CucumberOptions(
plugin = "json:target/cucumber-report.json",
features = "/shyom/src/test/java/feature",
glue="stepDefinations"
)
public class TestRunner extends AbstractTestNGCucumberTests{
}

Android Instrumentation Tests Stuck "Running Tests" Forever Android Studio

I use Android Espresso Tests with latest Android Studio 2.1.2 and Tests are running ok but it does not seems like the standalone test app returns back the results to reflect back to Android Studio and it shows Running Tests Forever
I realize this is an old question, but I just ran into this and didn't see any other search results that had the same problem.
In my case, this was caused by the code under test having a stack overflow exception, which it seems that the test runner failed to handle. I was only able to figure it out by looking at the "Android Monitor" and looking in the logcat.
So if you get to the point where AS just sits at "running test" forever, you might want to look in logcat for an exception that the test runner couldn't handle.
You have to try removing testCoverageEnabled option from build.gradle file if it's there.
possible duplicate
Gradle build tool long for android Tests
In case this helps anyone.
In my case, I was setting the idle state wrongly(false instead of true) after doing a background task, so espresso was stuck thinking that was idle.
You can add an exit test class like this and include this in your Test Suite or Executor in the last
import android.os.Looper;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;
import org.junit.FixMethodOrder;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import java.io.IOException;
import static androidx.test.InstrumentationRegistry.getInstrumentation;
#RunWith(AndroidJUnit4.class)
#FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ExitTests {
#Rule
public ActivityTestRule<MainActivity> myActivityTestRule =
new ActivityTestRule<>(MainActivity.class, false, true);
public void init(){
getInstrumentation().waitForIdleSync();
if(Looper.myLooper() == null)
Looper.prepare();
}
#Test
public void Exit() throws InterruptedException, IOException {
Runtime.getRuntime().exec(new String[] {"am", "force-stop", "com.package.name"});
}
}
Here is the Test Suite
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
#RunWith(Suite.class)
#Suite.SuiteClasses({ABC.class, ExitTests.class})
public class TestExecutionOrder {
}