Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get The Step Name & Number Of A CucumberJs Step & Set The Result Of A Step #719

Closed
bhreinb opened this issue Jan 13, 2017 · 17 comments
Closed

Comments

@bhreinb
Copy link

bhreinb commented Jan 13, 2017

Hi there,

I know this is an issue repository but I'm hoping you can help answer the following question as i'm unsure whether the framework supports this. The question is as follows

I would like get the following information from cucumber.js at runtime

  1. From a JavaScript step get the current step number
  2. From a JavaScript step get the current step name
  3. From a JavaScript Step "set" the step result

I have cases whereby I would like to override the result provided by framework. Is any of the three steps possible. I'm currently using cucumber@1.3.1. Btw I see there is cucumber 2.0.0 currently been developed. Will their be sample code on how to use with protractor, as I use cucumber.js initiated through protractor. Many thanks in advance.

@charlierudolph
Copy link
Member

What exactly does "From a JavaScript step" mean exactly?

There is setDefinitionFunctionWrapper that may be able to be useful but I'm not sure.

I am not involved in the protractor project and thus this is wrong place to look for help with that. I am open to work with someone from the protractor team to help build that out but that would belong in the protractor repo anyway instead of here.

@bhreinb
Copy link
Author

bhreinb commented Jan 13, 2017

Lol sorry about the confusion. That is very vague my apologies. So a JavaScript step would mean from my perspective as the JavaScript equivalent of a cucumber feature step

i.e.

Given A User Navigates To The Login Page

this.Given(/^A User Navigates To The Login Page$/, function () {

});

so ideally I would be able to get the step name, step number & possibly set the step result from within the world context if that makes sense.

This function you mention is that only available to cucumber 2.0 plus?

That's a fair enough point you make about protractor just curious.

@charlierudolph
Copy link
Member

so ideally I would be able to get the step name, step number & possibly set the step result from within the world context if that makes sense.

  • Step name - Not saved as a variable anywhere but you have the context to know it based on the parameters and what function you are in.
  • Step number - this is not really a concept within cucumber-js
  • Step result - If the step is currently running, the step result is based on what the function returns / passes to the callback. What would you need to set exactly?

Maybe see registerHandler is does not allow you to set the step result but you can view step names, track the step number yourself, and view step result.

This function you mention is that only available to cucumber 2.0 plus?

Correct

@bhreinb
Copy link
Author

bhreinb commented Jan 16, 2017

Hey @charlierudolph

Many thanks for your comments above. They were very useful. I have two more questions for you if you don't mind. To give you some context I want to be able to put manual testing through the framework, hence all the questions.

I have three hook functions listed below

var _this = this;
_this.Before(Before);
_this.After(After);
_this.After([{tags: '@Aca_Ipmf_02'}, {timeout: 90 * 1000}] ,Aca_Ipmf_02);

Is there anyway to assign a name to them so when I call the following code within an EventHandler function i.e.

function BeforeStep(event, callback) {

 ++StepNumber;

console.log('We Are Currently Executing Step Number ' + StepNumber);

console.log('Step Name ' + event.getName());

callback();

}

as event.getName returns 'undefined' for each of those. If not no worries, I can work around that so to exclude steps that get processed as hooks.

to set the result of a step definition manually in the framework I'm assuming I can do the following:

return Cucumber.Status.PASSED;

or one of

Status.AMBIGUOUS,
Status.FAILED,
Status.PASSED,
Status.PENDING,
Status.SKIPPED,
Status.UNDEFINED

Cheers,

~Bhréin

@charlierudolph
Copy link
Member

charlierudolph commented Jan 16, 2017

  1. For Before / After hooks you can use getKeyword to differentiate the two and also getTags in order to differentiate the two after hooks

  2. No you should not be doing that. Can you please explain more what you are trying to accomplish?

@bhreinb
Copy link
Author

bhreinb commented Jan 16, 2017

So I have two use cases

  1. Run automated tests through the framework which is catered for already. 👍

  2. Run manual test cases through the framework.....
    So how that will work is I will deserialize an XML file that contains test results in probably ''BeforeFeatures' event handler. The XML looks something like this (I'm still in concept mode)

<Scenario Name="Test">
	<Step Number="1" Result="Pass">
		<Message type="info">Overall this step passed as the step passed on four of the five supported browsers.</Message>
	</Step>
	<Step Number="2" Result="Fail">
		<Message type="error">This step failed because it failed on four of the five supported browsers.</Message>
	</Step>
</Scenario>

So based on the XML i.e. Result attribute I want the framework to set a test step in the framework for a manual test case, so that I get for free the same JSON produced at the end of a test run.

so Pass will be a cucumber equivalent etc. Hope I'm making sense? Btw
Info Message will be appended to JSON report using _scenario.attach()
Error Message will be appended to JSON by throwing an exception or some other form.

@charlierudolph
Copy link
Member

I'm sorry @bhreinb but I would rather not support the use case for number 2. That would open up too much of the internals in my mind just in order to give you the "same JSON produced at the end of a test run".

@bhreinb
Copy link
Author

bhreinb commented Jan 16, 2017

Okay thanks for your help with this.

@bhreinb
Copy link
Author

bhreinb commented Jan 17, 2017

Hi @charlierudolph

Sorry for the bother again...but I seem to be having an issue overriding a tagged hook timeout

_this.After([{tags: '@Aca_Ipmf_02'}, {timeout: 90 * 1000}] ,Aca_Ipmf_02);

Basically what I'm trying to do is exercise the backend APIs via this hook. As there is a lot of data been sent when exercising the API it can take longer to complete than the default timeout of 30 seconds. I need to keep default timeouts to be 30 seconds for other non-angular tests that are done via the framework. However, it never respects the timeout I set on the hook. I have tried a few variations of the signature above to no avail. Sorry to bother again and I appreciate any suggestions on the above.

@charlierudolph
Copy link
Member

See the api reference docs. The tags and timeout should be in a single object (and no array)

@bhreinb
Copy link
Author

bhreinb commented Jan 17, 2017

Hey thanks a mill...here is the construct that worked for us

this.After({tags: ['@Aca_Ipmf_02'], timeout: 90 * 1000}, function (scenario) {
}

this construct threw an exception

this.After({tags: '@Aca_Ipmf_02', timeout: 90 * 1000}, function (scenario) {
}

@charlierudolph
Copy link
Member

Are you on version 1.3.1? Sorry my answer for for 2.0.0-rc.6

@bhreinb
Copy link
Author

bhreinb commented Jan 17, 2017

I'm on 1.3.1. I'd love to upgrade at a later stage but to do that I'd need compatibility with protractor.

@bhreinb
Copy link
Author

bhreinb commented Jun 28, 2017

Hi @charlierudolph sorry to initiate an old thread again. Suppose I have a cucumber step something like the following....

And The User Searches For An Employee That Has An Unique Identifier Of Status "Active"

Is it possible via a cucumber API to get the regex equivalent of an individual step?

this.When(/^The User Searches For An Employee That Has An Unique Identifier Of Status "([^"]*)"$/

I know you have a capacity to print empty steps to the stdout via dry-run parameter but I'm looking for a translation at a more granular level if that makes sense.

Appreciate any guidance on the above.

@danielvanmil
Copy link

I also would like to have the step information in the setDefinitionFunctionWrapper function. Still not clear how to achieve this? Do you have an example how to for example log this info in a setDefinitionFunctionWrapper function? Thanks!

@Gilad-Shnoor
Copy link

@danielvanmil Did you figure it out? I am looking for the same thing and could not find it anywhere

@lock
Copy link

lock bot commented Jan 17, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants