Can I repeat steps without repeating the steps using Cucumber? - ruby

I need to test behaviour that triggers when a user repeats a set of actions many times. I would like to end up with a scenario that looks something like this:
Scenario: Nice way
Given that I am on some screen
When I enter something into some text field
And I press the Continue button
And I go back
And I repeat the previous 2 steps 5 times
Then the application should crash
Rather than a scenario that looks like this:
Scenario: Annoying way
Given that I am on some screen
When I enter something into some text field
And I press the Continue button
And I go back
And I press the Continue button
And I go back
And I press the Continue button
And I go back
And I press the Continue button
And I go back
And I press the Continue button
And I go back
And I press the Continue button
And I go back
Then the application should crash
Is there a standard way of doing this or do I have to implement it myself?

If you have control over the step definition code try a step like this -
And I press Continue button and go back 5 times
Capture the number of times in the step definition with a variable and call existing functions in a loop for the number of times.
It can be captured by something like:
#And("^I press Continue button and go back (//d+) times")
public void iPressContinueButtonAndGoBackNTimes(int n){
//enter code here
}

To repeat arbitrary steps without having to write a new one each time, define this step
When /^I repeat "([^"]*)" (\d+) times$/ do |steps, times|
times.to_i.times do
steps.split(/;\s*/).each do |step|
step step
end
end
end
and use it like this:
When I repeat "press the Continue button; go back" 5 times
(And don't use semicolons in the names of steps that you want to repeat.)

Related

How to step out from a loop in PhpStorm?

While debugging, how to step out form a loop (foreach, for, while) in PhpStorm like what you do to step out from a function (shift+f8)?
There isn't a single shortcut solution, but there is a simple workaround.
As stepping out of loop basically means you would execute the rest of the loop anyway, you can place the cursor after the loop and press Alt+F9 to move to its position. This way you can skip all the loop iterations you don't want to inspect anymore.
Set your next break point after loop and remove the break point in the loop and press F9

vb6: interrupt endless msgbox loop

I am writing a program in VB6.
By mistake many times my code contains an endless loop, inside which there is a message box. For example:
while a>0
msgbox "a is positive"
wend
Then I press the play/run and I realize what has happened. Is there any way to stop the debugging/running of my program?
The only thing that works so far is Ctrl+Alt+Del and end task. But this way the whole visual basic closes and I lose my unsaved data. (please don't comment that I should save my program more often. I know it (now)).
Edit: I found on the internet that maybe esc or ctrl+c or ctrl+break could do the job. The first two do nothing and my laptop doesn't have a break key
Solution: I have the insert key in my laptop. on the key there is also written pause for use along with the Fn key. So I was able to break the application by pressing Ctrl+Fn+Insert (which maybe could be translated in Ctrl+Pause)
edit: link to photo of my keyboard:
ctrl + break will work. If you don't have those keys, use the on screen keyboard.
Start | Run | osk
Then press ctrl + break.

Xcode - stepping over the debugger to cursor location

Is there a way to to step over the debugger to the cursor location?
In many occasions I want to skip a whole section of code while debugging, in that case I have to put a new breakpoint in the line I want to go to and click the continue execution button. I can't believe Xcode lacks the step over to cursor function.
Right-click on the line and select "Continue to Here".
If you move the cursor over the line number a little icon comes out that is a little play button That lets you run the code and stop at that selected line. Give that a try.

Automatically step by step debugging in Visual Studio?

I was getting tired of hitting the F10 every step to debug the programs. Are there any program can automate the visual studio to run each debugging step in a consistent frequency? say, 3 seconds for each step?
Regards,
Sam
You can easily do that with a simple script in Autohotkey.
Download it from here: http://www.autohotkey.com/
Install Autohotkey.
Run it.
Find the green "H" icon in the task bar (bottom right).
Right click the icon and select Edit script.
And copy paste this script below.
^!y::
InputBox, input1, How many F10 strokes you want?, , , 250, 100
InputBox, input2, How many seconds between each F10 stroke?, , , 250, 100
if ErrorLevel <> 0
{
MsgBox, CANCEL was pressed.
}
else
{
loop, %input1%
{
Sleep, (input2 * 1000)
Send {F10}
}
MsgBox, "Your F10 script has Ended"
}
return
Then reload (again by right clicking the green "H" icon in task bar).
Press Control+Alt+y to try out the above script.
Sitting there repeatedly hitting F10 can be annoying, but you probably just need to make more use of the inbuilt debugging features.
set a breakpoint at a targetted location and hit F5 to run the program, it will stop when it hits the breakpoint
use F11 to step in to a function
use Shift-F11 to step out of a function
use the breakpoints window (Debug->Windows->Breakpoints) to get a complete list of all the bp's and you can easily enable/disable any of them (or set any of their other options)
use the Exceptions window (Debug->Exceptions) to select exceptions that you want to break on when they are first thrown
familiarize yourself with the options available to breakpoints (right-click on the bp itself to get these)
hit count: specify how many times code should go past the breakpoint before it stops
condition: super useful (i use it all the time), you can use almost any expression in there, including checking the value of inscope variables
when hit: you can run a macro when the breakpoint is hit
filter: to restrict which running thread can break on that breakpoint

Visual Studio 2008 - Debugging tips/tricks - Continue "until next function" or "until next file"

Is there any way to tell the debugger to just continue until the next file is accessed, and/or until the next (developer written) function is accessed, without setting debug points ahead of time? I'm kind of new to VS debugging so all I use right now are f5, f10, and f11.
There is currently no way to do what you are asking. The main ways of telling VS to go until something happens are the following
Hit F5 and VS will go until the next user breakpoint or ,depending on your settings and where it occurs, the next exception is raised
Right click and select "Run to cursor"
Shift-F11 breaks out of the current method
Run to cursor doesn't require an explicit break point but it does require that you know where you want to break next.
You can right-click and select "run to cursor" if you just want to run to a specific line ahead in the execution stream.
Another one is Shift-F11 which finishes the current method and breaks again when you get back to the caller.
Actually, there is a way to set conditional break points.
Click in the left margin on the line where you want to break, as usual. (or F9)
Right-click on the red dot. In the context menu, click on "Condition...."
In the dialog, set your condition, e.g., fileName == "foo"
Hit F5 and go until the conditional break is hit.
Looks like there's not a way to do what I wanted to do

Resources