Citrus-Cucumber: Can I run a single Cucumber Scenario? - intellij-idea

I have a Cucumber feature file with a bunch of Scenarios to execute Citrus integration tests (Citrus-Cucumber integration). I can run all Scenarios at once in IntelliJ or through Maven.
Works perfect, but is it possible to run a single Scenario in IntelliJ or through Maven?
In IntelliJ I found a Cucumber plugin that gives me this option, but after fixing lots of NoClassDefFound errors with dependency tricks, it fails because it does not respect the Citrus project files such as citrus-application.properties.

Answer to myself: Yes, I can.
According to the Cucumber docs, it uses tags to (what a surprise) tag scenarios. Tags begin with the # symbol and one can set any number of tags on a Feature or Scenario.
Example:
#Test123
#Important
Scenario: My awesome Scenario
Given ...
When ...
Then ...
#Test456
Scenario: My other Scenario
Given ...
When ...
Then ...
With these tags in place, I can "select" scenarios to execute based on tags. For example to execute all important Scenarios I use the tag #Important.
cucumber --tags #Important
Since I execute my tests through a Citrus class, I have to pass the tags to execute in the CucumberOptions of my test class.
#RunWith(Cucumber.class)
#CucumberOptions(
strict = true,
glue = { "com.consol.citrus.cucumber.step.runner.core" },
plugin = { "com.consol.citrus.cucumber.CitrusReporter" },
tags = { "#Important" }
)
public class RunCucumberTests {
}
It is not super-convenient, to edit the test class metadata every time, but it works.

Related

Karate API framework- test dependency

In my regression suite I have 600+ test cases. All those tests have #RegressionTest tag. See below, how I am running.
_start = LocalDateTime.now();
//see karate-config.js files for env options
_logger.info("karate.env = " + System.getProperty("karate.env"));
System.setProperty("karate.env", "test");
Results results = Runner.path("classpath:functional/Commercial/").tags("#RegressionTest").reportDir(reportDir).parallel(5);
generateReport(results.getReportDir());
assertEquals(0, results.getFailCount(), results.getErrorMessages());
I am thinking that, I can create 1 test and give it a tag #smokeTest. I want to be able to run that test 1st and only if that test passes then run the entire Regression suite. How can I achieve this functionality? I am using Junit5 and Karate.runner.
I think the easiest thing to do is run one test in JUnit itself, and if that fails, throw an Exception or skip running the actual tests.
So use the Runner two times.
Otherwise consider this not supported directly in Karate but code-contributions are welcome.
Also refer to the answers to this question: How to rerun failed features in karate?

how to run only one test in scalatest/playspec

My spec file has several tests
"HomeController index page" should {
"have title Welcome " in {
....
}
"Home controller " should {
"render homepage with csrfToken" in {
...
}
To run the tests in IntelliJ, I right-click on the spec file and select run. But this runs all the tests. Is there a way to select tests and run only the selected ones?
You should be able to run individual tests by placing the cursor inside the test method and pressing Ctrl+Shift+F10 or by creating the ScalaTest run/debug configuration where you can specify the test name to run.
See also Test scopes in Scala section in the documentation:

how to skip testing scenario for different environment

How to skips scenarios conditionally in Cucumber Java testing?
For different testing environement,different scenarios need to be skipped.
You can assign a tag for the scenarios and exclude those scenario using the tags with cucumber options.
For example,
Feature: Feature 1
#skipforenv2
Scenario: Testing 1
....
#skipforenv1
Scenario: Testing 2
....
Assume if you want to skip scenario "Testing 2" in environment 1 and scenario "Testing 1"in Environment 2 Then,
While running on Environment 1, you can pass the tag argument as ~#skipforenv1 (--tags #skipforenv1). if we use ~ symbol before tag then it will be skipped for that execution.
using command line, `-Dcucumber.options="--tags ~#skipforenv1"`
using runner class, `#CucumberOptions(tags={"~#skipforenv1"}, .....)`
While running on Environment 2, you can pass the tag argument as ~#skipforenv2 (--tags #skipforenv2). Scenario 2 will be skipped.
using command line, -Dcucumber.options="--tags ~#skipforenv2"
using runner class, #CucumberOptions(tags={"~#skipforenv2"}, .....)

How to run an specific test case in the selected environment in SoapUI

I have multiple Environment and a lot of test cases, but not all test cases are needed to be run in all environment. Is there a way to run only an specific test cases from a test suite based on the selected Environment.
For Example
If I select Environment1, it will run the following test cases
TC0001
TC0002
TC0003
TC0004
TC0005
If I select Environment2, it will run only the following test cases
TC0001
TC0003
TC0005
There can be different solution to achieve this since you have multiple environments i.e., pro software being used.
I would achieve the solution using Test Suite's Setup Script:
Create Test Suite level custom property. Use the same name as your environment name. For instance, DEV is the environment defined, use the same as test suite property name and provide the list of values separated by comma as value for that property, say TC1, TC2 etc.,
Similarly defined other environments and its values as well.
Copy the below script in Setup Script for the test suite and execute the script which enables or disables the test cases according to the environment and property value
Test Suite's Setup Script
/**
* This is soapui's Setup Script
* which enables / disables required
* test cases based on the user list
* for that specific environment
**/
def disableTestCase(testCaze) {
testCaze.disabled = true
}
def enableTestCase(testCaze) {
testCaze.disabled = false
}
def getEnvironmentSpecificList(def testSuite) {
def currentEnv = testSuite.project.activeEnvironment.NAME
def enableList = testSuite.getPropertyValue(currentEnv).split(',').collect { it.trim()}
log.info "List of test for enable: ${enableList}"
enableList
}
def userList = getEnvironmentSpecificList(testSuite)
testSuite.testCaseList.each { kase ->
if (userList.contains(kase.name)) {
enableTestCase(kase)
} else {
disableTestCase(kase)
}
}
Other way to achieve this is using Event feature of ReadyAPI, you may use TestRunListener.beforeRun() and filter the test case whether to execute or ignore.
EDIT:
If you are using ReadyAPI, then you can the new feature called tag the test cases. A test case can be tagged with multiple values and you can execute tests using specific tags. In this case, you may not needed to have the setup script as that is for the open source edition. Refer documentation for more details.
This solution is only specific to Pro software and Open Source edition does have this tag feature.

ScalaTest and IntelliJ - Running one Test at a time

I have a ScalaTest which extends the FlatSpec. I have many tests inside the test and I now want to have the possibility to run one test at a time. No matter what I do, I can't get IntelliJ to do it. In the Edit Configurations of the test, I can specify that it should run one test at a time by giving the name of the test. For example:
it should "test the sample multiple times" in new MyDataHelper {
...
}
where I gave the name as "test the sample multiple times", but it does not seem to take that and all I get to see is that it just prints Empty Test Suite. Any ideas how can this be done?
If using Gradle, go to Preferences > Build, Execution, Deployment > Build Tools > Gradle and in the Build and run > Run tests using: section, select IntelliJ IDEA if you haven't already.
An approach that works for me is to right-click (on Windows) within the definition of the test, and choose "Run MyTestClass..." -- or, equivalently, Ctrl-Shift-F10 with the cursor already inside the test. But it's a little delicate and your specific example may be causing your problem. Consider:
class MyTestClass extends FlatSpec with Matchers {
"bob" should "do something" in {
// ...
}
it should "do something else" in {
// ...
}
"fred" should "do something" in {
// ...
}
it should "do something else" in {
// ...
}
}
I can use the above approach to run any of the four tests individually. Your approach based on editing configurations works too. But if I delete the first test I can't run the second one individually -- the others are still fine. That's because a test that starts with it is intended to follow one that doesn't -- then the it is replaced with the appropriate string in the name of the test.
If you want to run the tests by setting up configurations, then the names of these four tests are:
bob should do something
bob should do something else
fred should do something
fred should do something else
Again, note the substitution for it -- there's no way to figure out the name of a test starting with it if it doesn't follow another test.
I'm using IntelliJ Idea 13.1.4 on Windows with Scala 2.10.4, Scala plugin 0.41.1, and ScalaTest 2.1.0. I wouldn't be surprised if this worked less well in earlier versions of Idea or the plugin.
I just realized that I'm able to run individual tests with IntelliJ 13.1.3 Community Edition. With the one that I had earlier 13.0.x, it was unfortunately not possible.