Situation:
In my current project we are running all kinds of different JBehave stories. Every ".story" file is related to a product and a flow.
Example:
xyz-cellphone-call.story would be the story describing making a phonecall with a cellphone.
xyz-phone-call.story would be the story describing making a phonecall with a fixed-line phone.
xyz-cellphone-browse.story would be the story describing browsing the internet with a cellphone.
My question:
In Jbehave you can add metaFilters to filter on the stories based on meta tags. Assume the tags are #product & #action. (#product cellphone, #action call).
Would it be possible to pass a filter to run the JBehave stories concerning both the phone & cellphone stories, if yes, what would be the syntax?
I've tried adding the following filters (none of which work):
+product cellphone +product phone
+product cellphone|phone
+product cellphone,phone
Same for actions.
Is it possible to filter on multiple meta-tags?
Yes it is possible.
In the API docs you will find this information:
A filter is uniquely identified by its String representation which is
parsed and matched by the MetaFilter.MetaMatcher to determine if the
Meta is allowed or not.
The MetaFilter.DefaultMetaMatcher interprets the filter as a sequence
of any name-value properties (separated by a space), prefixed by "+"
for inclusion and "-" for exclusion. E.g.:
MetaFilter filter = new MetaFilter("+author Mauro -theme smoke testing
+map *API -skip"); filter.allow(new Meta(asList("map someAPI")));
The use of the MetaFilter.GroovyMetaMatcher is triggered by the prefix
"groovy:" and allows the filter to be interpreted as a Groovy
expression.
MetaFilter filter = new MetaFilter("groovy: (a == '11' | a == '22')
&& b == '33'");
So probably if you play with the conditions, you will get your run configuration customized.
Try this example:
mvn clean install -P -Djbehave.meta.filter="myCustomRunConf:(+product && +action)"
More info amout the MetaFilter class in the API docs:
http://jbehave.org/reference/stable/javadoc/core/org/jbehave/core/embedder/MetaFilter.html
I guess there is easier solution for you using groovy
http://jbehave.org/reference/stable/meta-filtering.html
In your case it would be
-Dmetafilter="groovy: "product=='cellphone' && action=='call'"
I tried it as "-Dmetafilter=groovy:t2 && t3" for this feature file
Meta:
#t1
Narrative:
As a user
I want to blah-blah-blah
Scenario: test 1
Meta:
#t2
Given I am on home page
Scenario: test 2
Meta:
#t2
#t3
Given I am on home page
Scenario: test 3
Meta:
#t3
Given I am on home page
Only test 2 scenario is executed in this case
How about:
mvn clean install -P -Djbehave.meta.filter = "+product cellphone&&phone"
Related
I have a scenario, where I need to run multiple tags and need not run another one when a condition occurs. I don't want to run Feature_1 when the browser is IE.
#run_me #do_not_run
Feature 1
#Tag1 #Tag2
Scenario: Scenario 1
#run_me
Feature 2
#Tag1 #Tag3
Scenario: Scenario 2
Condition:
if(browser == "IE"){
then execute all #run_me tags but don't execute it when there is #do_not_run
else
run all #run_me
Current code:
--tags #run_me
What should be the right way to achieve it?
Note:
I tried --tags #run_me ~#do_not_runinside the if condition. But not sure it is the correct method or not.
You can follow below approach to execute the tags.
#fast -- Scenarios tagged with #fast
#wip and not #slow -- Scenarios tagged with #wip that aren’t also tagged with #slow
#smoke and #fast -- Scenarios tagged with both #smoke and #fast
#gui or #database --Scenarios tagged with either #gui or #database
Reference Link
I work with JBehave on a daily basis, but have been tasked with working on a project that uses Cucumber. In order to add a custom reporting class functionality to that project, I need to add two steps, one at the start of the feature (story) and another at the start of the scenario. I merely want to pass to the application a description of the feature/story and the scenario to be passed to the reporting module. I know that cucumber can access the scenario name through code, but that would only resolve one of the two lines - I would still need to have another one that passes the description of the feature/story.
What I've tried in the feature file:
Feature: Ecolab BDD Test Automation Demo
Scenario Outline: User can login and logout from the landing page
Given story "EcolabWebDemo_TestCases - Ecolab BDD Test Automation Demo"
Given scenario "User can login and logout from the landing page"
Given I am on the Ecolab landing page
The corresponding code for the two added Given statements at the beginning above:
#Given("^story {string}$") // \"(\\S+)\"
public void givenStory(String storyName) {
test.initStory(storyName); // will show on report in Features column
}
#Given("^scenario {string}$") // \"(\\S+)\"
public void givenScenario(String scenarioName) {
test.initScenario(scenarioName);
}
The commented regex patterns afterwards are the suggested ones I should try but do not seem to work either.
The current configuration at least seems to "find" the steps but reports:
cucumber.runtime.CucumberException:
java.util.regex.PatternSyntaxException: Illegal repetition near index
13 ^the scenario {string}$
So that's obviously not the solution. The regex used instead of {string} simply does not find a match and does not run.
regex is absolute Greek to me, not sure why it can't just be simple like the {string} option implied it would be in the cucumber documentation. I've been searching on-line for guidance for the better part of two days to no avail, I'm apparently not even sure what to be searching for.
Based on Grasshopper's suggestion, I updated the version of Cucumber from 1.2.0 to 1.2.5. I was prepared to change the pom.xml to use the 3.x versions but tried the latest of the specified libraries first, and it did report after an attempted run what the correct regex should be for the two steps I added.
#Given("^story \"([^\"]*)\"$")
and
#Given("^scenario \"([^\"]*)\"$")
Now that the project has a version that seems to recognize strings and also reports the missing steps, the project now runs as intended.
Thanks for your help, Grasshopper.
We're looking to better manage test data using Cucumber in our Java test automation framework. For a Scenario Outline, we're looking to tabulate test parameters categorized by the applicable environment in which they will run.
For example,
Scenario Outline: Login into application
Given I am on the homepage in the <environment>
When I enter my <user>
And I enter my <pass>
Then I am taken to the homepage
Examples:
|user |pass |environment|
|test |test1 |local |
|retest |retest1 |sit |
|prodtest|prodtest1|production |
So, when the above scenario is executing in, for example, the SIT environment, only the 2nd example will be picked up, and not the first and third.
Can this level of execution be accomplished?
You can get this done by splitting up your examples table into two and using tags on them... Then run the test with the tags to filter in cucumberoptions.
#others
Examples:
|user |pass |environment|
|test |test1 |local |
|prodtest|prodtest1|production |
#sit
Examples:
|user |pass |environment|
|retest |retest1 |sit |
That is not what scenario outlines are designed for.
You can write separate scenario's and then use tags on each one that you can then pass in at runtime which tag you want to run.
So we have tests that look like this:
Scenario: XXX- 9056: Change password to special characters
Meta:
#Regression
#ticket #5732
#skip
Given a customer with the following properties:...
we put the #skip there whenever we are still working on it or we know it will not work properly.
We want to get Serenity reports, but we don't want it to include skipped stories. How can we exclude them from being reported?
We found our issue was that in the Scenario line some of our test cases looked like
Scenario: XXX-#9056: Change password to special characters
Instead of
Scenario: XXX- 9056: Change password to special characters
So having the pound symbol(#) on the line with Scenario was messing it up. It doesn't matter if it is under the meta tag. Now none of the skipped test are showing in the report.
I'm planning to build an application which would crawl a part of a local filesystem (a subtree) in a depth-first-search manner and process all files it finds, except for some configurable exceptions.
To give an example, let's say I have a directory structure like this:
> documents
- generic-doc.txt
> mails
- mail-01.txt
- mail-02.txt
- mail-03.txt
> unread
- mail-04.txt
> invoices
> paid
- invoice-01.pdf
- invoice-02.pdf
> unpaid
- invoice-03.pdf
I also have an exclusion rule like this:
exclude = "documents/mails/unread | documents/invoices"
Given these data on input, my application would process the following documents:
generic-doc.txt
mail-01.txt
mail-02.txt
mail-03.txt
(e.g. it would process all files, except for those located in the documents/mails/unread and documents/invoices folders)
In future, I might need to implement various forms of exlusion rules.
What is the best way to test the implementation of the crawling module (e.g. that when given an exclusion rule, the module would return the correct set of documents)? Can it be done without using a real filesystem?
Extract the exclusion ruling to a separate module/class/object and test that in isolation. Then make sure, that your crawler asks the ExclusionRule before processing a file.
A sketch
public interface FileExcluder {
boolean isExcluded(File aFile);
}
Note that there is already the FileFilter that provides a similar service, maybe you can reuse that abstraction.
If you are using Java 7 you can create a dummy Filesystem. (Assuming you are using that)
You can create an interface which can be mocked out for all file handling operations but it's likely to be much simpler to create test files and test those (and delete them when finished)