How to ensure Cucumber doesn't print skipped steps? - cucumber

I have a long Cucumber scenario with only a few steps implemented, and many steps are pending. In my set up, Cucumber skips all pending steps, but still prints all the names of those skipped tests in the output, and that makes it tedious to scroll up to find the step where the scenario failed.
How can I make sure the skipped steps are not printed in the output? Ideally, I want the output to show all passing steps and the last failed step.

I think there is no out of the box formatter that does exactly that. You would need to create a custom one but perhaps you could use the progress formatter. It prints information about the failed steps, green dots for the passing steps and dashes for the skipped ones:
>> cucumber --format progress
..............................F-
(::) failed steps (::)
"Error messages here"
Failing Scenarios:
cucumber features/dashboard.feature:13 # Scenario: Dashboard data is loaded
4 scenarios (1 failed, 3 passed)
26 steps (1 failed, 1 skipped, 24 passed)
0m41.604s
Also you can combine different formatters. One to give its output in the console and others to output its format in different files for later inspection. for example:
$ cucumber -f progress -f pretty --out results.txt -f rerun --out rerun.txt

Related

Queue SLURM jobs to run X minutes after each other

I have been trying to search around for an example of how to use the following option for job dependencies, -d, --dependency=<dependency_list>.
In the documentation, the syntax is shown to be after:job_id[[+time][:jobid[+time]...]]
But I am unable to find any examples of this, and to be honest I find the presentation of the syntax confusing.
I have tried sbatch --dependency=after:123456[+5] myjob.slurm and sbatch --dependency=after:123456+5 myjob.slurm, but this yields the error
sbatch: error: Batch job submission failed: Job dependency problem.
How can I add a dependency to Job B so that it starts X minutes after Job A starts?
The square brackets [...] indicate an optional parameter value and should not appear in the actual parameter value. Try with
sbatch --dependency=after:123456+5 myjob.slurm
With guidance from damienfrancois to exclude the brackets, I tried the following
sbatch --dependency=after:123456:+5 myjob.slurm
Which seems to work beautifully, listing it in the queue as dependent.
EDIT: This is for version 19.05.07

Is it possible to change a job ID to something human-readable?

I'd like to send myself a text when a job is finished. I understand how to change the job name so that the .o and .e files have the appropriate name. But I'm not sure if there's a way to change the job ID from a string of numbers to a specified key so I know which job it is. I usually have a lot of different jobs going at once, so it's difficult to remember all the different job ID numbers. Is there a way in the .pbs script to change the job ID so that when I get the message I can see which job it is rather than just a string of numbers?
If you are using Torque and add the -N flag, then you can add a name to the job. It will still use the numeric portion of the job id as part of the output and error filenames, but this allows you to add something to help you distinguish among your jobs. For example:
$ echo ls | qsub -N whatevernameyouplease

Bash Script Efficient For Loop (Different Source File)

First of all i'm a beginner in bash scripting. I usually code in Java but this certain task requires me to create some bash scripts in Linux. FYI i've already made a working script but I think its not efficient enough because of the large files I'm dealing with.
The problem is simple I have 2 logs that I need to compare and make some correction on one of the logs... ill call it logA and logB. This 2 logs contains different format here is an example:
01/04/2015 06:48:59|9691427842139609|601113090635|PR|30.00|8.3|1.7| <- log A
17978712 2015-04-01 06:48:44 601113090635 SUCCESS DealerERecharge.<-log B
17978714 2015-04-01 06:48:49 601113090635 SUCCESS DealerERecharge.<-log B
As you can see there is a gap in time stamp. The actual logs that will match with log A is the one with the ID 17978714 because it is the closest time from it. The highest time gap I've seen is 1 minute. I cant use the RANGE logic because if there are more than one line on log B that is within the 1 minute range then all of the line will show in my regenerated log.
The script I made contains a for loop which iterate the timestamp of log A until it hits something in log B (The first one it hits is the closest)
Inside the for loop I have this line of code which makes the loop slow.
LINEOUTPUT=$(less $File2 | grep "Validation 1" | grep "Validation 2" | grep "Timestamp From Log A")
I've read some sample using SED but the problem is I have 2 more validation to consider before matching it with the time stamp.
The validation works as a filter to narrow down the exact match for log A and B.
Additional Info: I tried doing some benchmark test for the script I made by performing some loop. One thing I've noticed is that even though I only use 1 pipe for that script the loop tick is still slow.

How to skip Cucumber steps?

I have the scenario like:
Given I go to this page
When I type cucumber
And I click
Then I should see the text
And I should not see the line
If I run this scenario it will execute all the 5 steps. But I want to skip the 4th step (Then I should see the text) and execute the 5th step.
Please give me your suggestions. Thanks in advance. :)
TL;DR - don't do it - you're (probably) getting it wrong. And you can't (easily) do it. As Aslak wrote (one of Cucumber main creators):
A step can have the following results:
undefined (no matching stepdef)
pending (a matching stepdef that throws PendingException)
passed (a matching stepdef that doesn't throw anything)
failed (a matching stepdef that throws an exception that isn't PendingException)
skipped (a step following a step that threw any exception (undefined, pending or failed))
What you're asking for is a new kind of result - ignored. It could be
implemented by throwing an IgnoredException. This would mean that
skipped would have to be changed to: (a step following a step that
threw any exception (undefined, pending or failed) - unless the
exception was IgnoredException)
I'm not sure I like this. It sounds like more complicated than it
needs to be. You already have the necessary information that something
is amiss - your step will either fail or be pending. I don't see the
value in continuing to execute the following steps. You still have to
implement the failing/pending step.
As long as you're reminded that "there is work to be done here" I
don't think it's wortwhile complicating Cucumber to tell you what kind
of work needs to be done...
Aslak
Whole discussion is here: http://comments.gmane.org/gmane.comp.programming.tools.cucumber/10146
I have had to skip steps conditionally based on environments. I used next to skip steps. Here is an example on how to do what you wanted.
Then /^I should see the text/$ do
next if #environment == 'no text'
...
<The actual step definition>
...
end

cucumber features --guess

I'm setting up my Authlogic user session features.
And I'm in some kind of confusion.
When I run:
cucumber features
I get some red errors
Scenario: User signs in successfully # features/user_sessions.feature:21
Given a user exists with login: "sachin", password: "secret" # features/step_definitions/pickle_steps.rb:4
When I go to the login page # features/step_definitions/webrat_steps.rb:15
And I login as "sachin" with password "secret" # features/step_definitions/user_session_setps.rb:5
Then I should see "Login successful" # features/step_definitions/webrat_steps.rb:123
And I should be logged in # features/user_sessions.feature:26
Ambiguous match of "I should be logged in":
features/step_definitions/pickle_steps.rb:55:in `/^((?:(?:I|myself|me|my)|(?:(?:a|an|another|the|that) )?(?:(?:(?:(?:first|last|(?:\d+(?:st|nd|rd|th))) )?(?:user))|(?:(?:user)(?::? "(?:[^\"]|\.)*"))))) should (?:be|have) (?:an? )?((?:duplicable|readonly|nil|store[_ ]full[_ ]sti[_ ]class|new[_ ]record|equal|present|eql|marked[_ ]for[_ ]destruction|valid[_ ]password|valid[_ ]with[_ ]callbacks|logged[_ ]in|valid[_ ]without[_ ]callbacks|respond[_ ]to[_ ]without[_ ]attributes|valid|logged[_ ]out|respond[_ ]to|instance[_ ]variable[_ ]defined|admin|blank|changed|tainted|unserializable[_ ]attribute|locking[_ ]enabled|has[_ ]role|instance[_ ]of|partial[_ ]updates|kind[_ ]of|attribute[_ ]present|is[_ ]a|frozen|invalid|acts[_ ]like|method[_ ]exists|has[_ ]attribute|disable[_ ]perishable[_ ]token[_ ]maintenance|is[_ ]haml|id|created[_ ]at|updated[_ ]at|login|crypted[_ ]password|password[_ ]salt|persistence[_ ]token|login[_ ]count|last[_ ]request[_ ]at|last[_ ]login[_ ]at|current[_ ]login[_ ]at|last[_ ]login[_ ]ip|current[_ ]login[_ ]ip|roles|first[_ ]name|last[_ ]name|perishable[_ ]token|email))$/'
features/step_definitions/user_session_setps.rb:13:in `/^I should be logged in$/'
You can run again with --guess to make Cucumber be more smart about it
(Cucumber::Ambiguous)
features/user_sessions.feature:26:in `And I should be logged in'
Failing Scenarios:
cucumber features/user_sessions.feature:7 # Scenario: User is not signed up
cucumber features/user_sessions.feature:14 # Scenario: User enters wrong password
cucumber features/user_sessions.feature:21 # Scenario: User signs in successfully
And as cucumber suggests, and when I run with --guess option:
cucumber features --guess
All come green and passes.
Is this the expected behavior or error??
AFAIK, if you have 2 different step definitions that are the same, Cucumber does not know which one to run. Using the --guess flag forces Cucumber to pick the most likely one. The cucumber rake tasks use the --strict flag, and will fail if you have ambigious steps.
Essectially, you need to consider the 2 steps (one in pickle steps and one in user_session_steps) that are conflicting and make a decision as to which one to use, then delete the other one.
Consider these step definitions:
Given /Three (.*) mice/ do |disability|
# some code
end
Given /Three blind (.*)/ do |animal|
# some other code..
end
And a plain text step:
Given Three blind mice
Cucumber can’t make a decision about what Step Definition to execute, and will raise a Cucumber::Ambiguous error telling you to fix the ambiguity.
Guess mode
Running the plain text step will match the Regexp of both step definitions and raise Cucumber::Ambiguous. However,
if you run Cucumber with --guess, it will guess that you were aiming for the step definition with 2 match groups.
There is ranking logic that gets invoked when the option is turned on:
The longest Regexp with 0 capture groups always wins.
The Regexp with the most capture groups wins (when there are none with 0 groups).
If there are 2+ Regexen with the same number of capture groups, the one with the shortest overall captured string length wins.
If there are still 2+ options then an Ambiguous error is raised.
So if you try --guess with the mice above, Cucumber will pick /Three blind (.*)/, because “mice” is shorter than “blind”.
More details here
for $ rake to work properly, specify cucumber's guess mode
in lib/tasks/cucumber.rake, specify t.cucumber_opts = "--guess":
# ...
namespace :cucumber do
Cucumber::Rake::Task.new({:ok => 'test:prepare'}, 'Run features that should pass') do |t|
t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
t.fork = true # You may get faster startup if you set this to false
t.profile = 'default'
t.cucumber_opts = "--guess" # <------- add this line -------<<<
end
# ...
end
# ...

Resources