Cucumber Predefined steps usage - cucumber

I have a project where I have written some per-defined steps and implemented.
Now I like to use the per-defined steps in another project in eclipse. Kindly let me know how could I do that?

Cucumber only knows how to read and execute your feature files because of the step definition files usually defined with in a steps directory. That is where your feature statements are captured by regular expressions and translated to Java code
The steps Cucumber will search for just live in a package, or a sub-package from the runner.
Suggestion would be to copy the step definitions from Project 2 into your steps directory in Project 1.
Also there is way to re-use steps is therefore to package the steps in a jar and add that jar as a dependency. You can use Maven for creating the jar.

Related

How to output karate test results to custom folders instead of target?

We recently started using karate for API testing in our project and we are using Executable Jar File with visual studio plugin for karate. Currently We are not using any test runner classes or Junit in our framework and still able to achieve almost everything by usage of tags and karate-config.js file. We are using both cucumber-html report and surefire-report plugins and results generated at target folder on execution.
Now we are looking to customize the outputs to different folders. I assume we could use the reportDir() parameter to set the output folder path. Can someone please advice is it achievable in Executable Jar version and without Junit framework? If possible, where can I set this path in our tests? Do I need to create a test runner class for this ?
Can you please start evaluating the RC version, details here: https://github.com/intuit/karate/wiki/1.0-upgrade-guide
You should be able to set a different "output" folder using the command-line -o or --output flag.
Based on your feedback, we can improve it.

how to access steps available in other cucumber project in current cucumber project

Please help me understand accessing steps available in other cucumber projects in current cucumber project.
i have tried glue option as well and i also have added other cucumber project jar file in maven dependencies but could not make it work.
Below is the feature file of project1:
Feature: To test cucumber test is running
I want to run a sample feature file.
Scenario: cucumber setup
Given sample feature file is ready1
When I run the feature file1
Then run should be successful1
Scenario: cucumber setup for cucmbertestautomation2
Given sample feature file is ready2
When I run the feature file2
Then run should be successful2
"Given sample feature file is ready2" step is available in project2.
and project1 (cucumbertestautomation1) POM have project2(cucumbertestautomation2) as dependency:
com.celcom
cucumbertestautomation2
0.0.1-SNAPSHOT
Still the step "Given sample feature file is ready2" is not recognized which is there in the project2 (cucumbertestautomation2) which is added as dependency.
The steps Cucumber will search for just live in a package, or a sub-package from the runner.
If you have steps from somewhere else, added as a dependency through a jar or similar, then these steps will be found.
They way to re-use steps is therefore to package the steps in a jar and add that jar as a dependency. You can use Maven for creating the jar.
Cucumber only knows how to read and execute your feature files because of the step definition files usually defined with in a steps directory and called something like step_definitions.rb That is where your feature statements are captured by regular expressions and translated to Ruby code.
My suggestion would be to include the step definitions from Project 2 into your steps directory in Project 1.

Gradle Project Dependencies - As Shared Projects or JAR's?

So basically we have a project structure like below:
C:\Projects\Eclipse\Workspace->
afbEJB
rmcEJB
rmbEJB
**bridgesClient**
**sharedApp**
**framework**
**commonApp**
The ones marked in bold are standard java projects which are dependencies for the first 3 EJB projects. These standard projects are not built as JAR'rather actual projects so I am guessing in order to build EJB projects I would have to use ':Project' syntax.
Questions:
I was not able to refer to the standard projects without first creating settings.gradle file.
I had to create build.gradle file in all of the standard projects as well as the EJB projects. Why is there a mandate for creating gradle files in dependent projects as well? Cant the root project build it when it finds the project dependencies as part of the dependencies {...} ? that way there would be less number of build.gradle files in the entire workspace.
I think a better way around this would be to create JAR's for the standard projects and refer them as compile fileTree(dir: 'dir-where-jar-are-stored')?
What do you guys think?
Thanks,
Yogendra
ad 1) Yes, a settings.gradle is required for multi-project builds.
ad 2) It isn't necessary to create multiple build scripts. If you prefer, you can configure all projects from a single build script. Often, a mixture of these styles is used (configure commonalities from root script, remainder from subproject scripts).
ad 3) In general, I wouldn't turn the projects into separate builds, as this would complicate matters for build users. In particular, they'd have to execute multiple builds, and in the right order.
To learn more about multi-project builds, check out the "multi-project builds" chapter in the Gradle User Guide, and the many sample builds in the full Gradle distribution.

Packaging a Groovy application

I want to package a Groovy CLI application in a form that's easy to distribute, similar to what Java does with JARs. I haven't been able to find anything that seems to be able to do this. I've found a couple of things like this that are intended for one-off scripts, but nothing that can compile an entire Groovy application made up of a lot of separate Groovy files and resource data.
I don't necessarily need to have the Groovy standalone executable be a part of it (though that would be nice), and this is not a library intended to be used by other JVM languages. All I want is a simply packaged version of my application.
EDIT:
Based on the couple of responses I got, I don't think I was being clear enough on my goal. What I'm looking for is basically a archive format that Groovy can support. The goal here is to make this easier to distribute. Right now, the best way is to ZIP it up, have the user unzip it, and then modify a batch/shell file to start it. I was hoping to find a way to make this more like an executable JAR file, where the user just has to run a single file.
I know that Groovy compiles down to JVM-compatible byte-code, but I'm not trying to get this to run as Java code. I'm doing some dynamic addition of Groovy classes at runtime based on the user's configuration and Java won't be able to handle that. As I said in the original post, having the Groovy executable is included in the archive is kind of a nice-to-have. However, I do actually need Groovy to be executable that runs, not Java.
The Gradle Cookbook shows how to make a "fat jar" from a groovy project: http://wiki.gradle.org/display/GRADLE/Cookbook#Cookbook-Creatingafatjar
This bundles up all the dependencies, including groovy. The resulting jar file can be run on the command line like:
java -jar myapp.jar
I've had a lot of success using a combination of the eclipse Fat Jar plugin and Yet Another Java Service Wrapper.
Essentially this becomes a 'Java' problem not a groovy problem. Fat Jar is painless to use. It might take you a couple of tries to get your single jar right, but once all the dependencies are flattened into a single jar you are now off an running it at the command line with
java -jar application.jar
I then wrap these jars as a service. I often develop standalone groovy based services that perform some task. I set it up as a service on Windows server using Yet Another Java Service and schedule it using various techniques to interact with Windows services.

Creating own groovy library

Do anyone have an idea whats the best way of creating an own library for groovy.
I have several methods which i just dont want copy and paste into all my groovy scripts.
The perfect solution would be to do it by an
import myownmethods
How to create the library myownmethods.jar?
Thanks for any answer and solution
Cheers
The simplest method is to compile your groovy files with groovyc and then package them into a jar file with jar. For example:
groovyc -d classes myclasses.groovy
jar cvf myclasses.jar -C classes .
I'd also consider looking at gradle. To get started, you can use a build.gradle containing just:
apply plugin: 'groovy'
Then put your source files in a subdirectory called src/main/groovy and run gradle jar. It will build your source files into a jar file in build/libs.
You should follow the same process that you would for a Java library, i.e.
Create a project for the code
Configure your favorite build tool (Ant, Maven, etc.) to build a JAR for that project
Put the JAR somewhere where other projects can find it. If you're using a tool like Ivy or Maven that does dependency management you'll likely want to deploy it to a repository. Otherwise, you can probably just put it somewhere in source control †
Projects that depend on this library should either load it from the repository (if using dependency management), or have it copied into their lib directory (if not) †
† I know this sucks, but I can't remember how I used to manage dependencies without using a dependency management tool

Resources