Giter VIP home page Giter VIP logo

sbt-cucumber's Introduction

SBT Cucumber

The Cucumber plugin provides a new sbt command, allowing you to run just your Cucumber tests using sbt cucumber.

The plugin can be used if you want a separate command to run Cucumber tests and have your normal test framework ignore Cucumber tests.

If you want to run Cucumber tests within a ScalaTest unit test framework see here.

Dependency Information

 addSbtPlugin("com.waioeka.sbt" % "cucumber-plugin" % "0.3.1")

Note The latest version of the plugin is built using SBT 1.2.8.

Cucumber Plugin Example

The project cucumber-plugin-example highlights how to use the plugin. You will need to ensure that your build.sbt file defines both the dependencies and the 'glue' setting (i.e. where to find the step definitions).

name := "cucumber-test"
organization := "com.waioeka.sbt"
version := "0.3.0"

libraryDependencies ++= Seq (
  "io.cucumber" % "cucumber-core" % "6.10.3" % "test",
  "io.cucumber" %% "cucumber-scala" % "6.10.3" % "test",
  "io.cucumber" % "cucumber-jvm" % "6.10.3" % "test",
  "io.cucumber" % "cucumber-junit" % "6.10.3" % "test",
  "org.scalatest" %% "scalatest" % "3.2.8" % "test")

enablePlugins(CucumberPlugin)

CucumberPlugin.glues := List("com.waioeka.sbt")

// Any environment properties you want to override/set.
CucumberPlugin.envProperties := Map("K"->"2049")

Remember to set the CucumberPlugin.glue parameter to the sub directory in test that contains your Scala step definitions.

In your resources directory, put in your feature files.

@my-tag
Feature: Multiplication
  In order to avoid making mistakes
  As a dummy
  I want to multiply numbers

Scenario: Multiply two variables
Given a variable x with value 2
And a variable y with value 3
When I multiply x * y
Then I get 6

If you need to generate the stubs, just run sbt cucumber and you will get an error complaining about missing stubs. You can copy and paste the stub functions into your step implementation.

You can now put in your stub implementation:

package com.waioeka.sbt

import io.cucumber.scala.{EN, ScalaDsl}
import org.scalatest.Matchers

/** AddAndMultiplySteps*/
class MultiplicationSteps extends ScalaDsl with EN with Matchers {
  var x : Int = 0
  var y : Int = 0
  var z : Int = 0

  Given("""^a variable x with value (\d+)$""") { (arg0: Int) => x = arg0 }

  Given("""^a variable y with value (\d+)$""") { (arg0: Int) => y = arg0 }

  When("""^I multiply x \* y$""") { () => z = x * y }

  Then("""^I get (\d+)$""") { (arg0: Int) => z should be (arg0) }
}

To run the tests in standalone mode:

sbt compile
sbt cucumber

You should see some output as follows:

paeroa:cucumber-test lewismj$ sbt cucumber
[info] Loading project definition from /Users/lewismj/waioeka/upa-plugins/cucumber-test/project
[info] Set current project to cucumber-test (in build file:/Users/lewismj/waioeka/upa-plugins/cucumber-test/)
[info] Feature: Multiplication
[info]   In order to avoid making mistakes
[info]   As a dummy
[info]   I want to multiply numbers
[info]
[info]   Scenario: Multiply two variables  # Multiplication.feature:6
[info]     Given a variable x with value 2 # MultiplicationSteps.scala:17
[info]     And a variable y with value 3   # MultiplicationSteps.scala:21
[info]     When I multiply x * y           # MultiplicationSteps.scala:25
[info]     Then I get 6                    # MultiplicationSteps.scala:29
[info]
[info] 1 Scenarios (1 passed)
[info] 4 Steps (4 passed)
[info] 0m0.106s
[info]
[success] Total time: 1 s, completed 28-Dec-2015 22:16:19

The results will be output in the following formats:

  • cucumber-html, standard Cucumber html output.
  • cucumber.json, standard Cucumber json output.
  • cucumber-junit-report.xml, a Junit style rest report.

Cucumber Plugin Arguments

Cucumber arguments may be supplied. For example, sbt "cucumber --tags ~@my-tag" will filter tagged feature files.

[success] Total time: 1 s, completed 15-Jun-2016 09:23:22
paeroa:cucumber-plugin-example lewismj$ sbt "cucumber --tags ~@my-tag"
[info] Loading global plugins from /Users/lewismj/.sbt/0.13/plugins
[info] Loading project definition from /Users/lewismj/github/cucumber/cucumber-plugin-example/project
[info] Set current project to cucumber-test (in build file:/Users/lewismj/github/cucumber/cucumber-plugin-example/)
** hello **
[info] None of the features at [classpath:] matched the filters: [~@my-tag]
[info]
[info] 0 Scenarios
[info] 0 Steps
[info] 0m0.000s
[info]
** goodbye **
[success] Total time: 1 s, completed 15-Jun-2016 09:23:41

Properties

In your build.sbt file you can now specify environment variables as follows:

CucumberPlugin.envProperties := Map("K"->"2049")

The setting expects a type of Map[String,String].

Changelog

Version Summary
0.3.0 The plugin now uses Cucumber 6.10.3
0.2.0 Please note this change was merged in, to make the glue parameter a List, rather than String.

sbt-cucumber's People

Contributors

asarturas avatar bottaio avatar eed3si9n avatar gedeh avatar lewismj avatar michalmela avatar ppiotrow avatar rudwna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sbt-cucumber's Issues

Cross release for 2.11, 2.12, 2.13

Hi, currently the project is released only for Scala 2.12.
Could you cross release this project for other still widely used Scala versions?

Q: Use with SBT version 1.3.13

Are there any objections to use the cucumber-plugin 0.3.1 with SBT 1.3.13?

The note in RADME.md says

Note The latest version of the plugin is built using SBT 1.2.8.

but it seems to work with SBT 1.3.13 (Scala 2.13.5) as follows:

plugins.sbt

addSbtPlugin("com.waioeka.sbt" % "cucumber-plugin" % "0.3.1")

build.sbt

libraryDependencies ++= Seq (
  "io.cucumber" %% "cucumber-scala" % "8.13.1" % Test
)

enablePlugins(CucumberPlugin)

java.lang.IllegalStateException if any of the JUnit Assertions failing

Hi,

I am have written some cucumber scenarios and added junit assertions in the steps.
If any of the assertions fail, the cucumber report comes with step failure, but cucumber plugin also throws following error.

[error] java.lang.IllegalStateException: Cucumber did not succeed and returned error =1
[error] at com.waioeka.sbt.CucumberPlugin$.$anonfun$projectSettings$6(CucumberPlugin.scala:116)
[error] at com.waioeka.sbt.CucumberPlugin$.$anonfun$projectSettings$6$adapted(CucumberPlugin.scala:91)
[error] at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:39)
[error] at sbt.std.Transform$$anon$4.work(System.scala:66)
[error] at sbt.Execute.$anonfun$submit$2(Execute.scala:262)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error] at sbt.Execute.work(Execute.scala:271)

Following are the sbt changes..

Plugin Dependencies added:
addSbtPlugin("com.waioeka.sbt" % "cucumber-plugin" % "0.3.0")

lazy val qaDependencies = Seq(
"io.cucumber" % "cucumber-core" % "6.10.4" % "test",
"io.cucumber" %% "cucumber-scala" % "6.10.4" % "test",
"io.cucumber" % "cucumber-jvm" % "6.10.4" % "test",
"io.cucumber" % "cucumber-junit" % "6.10.4" % "test",
"io.cucumber" % "cucumber-java" % "6.10.4"% "test",
"org.scalatest" %% "scalatest" % "3.0.5" % "test",
"junit" % "junit" % "4.12" % "test")

lazy val testPro= project
.settings(name := "testPro")
.settings(libraryDependencies ++= qaDependencies)
.settings(crossPaths :=false)
.enablePlugins(CucumberPlugin)
.settings(CucumberPlugin.glues := List("com.waioeka.sbt"))
.settings(CucumberPlugin.envProperties := Map("cucumber.execution.strict"->"true"))

Any help on how to resolve this. This is causing the jenkins builds to go on error always if there is any assertion failure.

Unresolved Dependencies

Hello,

This plugin cannot be found

sbt.ResolveException: unresolved dependency: com.waioeka.sbt#cucumber-plugin;0.1.7: not found

Any Help?

Can't seem to pass through JVM options on the command line

I've had a look around but can't see the answer so if the following does exist, pointing me in the right direction would be appreciated.

Firstly, great that I can just run sbt cucumber and not have the unit tests execute also, however, in my tests, I tend to specify various JVM options, these seem to be ignored with sbt cucumber though.

For example, when choosing what browser to run against I would normally enter:

sbt -Dbrower=firefox test and the test would run agains the firefox driver as expected

however, that is ignored if I enter

sbt -Dbrowser=firefox cucumberand the test runs in Chrome by default.

Is it possible to be able to pass through JVM options on the command line?

Enhancement request : --retry flag

Currently there is no ability to retry failed test for failed test from the CLI using something like a --retry. Is there any ability to add this or any alternate solution that can be used to currently that serves the same purpose?

BeforeAll | AfterAll - Enhancement proposition

In our team we found that there is missing pretty basic functionality which would cover BeforeAll and AfterAll hooks executions block.
The solution support Before and After but is is performed for each case alongside with the use case Gherkin table.

classpath setting is not available in published 0.3.1

Looking at the commit dates, it looks like the configurable classpath should have made it into the published 0.3.1 version, but when browsing to the 0.3.1 source that sbt has downloaded I can see that it's not there. It would be great to have this available.

My plugins.sbt:

addSbtPlugin("com.waioeka.sbt" % "cucumber-plugin" % "0.3.1")

My build.sbt:

CucumberPlugin.classpath = (fullClasspath in IntegrationTest).value

sbt output:

error: value classpath is not a member of object com.waioeka.sbt.CucumberPlugin

prettier reporting

I've followed this to enable prettier reporting for the tests.
https://www.jvt.me/posts/2019/04/07/prettier-cucumber-jvm-html-reports/
https://gitlab.com/monochromata-de/cucumber-reporting-plugin

Following this I've managed to run the reporting plugin by doing:
sbt "cucumber --tags @healthcheck --add-plugin de.monochromata.cucumber.report.PrettyReports:integration/target/test-reports/cucumber"

But I've had no luck getting it to work when trying to referencing the plugin from the build.sbt.... any ideas or thoughts how to accomplish this?

Test file does not recognize .feature file

Quando executo o arquivo de teste ele não reconhece o arquivo .feature. This is what I use on sbt:

"io.cucumber" % "cucumber-core" % "4.3.0" % "test",
"io.cucumber" %% "cucumber-scala" % "4.3.0" % "test",
"io.cucumber" % "cucumber-jvm" % "4.3.0" % "test",
"io.cucumber" % "cucumber-junit" % "4.3.0" % "test"

This is the answer that I receive:

jul 23, 2019 2:40:05 PM cucumber.runtime.FeaturePathFeatureSupplier get
AVISO: No features found at classpath:src/test/functional/features

0 Scenarios
0 Steps
0m0,308s

Thanks in advance.

Version 0.3.0

Is the new version already available ?
We have try to bump it but end up with the error

[error] sbt.librarymanagement.ResolveException: unresolved dependency: com.waioeka.sbt#cucumber-plugin;0.3.0: not found
[error] 	at sbt.internal.librarymanagement.IvyActions$.resolveAndRetrieve(IvyActions.scala:332)

related to the commit made by @gedeh

thanks in advance !

Warning when passing --tags args to command line

Hi

I've been running my tests from the command line with
sbt 'cucumber --tags ~@ignore'

And I am getting this warning:
WARNING: Found tags option '~@ignore' Support for '~@tag' will be removed from the next release of Cucumber-JVM. Please use 'not @tag' instead.

However when I try to use the 'not @tag' it doesn't appear to work. Any ideas?

Plugin is not compatible with latest cucumber-scala 6.2.2

I am seeing error:
Jul 23, 2020 4:14:12 PM cucumber.api.cli.Main run
WARNING: You are using deprecated Main class. Please use io.cucumber.core.cli.Main
Exception in thread "main" java.lang.IllegalArgumentException: Couldn't create a file output stream for /Users/tester/cucumber-tests/target/test-reports/cucumber.
Make sure the the file isn't a directory.
The details are in the stack trace below:
at io.cucumber.core.plugin.PluginFactory.createFileOutputStream(PluginFactory.java:209)
at io.cucumber.core.plugin.PluginFactory.openStream(PluginFactory.java:197)
| => rat io.cucumber.core.plugin.PluginFactory.convert(PluginFactory.java:164)
| => rat io.cucumber.core.plugin.PluginFactory.instantiate(PluginFactory.java:97)
at io.cucumber.core.plugin.PluginFactory.create(PluginFactory.java:62)
at io.cucumber.core.plugin.Plugins.createPlugins(Plugins.java:32)
at io.cucumber.core.plugin.Plugins.(Plugins.java:25)
at io.cucumber.core.runtime.Runtime$Builder.build(Runtime.java:171)
at io.cucumber.core.cli.Main.run(Main.java:76)
at cucumber.api.cli.Main.run(Main.java:30)
at cucumber.api.cli.Main.main(Main.java:15)
Caused by: java.io.FileNotFoundException: /Users/tester/cucumber-tests/target/test-reports/cucumber (Is a directory)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.(FileOutputStream.java:213)
at java.io.FileOutputStream.(FileOutputStream.java:162)
at io.cucumber.core.plugin.PluginFactory.createFileOutputStream(PluginFactory.java:207)
... 10 more
[error] java.lang.IllegalStateException: Cucumber did not succeed and returned error =1
[error] at com.waioeka.sbt.CucumberPlugin$.$anonfun$projectSettings$6(CucumberPlugin.scala:113)
[error] at com.waioeka.sbt.CucumberPlugin$.$anonfun$projectSettings$6$adapted(CucumberPlugin.scala:88)
[error] at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error] at sbt.std.Transform$$anon$4.work(Transform.scala:67)
[error] at sbt.Execute.$anonfun$submit$2(Execute.scala:281)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:19)
[error] at sbt.Execute.work(Execute.scala:290)
[error] at sbt.Execute.$anonfun$submit$1(Execute.scala:281)
[error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error] at java.lang.Thread.run(Thread.java:748)
[error] (cucumber) java.lang.IllegalStateException: Cucumber did not succeed and returned error =1

can't run sbt cucumber when I have sbt-jacoco

I'm running jacoco as my coverage tool as part of my unit tests and that runs fine. When I then try and run my seperate cucumber tests
sbt cucumber
I am being returned the following error:
error] Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0 [error] Apr 04, 2018 2:20:33 PM com.capitalone.integration.steps.StepDefinitions_Then $jacocoInit [error] INFO: 725cd0a7 [error] Exception in thread "main" java.lang.ClassCastException: java.lang.Long cannot be cast to [Z [error] at com.capitalone.integration.steps.StepDefinitions_Then.$jacocoInit(StepDefinitions_Then.scala) [error] at com.capitalone.integration.steps.StepDefinitions_Then.<init>(StepDefinitions_Then.scala) [error] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [error] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) [error] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [error] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) [error] at java.lang.Class.newInstance(Class.java:442) [error] at cucumber.runtime.scala.ScalaBackend$$anonfun$6.apply(ScalaBackend.scala:62) [error] at cucumber.runtime.scala.ScalaBackend$$anonfun$6.apply(ScalaBackend.scala:62) [error] at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245) [error] at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245) [error] at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59) [error] at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48) [error] at scala.collection.TraversableLike$class.map(TraversableLike.scala:245) [error] at scala.collection.AbstractTraversable.map(Traversable.scala:104) [error] at cucumber.runtime.scala.ScalaBackend.loadGlue(ScalaBackend.scala:62) [error] at cucumber.runtime.Runtime.<init>(Runtime.java:91) [error] at cucumber.runtime.Runtime.<init>(Runtime.java:69) [error] at cucumber.runtime.Runtime.<init>(Runtime.java:65) [error] at cucumber.api.cli.Main.run(Main.java:35) [error] at cucumber.api.cli.Main.main(Main.java:18)

I have tried disabling the plugin, but as I am running 'sbt cucumber' it doesn't seem to be excluding for me correctly. The disabling part of my build.sbt is below.

lazy val integration = (project in file("testing/integration"))
  .enablePlugins(CucumberPlugin)
  .disablePlugins(JacocoItPlugin)
  .settings(commonSettings: _*)
  .settings(commonDependencies: _*)
  .settings(integrationSettings: _*)
  .settings(cucumberSettings: _*)
  .settings(
    name := "DATAGOVINT"
  )
  .dependsOn(development)

Is there any way around excluding coverage tools from running with the cucumber command or do I need to run the cucumber tests differently?

addSbtPlugin("com.waioeka.sbt" % "cucumber-plugin" % "0.1.6")
addSbtPlugin("com.github.sbt" % "sbt-jacoco" % "3.0.3")

^^ plugin versions

Exclude feature proposal

As already can do

sbt "cucumber -tags @my-tag"

Would be great to have

sbt "cucumber -tags-exclude @my-tag"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.