Running subset of tests in Cucumber with maven - maven

I have following problem, i have class (ExoertTest.java) with one feature (with #expert tag):
package opi;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
features = "src/test/resources/features/Expert.feature",
tags = "#expert"
)
public class ExpertTest {
}
I want run only this one feature from maven with command
mvn clean test -Ptest -Dcucumber.options="--tags #expert"
but no tests are executed, logs from console:
[INFO] Running opi.ExpertTest None of the features at
[src/test/resources/features/Expert.feature] matched the filters:
[#expert]
0 Scenarios 0 Steps 0m0,000s
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed:
0.013 s - in opi.ExpertTest
Do You know why Cucumber dont see my #expert tag and this case is not executed?
I use Cucumber with Selenide

Ok, i put tags in feature file instead of CucumberOptions in TestRunner.class and it works

Related

What can I do with console error : Error: ENAMETOOLONG: name too long, stat 'cypress/integration/cypress...'?

I have 20 autotests and open sypress using comand:
./node_modules/.bin/cypress open
And Cypress window is closed. There is Error in the console:
Error: ENAMETOOLONG: name too long, stat 'cypress/integration/cypress/integration/cypress/integration/cypress/integration/cypress/integration/cypress/integration/cypress/...'
cypress.json:
{
"baseUrl": "https://localhost:3000",
"video": true,
"viewportWidth": 1920,
"viewportHeight": 1024,
"numTestsKeptInMemory": 0,
"defaultCommandTimeout" : 15000,
"testFiles": [
"1_ID.js",
"2_ID.js",
"3_ID.js",
...
"18_ID.js",
"19_ID.js",
"20_ID.js",
]
}
I delete 10 Autotests from the "testFiles" list and Cypress window operate as expected.
What can I do?
You can check for two things in your testFiles array:
Check whether any of the spec file names you added has a typo.
Check whether you have added a file name inside the testFiles array but in reality it doesn't exist.
For me personally I faced the same issue on my windows machine and the reason was point 2.
If you have trouble using testFiles configuration, try using a parent test instead.
my-tests.spec.js
import "1_ID.js";
import "2_ID.js";
import "3_ID.js";
...
import "18_ID.js";
import "19_ID.js";
import "20_ID.js";
Run the parent
npx cypress open --spec "my-tests.spec.js"

Can't pass testNg command line argument from gradle build

I have a standard build.gradle file which suppose to run testNg tests:
test{
useTestNG(){
spiListenersToSkip = "some value" - causes "option unknown" exception
...
useDefaultListeners=true
...
}
}
I want to pass a testNg runner command line argument (spiListenersToSkip) from the build file.
The problem is that gradle testNg plugin seem to be able to work only with arguments defined in it's TestNgOptions class. One thing to mention is that the list of options in the class is much shorter than actual list of available testNg CL arguments.
Would really appreciate any thoughts on how to pass command line parameter to testNg runner.
I think the right way is to path during execution
gradlew test -Psuite1
in case you want to choose one and only one of multiple suites
def suite1 = project.hasProperty("suite1")
def suite2 = project.hasProperty("suite2")
test {
useTestNG() {
dependsOn cleanTest
useDefaultListeners = true
if(suite1) {
suites "src/test/resources/simpleSuite.xml"
}
if(suite2) {
suites "src/test/resources/advancedSuite.xml"
}
}
}
Then you can easily choose by passing with -P
gradlew test -Psuite2
or even 2 of three
gradlew test -Psuite2 -Psuite1

Groovy: unable to resolve class when running from command line

I'm trying to run a groovy script from command line. It runs fine in a gradle project in intellij, but when I try to run it via command line I get several errors like this one
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
failed:
/home/tpulayan/jenkins-
watcher/src/main/groovy/attempt_authentification.groovy: 1: unable to resolve
class in.ashwanthkumar.slack.webhook.Slack
# line 1, column 1.
import in.ashwanthkumar.slack.webhook.Slack
^
1 error
My code:
#Grapes(
#Grab(group='in.ashwanthkumar', module='slack-java-webhook',
version='0.0.7')
)
import in.ashwanthkumar.slack.webhook.Slack
import in.ashwanthkumar.slack.webhook.SlackMessage
import org.apache.http.HttpException
import org.apache.http.HttpHost
import org.apache.http.HttpRequest
import org.apache.http.HttpRequestInterceptor
import org.apache.http.auth.AuthScheme
import org.apache.http.auth.AuthScope
import org.apache.http.auth.AuthState
import org.apache.http.auth.UsernamePasswordCredentials
import org.apache.http.client.CredentialsProvider
import org.apache.http.client.methods.HttpGet
import org.apache.http.client.protocol.ClientContext
import org.apache.http.impl.auth.BasicScheme
import org.apache.http.impl.client.DefaultHttpClient
import org.apache.http.protocol.BasicHttpContext
import org.apache.http.protocol.ExecutionContext
import org.apache.http.protocol.HttpContext
import org.apache.http.util.EntityUtils
use(TimerMethods) {
def timer = new Timer()
def periodSeconds = 600
new Slack()
.icon(':exclamation:')
.sendToChannel('jenkins-monitoring')
.displayName('Jenkins Watcher')
.push(new SlackMessage("Jenkins Watcher started at ${new Date()}. Started to monitor the status of deb-jenkins-prd..."))
def task = timer.runEvery(1000, periodSeconds * 1000) {
def response = getAuthentication().statusCode
if (response != 200) {
new Slack()
.icon(':exclamation:')
.sendToChannel('jenkins-monitoring')
.displayName('Jenkins Watcher')
.push(new SlackMessage("Login attempt by Jenkins Watcher failed at ${new Date()}. This could indicate that Jenkins is stuck! Request response code is: ${response}"))
}
}
}
I suppose it's something related to the classpath but I was unable to solve it.
Any help is much appreciated!
EDIT AFTER RESPONSE
I've updated my code with the #Grab but unfortunately I get this error when running it from command line:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during conversion: Error grabbing Grapes -- [unresolved dependency: in.ashwanthkumar#slack-java-webhook;0.0.7: not found]
java.lang.RuntimeException: Error grabbing Grapes -- [unresolved dependency: in.ashwanthkumar#slack-java-webhook;0.0.7: not found]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:238)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:250)
at groovy.grape.GrapeIvy.getDependencies(GrapeIvy.groovy:464)
in build.gradle seems you have defined dependencies.
you can put all dependencies (*.jar) into ./lib dir and run your groovy script like this:
groovy -cp ./lib/* MyScript.groovy
or you can specify all the dependencies using Grape/Grab directly in your groovy script then your command line will be simple and groovy will download all dependencies on script start
groovy MyScript.groovy

How to run single maven test with spaces within name

Normally using maven when I want to run a single test I would do something like this....
mvn clean test -Dtest= GetRegistrationValidatorTest#MyTestName
We have just changed our Groovy test names to be more meaningful using the following type of syntax.
class GetRegistrationValidatorTest {
#Test
void 'validation get registration chassis number success'() {
}
}
How can I run the single maven test when it is named as per above?
thanks
mvn clean test -Dtest='GetRegistrationValidatorTest#MyTestName'
Single quotes work for me, even with stranger characters than spaces:
class PlopTest {
#Test void 'Hey! Can you plöp?'() {
println "Sure..."
}
#Test void foo() {
assertTrue(false);
}
}
Then:
% mvn test -Dtest='PlopTest#Hey! Can you plöp?'
[...]
Running PlopTest
Sure...
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.91 sec
1 test run, no failure => it correctly executed only the single test I passed as argument.
If I try -Dtest='PlopTest' it runs both tests (and of course fails).

Scalatest takes 30s to start tests

EDIT: I found a solution. Killing the terminal seems to resolve the problem. I guess it is not terminated when the computer is rebooted.
I still don't know however where the problem came from.
I noticed that scalatest suddenly became lost slower to start the tests.
I removed all the tests and only left one, simply testing true.
Here is what I get (using sbt)
MacBook-Pro:simulator nicolas$ sbt
[info] Set current project to Simulator (in build file:/Users/nicolas/Private/simulator/)
> compile
[success] Total time: 1 s, completed 29-Oct-2016 14:30:04
> test
[info] MySpec:
[info] A pip
[info] - should pop
[info] Run completed in 312 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 31 s, completed 29-Oct-2016 14:30:37
As you can see, the compile is instant (1s) and the tests themselve run in 312 milliseconds. What could be explaining that it actually need 31s to run them?
It was not like this to start with, they were running in a few seconds then suddenly jumped up to 30s (even with only 1 extremely quick test)
Happens too after a fresh restart of the computer.
Here is my build.sbt just in case:
lazy val root = (project in file(".")).
settings(
name := "Simulator",
version := "0.1",
scalaVersion := "2.11.8"
)
// scala JSON library
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.2"
// ScalaTest dependencies
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.0"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % "test"
// QuickLens
libraryDependencies += "com.softwaremill.quicklens" %% "quicklens" % "1.4.8"
Thanks!
Edit: I made a new project (minimal) and I have the same issue, here is the full tree
project
| - build.sbt
| - src
| - main
| | - scala
| | - hw.scala
| - test
| - scala
| - myTest.scala
hw.scala:
object Hi { def main(args: Array[String]) = println("Hi!") }
myTest.scala:
import org.scalatest._
class MySpec extends FlatSpec with Matchers {
"A pip" should "pop" in { true should be(true) }
}
same build.sbt as above
If you recently upgraded to macOS Sierra, you may be running into this issue: SBT test extremely slow on macOS Sierra

Resources