How to access the execution context from a Cucumber step definition - cucumber-jvm

Can one access the cucumber executor context from a step definition to - for example - determine if the current step definition is the last entry of a scenario?

Related

How to share/pass a variable among multiple thread groups within jmeter and without using beanshell assertion

I have declared 1 user defined variable (A=wait) in a test plan and I have 2 thread groups in the test plan. When 1st thread group completes it's execution then I have changed the value to "go" (A=go) using beanshell post processor. Now, in second thread group I want that (A) should be pick the updated value (means "go" not "wait") but I am not able to pick the updated value in 2nd thread group. I am not using any regular expression extractor, just using and updating user defined variable.
I tried beanshell pre and post processor. First I created 1 bean shell sampler in which I changed the value(vars.put("A1","go");) then I created 1 beanshell postprocessor (${__setProperty(A,${A1})}) in first thread group and then in 2nd thread group I added BeanShell preprocessor to get the value (${__property(A)})
I also used beanshell assertion to pass the variable to next thread group but next thread group didn't catched the updated value.
If you don't want to use scripting - take a look at Inter-Thread Communication Plugin
There is an example test plan showing how variables could be shared.
Going forward be aware that since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting and in Groovy you should avoid inlining JMeter Functions or Variables
So:
In first thread group:
props.put('A', 'go')
In second thread group:
go = props.get('A')
or if you prefer a function:
${__P(A,)}
Demo:

Local Search phase needs to start from an initialized solution - But how?

I am writing a modified version of the Task Assignment example with my own domain model.
In my model each Task can have a NextTask and a PreviousTask and an Assignee. All 3 are configured as PlanningVariables:
...
/** PreviousTask is a calculated task that the Resource will complete before this one. */
#PlanningVariable(valueRangeProviderRefs = { "tasksRange" }, graphType = PlanningVariableGraphType.CHAINED)
public Task PreviousTask;
#InverseRelationShadowVariable(sourceVariableName = "PreviousTask")
public Task NextTask;
#AnchorShadowVariable(sourceVariableName = "PreviousTask")
public Resource Assignee;
I have been stuck on the Local Search Phase step for some time now as it appears to require an initialized state of my planning variables (Task.PreviousTask in this case).
Error log:
2020-07-16 15:00:15.341 INFO 4616 --- [pool-1-thread-1] o.o.core.impl.solver.DefaultSolver : Solving started: time spent (65), best score (-27init/[0]hard/[0/0/0/0]soft), environment mode (REPRODUCIBLE), random (JDK with seed 0).
2020-07-16 15:00:15.356 INFO 4616 --- [pool-1-thread-1] .c.i.c.DefaultConstructionHeuristicPhase : Construction Heuristic phase (0) ended: time spent (81), best score (-27init/[0]hard/[0/0/0/0]soft), score calculation speed (90/sec), step total (0).
2020-07-16 15:00:15.376 ERROR 4616 --- [pool-1-thread-1] o.o.c.impl.solver.DefaultSolverManager : Solving failed for problemId (5e433f57-8c75-4756-8a9c-4c4ca4a83d6d).
java.lang.IllegalStateException: Local Search phase (1) needs to start from an initialized solution, but the planning variable (Task.PreviousTask) is uninitialized for the entity (com.redhat.optaplannersbs.domain.Task#697ea710).
Maybe there is no Construction Heuristic configured before this phase to initialize the solution.
I've been pouring over the documentation and trying to figure out what I've missed or broken between it and the source example but I cannot work it out. I have no Construction Heuristic configured (Same as the example), and I could not see where in the example does it ever set the previousTaskOrEmployee variable before solving.
I could supply a random PreviousTask in the initial solution model, but surely at least 1 of the tasks would have no previous task?
May I ask if you have <localSearch/> in your solverConfig.xml? If so, the <constructionHeuristic/> has to be there as well.
If none of these phases (CH nor LS) is configured, both Construction Heuristic and Local Search is added with default parameters. But once the appears in the solverConfig.xml, it's considered an override of the defaults, and a user is supposed to take care of initializing the solution (most often by providing the Construction Heuristic configuration).

karate.abort() in v0.9.4 results in Failed scenario in cucumber html reports

karate.abort() results in skipped steps. There was a fix previous for this . However, cucumber reporting treats skipped tests as Failed.
Is there any workaround where I can use karate.abort() and not have Failed scenario, as I am using it deliberately to skip some DB checks.
Or is there any alternative to karate.abort()?
Yes we need some community help to resolve how third party reports treat skipped steps, please read this - and maybe you can be the one to find a solution: https://github.com/intuit/karate/issues/755#issuecomment-488710450
A workaround is to split into a second feature and then:
* if (condition) karate.call('second.feature')

JMeter order of samples with Redis Data

I am using Redis Data Set as a data source in my JMeter tests. I have configured the redis key with a value I retrieve from a JSR223 sampler.
Below are my test samplers.
in the bove JSR223 sampler I retrieve a previous value ${operator} and put in to properties.
Then in the next sampler ,
I reuse the value as ${__P(operator)}.
The issue with this is ,it doesn't look like JSR233 sampler is running before jp#gc RedisDataset. so the script fails like below.
Stop Thread seen for thread XXXXXX 1-1, reason: org.apache.jorphan.util.JMeterStopThreadException: End of Redis data detected, thread will exit
If I run the script once commenting the Redis data set sampler, and run on a second run with enabling it, the value can be seen, as the value have been stored in the Jmeter memory, this way it was evident that Redis data set runs before JSR223 sampler. I can not move JSR 233 sampler out of the test fragment to a much higher level as I need to run it within the test fragment.
Is there a location which defines these order of executions with Redis samplers ?
Or is there a way to define the order in Jmeter so that JSR223 will run before Redis sampler?
===================================
UPDATE 1
After #Dmitri-t s reply, I have updated the project as follows .
and
As per Execution Order chapter of JMeter User Manual:
0. Configuration elements
1. Pre-Processors
2. Timers
3. Sampler
4. Post-Processors (unless SampleResult is null)
5. Assertions (unless SampleResult is null)
6. Listeners (unless SampleResult is null)
Redis Data Set is a Configuration Element therefore it will be executed prior to anything else.
The only way you can make this operator property dynamic is overriding it via -J command-line argument like:
jmeter -Joperator=something -n -t test.jmx -l result.jtl
I got That working in the following way
TestPlan
|--Thread group
|--Module Controller -1
| |--CSV Data Set Config - to load operator name(this is going to be reused in other thread groups)
|--Module Controller -2
|--JSR233 Sampler - To read a second level file with ${operator} in its name
|--For Each Controller - to read through the second level file
| |--User Defined Variables - to split the line from the second level file in to variables
|--HTTP Request - Action sampler with ${operator} and other variables
Ref : Iterating over a csv file

when / how often to use Chai-as-promised's .notify()

We are using Chai-as-promised with protractor and cucumberjs. I have a question about the .notify(callback) method in the chai-as-promised library.
If we are running multiple scenarios with a few steps in each. Should notify() be called at the end of each step?
So
Scenario 1
Step 1 Expect(promise).to.eventually.to.equal(true).and.notify(callback);
Step 2 Expect(promise2).to.eventually.to.equal(true).and.notify(callback);
Scenario 2
Step 3 Expect(promise3).to.eventually.to.equal(true).and.notify(callback);
Step 4 Expect(promise4).to.eventually.to.equal(true).and.notify(callback);
I always though we should only have the 'and.notify(callback)' in the last step.
So
Scenario 1
Step 1 Expect(promise).to.eventually.to.equal(true);
Step 2 Expect(promise2).to.eventually.to.equal(true).and.notify(callback);
Scenario 2
Step 3 Expect(promise3).to.eventually.to.equal(true);
Step 4 Expect(promise4).to.eventually.to.equal(true).and.notify(callback);
I have a similar question over at the github page.
https://github.com/domenic/chai-as-promised/issues/65
Prior to CucumberJS v0.5.0, all Step Definitions needed to be defined with a callback argument that needed to be called once the step was finished executing.
In v0.5.0, they updated the library so that the callback argument was no longer necessary. From their CHANGELOG:
New features
Support promises from step definitions (Will Farrell)
Support synchronous step definitions (Julien Biezemans)
While the return value from chai-as-promised assertions aren't real promises, their interface is similar enough for CucumberJS to treat them like promises. So, to answer your question:
Prior to CucumberJS v0.5.0, you have to call notify() at the end of each step.
After CucumberJS v0.5.0, you do not have to call notify() at the end of any step.