lewismj / cucumber

Cucumber Test Framework & Plugin for SBT (BDD Testing in Scala)
Other
41 stars 18 forks source link

IOException #41

Closed doncorsean closed 6 years ago

doncorsean commented 6 years ago

No matter what path I pass I get IOException. Any ideas? /tmp/json target/cucumber.json testOptions in Test += Tests.Argument(cucumberFramework,"--plugin","json:path")

cucumber.runtime.CucumberException: java.io.IOException: Failed to create directory

lewismj commented 6 years ago

@Hi,

Failed to create directory could mean that you don't have permission or that a file already exists. testOptions in Test += Tests.Argument(framework,"--plugin","json:/tmp/json")

Is what I use (this is the Runner?) If you paste in your full build.sbt. Maybe try removing any existing file that you may have there (the plugin won't delete any files)

Mike

doncorsean commented 6 years ago

Same issue. Files deleted. IOException cucumber.runtime.CucumberException: java.io.IOException: Failed to create directory /tmp/json

doncorsean commented 6 years ago

On a linux box. Permissions?

lewismj commented 6 years ago

Yes, I think it looks like a file permission issue, maybe try setting it to a folder in your home directory. See if that works?

doncorsean commented 6 years ago

target/cucumber.json is in my home folder

Also the json file gets created but I still get the IOException

doncorsean commented 6 years ago

Appreciate your prompt response btw!

lewismj commented 6 years ago

Hi, The file shouldn’t exist before running (the plugin won’t remove any files) so, are you seeing the file generated and then the error? I would maybe just create an empty directory and give yourself write permission to it and without the file being there, see if it gets generated. Maybe start by copying the example project and just change the path to your directory. Mike

lewismj commented 6 years ago

I can maybe try to reproduce if you can share anything on github, maybe the build.sbt to begin with.

doncorsean commented 6 years ago
import Dependencies._

object Dependencies {
  val cucumberVersion = "2.0.1"
  lazy val scalaTest        = "org.scalatest" %% "scalatest" % "3.0.3"
  lazy val cucumberCore     = "io.cucumber" % "cucumber-core" % cucumberVersion
  lazy val cucumberScala    = "io.cucumber" %% "cucumber-scala" % cucumberVersion
  lazy val cucumberJunit    = "io.cucumber" % "cucumber-junit" % cucumberVersion
  lazy val selenium         = "org.seleniumhq.selenium" % "selenium-chrome-driver" % "2.3.1"
  lazy val ie               = "org.seleniumhq.selenium" % "selenium-ie-driver" % "3.6.0"
  lazy val seleniumSupport  = "org.seleniumhq.selenium" % "selenium-support" % "3.6.0"
  lazy val chromeDriver     = "org.seleniumhq.selenium" % "selenium-server" % "2.48.2"
  lazy val jUnit            = "junit" % "junit" % "4.12"
  lazy val slf4j            = "org.slf4j" % "slf4j-api" % "1.7.25"
  lazy val cucumberRunner   = "com.waioeka.sbt" %% "cucumber-runner" % "0.1.5"

}
val cucumberFramework = new TestFramework("com.waioeka.sbt.runner.CucumberFramework")
lazy val root = (project in file(".")).settings(
    organization := "com.example",
    scalaVersion := "2.12.3",
    version      := "0.1.0-SNAPSHOT",
    name := "Cucumber e2e tests",
    libraryDependencies ++= {
      Seq(
          slf4j,
          scalaTest % Test,
          cucumberScala,
          selenium % Test,
          chromeDriver % Test,
          ie % Test,
          seleniumSupport % Test,
          cucumberJunit % Test,
          jUnit % Test,
          cucumberRunner
      )
    },
    testFrameworks += cucumberFramework
)

// Configure the arguments.
testOptions in Test += Tests.Argument(cucumberFramework,"--glue","")
testOptions in Test += Tests.Argument(cucumberFramework,"--plugin","pretty")
testOptions in Test += Tests.Argument(cucumberFramework,"--plugin","html:target/cucumber/html")
testOptions in Test += Tests.Argument(cucumberFramework,"--plugin","json:target/cucumber/cuke.json")
parallelExecution in Test := false
unmanagedClasspath in Test += baseDirectory.value / "src/test/features"

target/cucumber does not exist run tests

cucumber.runtime.CucumberException: java.io.IOException: Failed to create directory target/cucumber/cuke.json

cucumber folder was created with html report and cuke.json exists

lewismj commented 6 years ago

I will see if I can reproduce tomorrow morning (evening time here in S’pore) only thing I would try is just fully qualify the directory, e.g create a directory /Users/xyz/tmp or whatever and then specify it as json:/Users/... but will try to reproduce anyway.

doncorsean commented 6 years ago

Thx, have a nice evening!

lewismj commented 6 years ago

Hi, I tried to reproduce:

tangaroa:tmp lewismj$ ls /tmp/
com.apple.launchd.cVOVGAIUSh    com.apple.launchd.shtRBI59AR    powerlog
sbt:cucumber-test2> test
running tests in thread: 67
[info] NonCucumberTest:
[info] - An empty Set should have size 0
@addition
Feature: Addition
  In order to avoid making mistakes
  As a dummy
  I want to add numbers

  @addition
  Scenario: Add two variables       # Addition.feature:7
    Given a variable x with value 2 # AddAndMultiplySteps.scala:41
    And a variable y with value 3   # AddAndMultiplySteps.scala:45
    When I add x + y                # AddAndMultiplySteps.scala:53
    Then I get 5                    # AddAndMultiplySteps.scala:57

@misc
Feature: Misc
  In order to do something
  As a dummy
  I want to run stuff

  @misc
  Scenario: Test stuff # Misc.feature:7
    Given a foo        # MiscSteps.scala:37
    And a bar          # MiscSteps.scala:40
    When I foo and bar # MiscSteps.scala:44
    Then I get baz     # MiscSteps.scala:47

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

  @multiplication
  Scenario: Multiply two variables  # Multiplication.feature:7
    Given a variable x with value 2 # AddAndMultiplySteps.scala:41
    And a variable y with value 3   # AddAndMultiplySteps.scala:45
    When I multiply x * y           # AddAndMultiplySteps.scala:49
    Then I get 6                    # AddAndMultiplySteps.scala:57

3 Scenarios (3 passed)
12 Steps (12 passed)
0m0.166s

[info] com.waioeka.sbt.Spec .. passed
[info] ScalaTest
[info] Run completed in 576 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.
[info] CucumberTest
[info] Tests: succeeded 1, failed 0
[info] Passed: Total 2, Failed 0, Errors 0, Passed 2
[success] Total time: 6 s, completed 9 Nov, 2017 10:22:00 PM
sbt:cucumber-test2> 

But can't seem to get the same error, will keep trying....

lewismj commented 6 years ago

Could you try one thing:

testOptions in Test += Tests.Argument(framework,"--plugin","json:/tmp/json")

Just try putting exactly 'json:/tmp/json' say as the plugin path? Also, if you clone the repo, does the 'singleReport' test work ok for you?

Failing that, if you have a minimal example that you could upload to github, I could clone it and see if I get the same error.

doncorsean commented 6 years ago

testOptions in Test += Tests.Argument(framework,"--plugin","json:/tmp/json") was the first configuration I tried. Same issue. Let me upload so you can clone. Gimme a few min

doncorsean commented 6 years ago

https://github.com/doncorsean/cucumber-test

doncorsean commented 6 years ago

[cricketts@NCL0116882-cricketts cucumber-test]$ sbt test [warn] Executing in batch mode. [warn] For better performance, hit [ENTER] to switch to interactive mode, or [warn] consider launching sbt without any commands, or explicitly passing 'shell' [info] Loading project definition from /home/cricketts/Documents/Projects/cucumber/cucumber-test/project [info] Updating {file:/home/cricketts/Documents/Projects/cucumber/cucumber-test/project/}cucumber-test-build... [info] Resolving org.fusesource.jansi#jansi;1.4 ... [info] Done updating. [info] Compiling 1 Scala source to /home/cricketts/Documents/Projects/cucumber/cucumber-test/project/target/scala-2.10/sbt-0.13/classes... [info] Set current project to Cucumber e2e tests (in build file:/home/cricketts/Documents/Projects/cucumber/cucumber-test/) [info] Updating {file:/home/cricketts/Documents/Projects/cucumber/cucumber-test/}root... [info] Resolving jline#jline;2.14.4 ... [info] Done updating. [info] Compiling 3 Scala sources to /home/cricketts/Documents/Projects/cucumber/cucumber-test/target/scala-2.12/test-classes... running tests in thread: 41 Starting ChromeDriver 2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4) on port 20685 Only local connections are allowed. Nov 09, 2017 9:58:10 AM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: OSS SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Feature: FindCheese feature

@FindCheeseFeature Scenario: Finding some cheese # FindCheese.feature:4 Starting ChromeDriver 2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4) on port 23982 Only local connections are allowed. Nov 09, 2017 9:58:10 AM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: OSS Given I am on the Google search page # HelloCucumber.scala:26 When I search for "Cheese!" # HelloCucumber.scala:28 Then the page title should start with "cheese" # HelloCucumber.scala:33

1 Scenarios (1 passed) 3 Steps (3 passed) 0m5.972s

[info] example.FindCheeseSpec .. passed running tests in thread: 41 Starting ChromeDriver 2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4) on port 3888 Only local connections are allowed. Nov 09, 2017 9:58:16 AM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: OSS Starting ChromeDriver 2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4) on port 18396 Only local connections are allowed. Nov 09, 2017 9:58:17 AM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: OSS cucumber.runtime.CucumberException: java.io.IOException: Failed to create directory /home/cricketts/Documents/Projects/cucumber/cucumber-test/target/cucumber/cuke.json at cucumber.runtime.formatter.PluginFactory.create(PluginFactory.java:86) at cucumber.runtime.RuntimeOptions.getPlugins(RuntimeOptions.java:322) at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:311) at cucumber.runtime.Runtime.run(Runtime.java:95) at com.waioeka.sbt.runner.CucumberRunner.$anonfun$invokeCucumber$1(CucumberRunner.scala:113) at scala.runtime.java8.JFunction0$mcI$sp.apply(JFunction0$mcI$sp.java:12) at scala.util.Try$.apply(Try.scala:209) at com.waioeka.sbt.runner.CucumberRunner.invokeCucumber(CucumberRunner.scala:107) at com.waioeka.sbt.runner.CucumberRunner.runTest(CucumberRunner.scala:86) at com.waioeka.sbt.runner.CucumberRunner$$anon$3.execute(CucumberRunner.scala:129) at sbt.TestRunner.runTest$1(TestFramework.scala:76) at sbt.TestRunner.run(TestFramework.scala:85) at sbt.TestFramework$$anon$2$$anonfun$$init$$1$$anonfun$apply$8.apply(TestFramework.scala:202) at sbt.TestFramework$$anon$2$$anonfun$$init$$1$$anonfun$apply$8.apply(TestFramework.scala:202) at sbt.TestFramework$.sbt$TestFramework$$withContextLoader(TestFramework.scala:185) at sbt.TestFramework$$anon$2$$anonfun$$init$$1.apply(TestFramework.scala:202) at sbt.TestFramework$$anon$2$$anonfun$$init$$1.apply(TestFramework.scala:202) at sbt.TestFunction.apply(TestFramework.scala:207) at sbt.Tests$.sbt$Tests$$processRunnable$1(Tests.scala:239) at sbt.Tests$$anonfun$makeSerial$1.apply(Tests.scala:245) at sbt.Tests$$anonfun$makeSerial$1.apply(Tests.scala:245) at sbt.std.Transform$$anon$3$$anonfun$apply$2.apply(System.scala:44) at sbt.std.Transform$$anon$3$$anonfun$apply$2.apply(System.scala:44) at sbt.std.Transform$$anon$4.work(System.scala:63) at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228) at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228) at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17) at sbt.Execute.work(Execute.scala:237) at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228) at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228) at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159) at sbt.CompletionService$$anon$2.call(CompletionService.scala:28) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:748) Caused by: java.io.IOException: Failed to create directory /home/cricketts/Documents/Projects/cucumber/cucumber-test/target/cucumber/cuke.json at cucumber.runtime.io.URLOutputStream.ensureParentDirExists(URLOutputStream.java:53) at cucumber.runtime.io.URLOutputStream.(URLOutputStream.java:33) at cucumber.runtime.io.URLOutputStream.(URLOutputStream.java:24) at cucumber.runtime.formatter.PluginFactory.convertOrNull(PluginFactory.java:139) at cucumber.runtime.formatter.PluginFactory.instantiate(PluginFactory.java:96) at cucumber.runtime.formatter.PluginFactory.create(PluginFactory.java:84) ... 37 more

lewismj commented 6 years ago

Hi, Will be a couple of hours before I get chance, but will take a look, thanks for the link. Regards, Mike

lewismj commented 6 years ago

Hi,

If you clone https://github.com/lewismj/cucumber-test2 This should produce output without any error, though I did make the steps just throw PendingException (i.e. unimplemented) so that I could check that the framework runs correctly. This seems to work, I don't get any errors.

Maybe clone this and paste in your step implementations, I think this should work. Basically moved to a single build.sbt and put in package name etc. It seems to run through ok. If you get trouble with the steps, let me know and I'll take a look later.

I think one thing, is to look at the examples, there are two different ways to use the runner (one is to use CucumberSpec if you want a single report generated from sequentially running all your features) the other is to inherit from CucumberTestSuite, if you want a directory with the output of each test as a separate file (for output purposes this is slightly less convenient, but does allow tests to run in parallel if you have lots of them). The 'examples' directory shows the two approaches.

Anyway, I think if you clone the repo and fill in the implementation of the steps you should be fine. Let me know if you still have issues. A good starting point is to see if you get output like:

[info] Compiling 2 Scala sources to /Users/lewismj/develop/cucumber-test2/target/scala-2.12/test-classes ...
[info] Done compiling.
Feature: FindCheese

  @FindCheeseFeature
  Scenario: Finding some cheese                    # FineCheese.feature:4
    Given I am on the Google search page           # FindCheeseSteps.scala:13
      cucumber.api.PendingException: TODO: implement me
doncorsean commented 6 years ago

CucumberTestSuite trait was borking it, removed and no exception. Many thx for your time :)

lewismj commented 6 years ago

No worries. The CucumberTestSuite is used to define a test that runs in parallel. The CucumberSpec is for when you want a consolidated report.

If you inherit the suite (and provide the overrides) each suite will run in parallel and output to its own sub-folder. That can be useful if you have a big set of tests.

The examples folder in the runner shows the two different approaches.

doncorsean commented 6 years ago

I had the override in there and sub folders were being created but json was a sibling to those folders not within them

lewismj commented 6 years ago

Thanks, I'll take a look. In the future, I may see if its possible to stitch together the individual test output and run all tests as parallel.