How to execute .feature file in cucumber - 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.

Related

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

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"},

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.

Rubymine is not able to find a step definition, located inside a gem

Rubymine returns an alert of "Undefined step reference" for the two steps of this scenario. This cucumber test is like this:
#smoke
Scenario: Update profile Smoke test.
Given I navigate to this test webpage
And In Test, I click the element of "test_link"
This 2 steps are located inside a gem, following this structure:
gemname/lib/features/step_definitions/web_shared_steps.rb
And (/^I navigate to this (.*?)$/) do |web|
web = '$' + web.downcase.gsub(' ', '_')
#browser.goto eval(web)
end
Then (/In (.*?), I click the element of "(.*?)"$/) do |page, element|
on_page(page + 'Page').click_element(element)
end
And the methods are also in the gem, following this structure:
gemname/lib/basic_methods.rb
module BasicMethods
include PageObject
include PageObject::PageFactory
def click_element (element)
element = element.downcase.gsub(' ', '_')
wait_until{send("#{element}?")}
select = send("#{element}_element")
wait_until{select.visible?}
select.click
end
So, If I execute with the command line "bundle exec cucumber", the test is able to find the step definitions in the gem, and the methods in the gem, and everything is executed correctly.
But, Rubymine is still giving an alert of "Undefined Step reference" for the two steps of the scenario, and I am unable to "command click" in those steps in order to navigate to the step definition.
QUESTION: Since the test in working, how is possible to "tell" Rubymine the folder/location where it has to search for the step definitions?
I don't have Rubymine so I can't verify this answer but it sounds very similar to a problem I had with Syntastic under Vim.
Try creating a file called features/support/external.rb containing:
require "lib/features/step_definitions/web_shared_steps.rb"
Actually it doesn't have to be called external.rb, it can be called anything except env.rb.
I'm guessing that Rubymine is calling cucumber with the --dry-run option to generate its warnings. See this answer for details.
try putting the gem source on your machine and then add this to your gemfile
gem 'gem', :path => 'path/to/gem-source'
I've had a similar problem with trying to use my own fork of a gem
When i did gem 'my-gem', :git => 'my-repo.git' i had the same problem as you, but by using :path I got rubyMine to recognise my step definitions.
I need to switch back to :git in production but at least i have a solution for my dev environment

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.

Is there a way to run a single cucumber feature file on autotest?

I'd like to run just a single cucumber feature file on autotest. I'd like the test to be run, report failures, then run again as soon as I save a change to my code base. Anyone know a way to do this?
--Jack
I found a solution myself:
Watchr - https://github.com/mynyml/watchr
It watches whenever you save specified files and runs specified tests at that point. Uses pattern matching.

Resources