How to get SpecFlow to change step definition when renaming step in feature file? - definition

Lets say i have a scenario in feature file like below
Given I log in as "super" user
When I click on login
Then Home page is displayed
With corresponding step definitions:
[Given(#"I log in as ""(.*)"" user")]
public void GivenIHaveLogInAsUser(string p0)
{
ScenarioContext.Current.Pending();
}
Now I want to change
Given I log in as "super" user
To
Given I have logged in as "super" user
When I make this change in feature file how to get SpecFlow to make this change automatically in the step definition.

UPDATE
This feature was added in a fairly recent update, so you should be able to follow the instructions here, which basically say
You can globally rename steps and update the associated bindings automatically. To do so:
Open the feature file containing the step.
Right-click on the step you want to rename and select Rename from the context menu.
Enter the new text for the step in the dialog and confirm with OK.
Your bindings and all feature files containing the step are updated.
Note: If the rename function is not affecting your feature files, you may need to restart Visual Studio to flush the cache.
previous answer
This is not possible I don't believe. you have 2 options:
amend the step definition text to match the new text
add the new definition to the step as well
like so:
[Given(#"I log in as ""(.*)"" user")]
[Given(#"I have logged in as ""(.*)"" user")]
public void GivenIHaveLogInAsUser(string p0)
{
ScenarioContext.Current.Pending();
}
This will allow steps with both pieces of text to match

Bit late to this thread, but you may use visual studios find and replace tool with regex enabled to replace both the step definition and the step implementations together.
e.g for the step definition: Given I have a message '(.*)' that is (.*) characters long, we can use the step definition itself to use in search for any matching steps, and replace with the new step. $n can be used to carry over regex matches picked up in the find.
Find: I have a message '(.*)' that is (.*) characters long
Replace: I have a message $1 that is $2 characters in length
Result: 'I have a message 'myMessage' that is 100 characters long' becomes 'I have a message 'myMessage' that is 100 characters in length'

Related

Custom info in Jmeter dashboard

Trying to add my own table to Jmeter dashboard report. In Jmeter it's not clear enough. Tried as in https://jmeter.apache.org/usermanual/generating-dashboard.html#customs_graphs
but the custom part doesn't appear in dashboard. Would appreciate your help and examples.
It looks like the documentation you're referring is not comprehensive enough, the chapter assumes that you can plot the numeric value of a Sample Variable
So if you put the next line to user.properties file (lives in "bin" folder of your JMeter installation)
sample_variables=ts-hit
and copy and paste the example configuration from the documentation:
jmeter.reportgenerator.graph.custom_testGraph.classname=org.apache.jmeter.report.processor.graph.impl.CustomGraphConsumer
jmeter.reportgenerator.graph.custom_testGraph.title=Chunk Hit
jmeter.reportgenerator.graph.custom_testGraph.property.set_Y_Axis=Number of Hits
jmeter.reportgenerator.graph.custom_testGraph.set_X_Axis=Over Time
jmeter.reportgenerator.graph.custom_testGraph.property.set_granularity=60000
jmeter.reportgenerator.graph.custom_testGraph.property.set_Sample_Variable_Name=ts-hit
jmeter.reportgenerator.graph.custom_testGraph.property.set_Content_Message=Number of Hits :
Create some fake values for the ts-hit variable using i.e. __Random() function:
As the result you should see something like this:
With regards to custom tables - as of JMeter 5.5 it's not possible, however if you're comfortable with FreeMarker you can amend the template and add whatever you want there

Special characters in drop-down list with Robot Framework (Selenium)

just wondering if any of you know how to handle special characters with a website that contains a drop-down list. I scripted the following in Robot Framework (Selenium) to verify the contents of a drop-down list:
Verify all required fields and labels are present
Verify a and lists of b for 'ööö'
Verify a and lists of b for '${xyz}'
(...)
Dropdown "{abc}" should contain options "${json_blabla["ABC"]["${xyz}"]}"
However, when trying to do that, I get the following error message when running the script:
Resolving variable '${json_blabla["ABC"]["ööö"]}' failed: KeyError: '\xc3\xb6\xc3\xb6\xc3\xb6'
Any idea how to get around this? I'm sure I saved everything in UTF-8 encoding, and I think the JSON file should be fine too, so I'm suspecting it's somewhere in the script I just showed?
Found it:
It seems that it needs to be told explicitly that the string must be in Unicode, so one option to have it corrected is:
Dropdown "{abc}" should contain options "${json_blabla["ABC"][u"${xyz}"]}"
And voilà!
Thanks for voting & until next time!

How do I write a robust structural search template to report Mockito times(1)/Times(1) passed to verify in IntelliJ IDEA?

In my project Mockito.times(1) is often used when verifying mocks:
verify(mock, times(1)).call();
This is redundant since Mockito uses implicit times(1) for verify(Object), thus the following code does exactly what the code above does:
verify(mock).call();
So I'm going to write an a structural search drive inspection to report such cases (let's say, named something like Mockito.times(1) is redundant). As I'm not an expert in IntelliJ IDEA structural search, my first attempt was:
Mockito.times(1)
Obviously, this is not a good seach template because it ignores the call-site. Let's say, I find it useful for the following code and I would not like the inspection to trigger:
VerificationMode times = Mockito.times(1);
// ^ unwanted "Mockito.times(1) is redundant"
So now I would like to define the context where I would like the inspection to trigger. Now the inspection search template becomes:
Mockito.verify($mock$, Mockito.times(1))
Great! Now code like verify(mock, times(1)).call() is reported fine (if times was statically imported from org.mockito.Mockito). But there is also one thing. Mockito.times actually comes from its VerificationModeFactory class where such verification modes are grouped, so the following line is ignored by the inspection:
verify(mockSupplier, VerificationModeFactory.times(1)).get();
My another attempt to fix this one was something like:
Mockito.verify($mock$, $times$(1))
where:
$mock$ is still a default template variable;
$times$ is a variable with Text/regexp set to times, Whole words only and Value is read are set to true, and Expression type (regexp) is set to (Times|VerificationMode) -- at least this is the way I believed it should work.
Can't make it work. Why is Times also included to the regexp? This is the real implementation of *.times(int), so, ideally, the following line should be reported too:
verify(mockSupplier, new Times(1)).get();
Of course, I could create all three inspection templates, but is it possible to create such a template using single search template and what am I missing when configuring the $times$ variable?
(I'm using IntelliJ IDEA Community Edition 2016.1.1)
Try the following search query:
Mockito.verify($mock$, $Qualifier$.times(1))
With $Qualifier$ text/regexp VerificationModeFactory|Mockito and occurrences count 0,1 (to find it when statically imported also).
To also match new Times(1) you can use the following query:
Mockito.verify($mock$, $times$)
With $times$ text/regexp .*times\s*\(\s*1\s*\) and uncheck the Case sensitive checkbox.

Synchronize modification between SWT table and TextEditor

I'm facing a problem and want to ask for a solution.
I'm working on an eclipse plugin project, in which an editor for a type of resource file is required. The resource file has similar structure like CSV file. My idea is to provide user the option to edit this type of file both in plain text format and also in an SWT table. Plain text is required for examining data and table provides more flexibility to editing such as sorting by column.
I have been able to create a MultiPageEditorPart, with one page of org.eclipse.ui.editors.text.TextEditor, and another page with a org.eclipse.swt.widgets.Table and several other widgets like search bar. The content of the resource file can be shown in the TextEditor, can also be edited and saved. On the other hand, the content can be loaded in the table too, sorting and searching all work good.
The problem is: when I edit a cell in the table, I want the change also reflected in the TextEditor, and vice versa. Since the resource file can be very large, I want the saving action happen only on the TextEditor, i.e. I don't want any modification in the table directly stored to resource file, but to mark the file dirty, but I can't figure out how. How can I for example get the content of EditorInput, check it line by line, and modify it outside TextEditor?
Or, are there more efficient ways to do this? Can anyone give any hints?
The IDocument used by the TextEditor gives you access to the document contents. Get this with something like:
IDocumentProvider provider = editor.getDocumentProvider();
IEditorInput input = editor.getEditorInput();
IDocument document = provider.getDocument(input);
IDocument has many methods for accessing lines such as:
int getLineOffset(int line);
int getLineLength(int line);
and methods for modify the text:
void replace(int offset, int length, String text);

PsychoPy Builder - How to I take a rest part way through a set of trials?

In PsychoPy builder, I have a lot of trials and I want to let the participant take a rest/break part way through and then press SPACE to continue when they're ready.
Any suggestions about how best to do this?
PsychoPy Builder uses the TrialHandler class and you can make use of its attributes to do control when you want to take a rest.
Assuming you're trial loop is utilising an Excel/csv file to get the trial data then make use of trialHandler's attribute : thisTrialN
e.g.
1/ Add a routine containing a text component into your loop (probably at the beginning) with your 'now take a rest...' message and a keyboard component to take the response when they are ready to continue.
2/ Add a custom code component as well and place something similar to this code into its "Begin Routine" tab:
if trials.thisTrialN not in [ int(trials.nTotal / 2) ]:
continueRoutine=False
where 'trials' is the 'name' of your trial loop.
The above will put a rest in the middle of the current set of trials but you could replace it with something like this
if trials.thisTrialN not in [10,20]:
continueRoutine=False
if you wanted to stop after 10 and again after 20 trials.
Note, if you're NOT using an Excel file but are simply using the 'repeat' feature of a simple trial loop, then you'll need to replace thisTrialN with thisRepN
If you're using an Excel file AND reps you'll need to factor in both when working out when you want to rest.
This works by using one of Builder's own variables - continueRoutine and sets it false for most trials so that most of the time it doesn't display the 'take a rest' message.
If you want to understand more, then use the 'compile script' button (or F5) and take a look at the python code that Builder generates for you.