How to set path of step Definition file , if my feature file ,stepDefinition file and runner file resides in separate folders? - cucumber

I am using maven project for cucumber execution and below is my project explorer view.
Project Explorer
I want to instruct "SimpleDataDriverRunner.java" file to execute "SimpleDataDriverStepDefinition.java" class. Both these files are present in different folder structure (as shown in image above).
Below is my runner class
#RunWith(Cucumber.class)
#CucumberOptions(
features="dir path\\com\\features\\SimpleDataDriven.feature",
glue= {"stepDefinition"},
monochrome=true
)
Can someone please guide me how to achieve this and if this is correct way to deal with multiple runner file and step definition files ?
If there is any BDD cucumber sample project having multiple feature, step Definition and runner files is much appreciated .

I never understood why multiple runners are needed, if is just to run different scenarios it doesn't seem very efficient.
I would use just one runner and select what to run by tags.
Annotate your feature with some tag like #someTag and run it.
E.g.:
mvn test -Dcucumber.filter.tags="#someTag"
From cucumber documentation:
cucumber.features= # command separated paths to feature files. example: path/to/example.feature, path/to/other.feature
cucumber.glue= # comma separated package names. example: com.example.glue
Try adding in glue the package for runners also:
glue= {"stepDefinition", "runner"},

Related

File Transform task fails to transform XML configurations on zipped package

I'm working on Release pipeline, which will perform transformation on App Service Worker configs, then will publish workers + web application.
My input package is a zip package produced out of MsBuild publish (from ASP.NET build pipeline).
...\PackageTmp\app_data\jobs\triggered\BillingWorker\App.Prod.config
...\PackageTmp\app_data\jobs\triggered\BillingWorker\App.Test.config
...\PackageTmp\app_data\jobs\triggered\BillingWorker\BillingWorker.exe.config
...\PackageTmp\app_data\jobs\triggered\EtlWorker\App.Prod.config
...\PackageTmp\app_data\jobs\triggered\EtlWorker\App.Test.config
...\PackageTmp\app_data\jobs\triggered\EtlWorker\EtlWorker.exe.config
...\PackageTmp\Web.config
...\PackageTmp\Web.Test.config
...\PackageTmp\Web.Prod.config
...\PackageTmp\many other files
Transformation of Web.config is done correctly by Publish to Azure Web App task. However, workers configs aren't transformed automatically, so I added a File Transform task with following config:
This step doesn't work and here is the output:
2019-08-14T15:41:01.1435779Z ##[section]Starting: File Transform: config
2019-08-14T15:41:01.1576716Z ==============================================================================
2019-08-14T15:41:01.1576853Z Task : File transform
2019-08-14T15:41:01.1576932Z Description : Replace tokens with variable values in XML or JSON configuration files
2019-08-14T15:41:01.1576994Z Version : 1.156.0
2019-08-14T15:41:01.1600786Z Author : Microsoft Corporation
2019-08-14T15:41:01.1600885Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/file-transform
2019-08-14T15:41:01.1600986Z ==============================================================================
2019-08-14T15:41:01.6339900Z ##[warning]Unable to apply transformation for the given package. Verify the following.
2019-08-14T15:41:01.6351367Z ##[warning]Unable to apply transformation for the given package. Verify the following.
2019-08-14T15:41:01.8369297Z Initiated variable substitution in config file :
...
... many lines about variable subsitution
...
This output looks wrong, as it produces warning without declared explanation. How to workaround this warning?
The problem is that File Transform task strongly relies on names of both files - the one being transformed and the one containing transformation rules. Strict naming convention is required which can be described in following words:
A template named Name.xml can be transformed only by files named Name.Debug.xml, Name.Release.xml, and more general - Name.{anything-here}.xml.
What's happening here is that App.config file is renamed to {YourApplicationName}.exe.config during build thus the tranformation using App.Debug.config fails.
I see 2 workarounds:
1. Preserve the original name App.config
a. In a project file, set App.config file's property to Copy to output directory: Copy always
b. Setup "File Transform task" with args -transform *.Debug.config -xml *.config -result {YourApplicationName}.exe.config
c (optional). If you didn't specify -result in task, you need to setup another task to rename App.config to {YourApplicationName}.exe.config after the transformation has finished (for example a Command Line task with command copy App.config {YourApplicationName}.exe.config /Y)
2. Write custom transformator script
a. Unzip package into temp folder
b. Transform file using Powershell (make use of Microsoft.Web.XmlTransform.dll installed on agent)
c. Zip again and replace the original zip.
The native step in the official task doesn't support transformation in zip files. You can use another task for do it before the deploy task.
I used this and it worked fine to me:
https://marketplace.visualstudio.com/items?itemName=solidify-labs.vsts-task-tokenize-in-archive

Python cx_freeze Create dirs for included files in build

Is it possible to create dirs(folders) on cx_freeze build output, cause i include(include_files) many databases files and i want these to be in specific folder etc. I can take them easily from my folders.....
"include_files": ["databases/nations.txt","databases/newafrica.txt",
"databases/neweeurope.txt","databases/neweurope.txt","databases/newmeast.txt","graph.py",
"databases/newnamerica.txt","databases/plates.txt",
"databases/ACN/rigidA.txt","databases/ACN/rigidB.txt",
"databases/ACN/rigidC.txt","databases/ACN/rigidD.txt","databases/ACN/flexibleA.txt",
"databases/ACN/flexibleB.txt","databases/ACN/flexibleC.txt",
"databases/ACN/flexibleD.txt","alternates.xlsx",
but this will just copy all of them in exe build dir and its a mess.
Thanks in advance.
There are several ways you can go around solving the problem.
Method 1 - Using include_files
Rather than ask for each individual text file you could just put the file name in the setup script and leave out the individual text files. In your case it would be like this:
"include_files": ["databases"]
This would copy the entire databases folder with everything in it into you build folder.
Absolute file paths work as well.
If you are going to use the installer feature (bdist_msi) this is the method to use.
You can copy sub folders only using "include_files": ["databases/ACN"]
Method 2 - Manually
Ok it's rather un-pythonic but the one way to do it is to copy it manually into the build folder.
Method 3 - Using the os module
Much the same as method two it would copy the folder into your build folder but instead of coping it manually it would use Python. You also have the option of using additional Python features as well.
Hope I was helpful.

Access test resources within Haskell tests

This is probably a basic question but I've been Googling for a while on it... I have a Cabal-ized Haskell project and I'm in the process of writing integration tests for it. I want to be able to include test resources for my project in the same repo and access them in tests. For example, here are a couple things I want to accomplish:
1) Check a dummy database instance into my repo, including a shell script that spins up a database process. I want to write an Hspec integration test that spins up the database process, makes some calls to it, and then shuts it down. So I need to be able to find the shell script so I can use System.Process.createProcess on it.
2) Check in paired "input" and "output" files. My test should process each of the input files and compare them to a corresponding output file to make sure they match. (I've read about "golden" but it doesn't seem to solve the problem of finding/reading the input files in the first place?)
In short, how can I go about creating a "resources" folder in the root folder of my Haskell project and find the path to it inside tests?
Have a look at an existing project that uses input and output file.
For example, take haddock, the source code is at https://github.com/haskell/haddock. They have the test files under a folder (https://github.com/haskell/haddock/tree/master/html-test/ref) and they are referenced as extra-source-files in the cabal file (https://github.com/haskell/haddock/blob/master/haddock.cabal). Then the test code (https://github.com/haskell/haddock/blob/master/html-test/run.lhs) uses some CPP macro (__FILE__) to get the current directory, and can then resolve the files relative to that folder.

Read file from Jenkins workspace with System groovy script

I have a question very similar to this: Reading file from Workspace in Jenkins with Groovy script
However I need to read the file from a System Groovy script so the solution of using Text-finder or the Groovy PostBuild plugin will not work.
How can I get the workspace path from a system groovy script? I have tried the following:
System.getenv('WORKSPACE')
System.getProperty("WORKSPACE")
build.buildVariableResolver.resolve("WORKSPACE")
Thanks!
If you have a file called "a.txt" in your workspace, along with a script called "sysgvy.groovy" that you want to execute as a system groovy script. Suppose your "sysgvy.groovy" script needs to read the file "a.txt".
The issue of this topic is that if your script read "a.txt" directly without providing any path, "sysgvy.groovy" executes and will throw an error saying cannot find "a.txt".
I have tested and found that the following method works good.
def build = Thread.currentThread().executable
Then use
build.workspace.toString()+"\\a.txt"
as the full location string to replace "a.txt".
It's also important to run on the Jenkins master machine by placing "a.txt" and "sysgvy.groovy" onto Jenkins master machine's workspace. Executing on slave machine does not work.
Try it, the file should be found and get read in the script without any problem.
If there is problem with variable Thread, it is just that some modules need to be imported. So add these lines to the start of code:
import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*
Each build has a workspace, so you need to find the desired project first. (The terms "job" and "project" are used rather interchangeable in Jenkins - also in the API.)
After that, you can either cross your fingers and just call getWorkspace(), which is deprecated (see JavaDoc for details).
Or you can find a specific build (e.g. the last), which can give you the workspace used for that specific build via the getWorkspace() method as it is defined in the AbstractBuild class.
Example code:
Jenkins.instance.getJob('<job-name>').lastBuild.workspace;
Just use
build.workspace
The "build" variable is available keyword in System Groovy Script.

How to execute .feature file in cucumber

I am a beginner to Cucumber. I have installed cucumber by the help of internet. I have written a .feature file. But I don`t know where to place this file and how to execute it.
Because it wants you to succeed in BDD, cucumber will guide you through the process. From the project directory, type cucumber in the cmd prompt or terminal, which returns:
You don't have a 'features' directory. Please create one to get started.
Create a features directory, and put your .feature file in it. Again, run cucumber, which returns pending step definitions that map to your feature file. As an example:
You can implement step definitions for undefined steps with these snippets:
Given /^I want to use cucumber$/ do
pending # express the regexp above with the code you wish you had
end
Now--as #siekfried indicates--create a directory called features/step_definitions for your step definition files, which should end with _steps (e.g. example_steps.rb). Then, edit your step definition file with the appropriate code to execute the step.

Resources