How Cucumber works?
How does Cucumber interacts with different components of a framework?
Lately, my inbox flooded with this question asked by many of you. With this heavy interest on the topic, I thought to put together this post, so that this question can be answered broadly and others can also get benefited. I have tried to detail as mush as possible, please let us know your views and questions if any thorough comments for this post.
I recommend to go through our earlier posts on Cucumber before proceeding on this post. You will have a better idea and can relate appropriately.
Lets assume, we have written features and scenarios in Gherkin and code has already been written in Step Definition file. Now as soon as execution is kicked off, Cucumber reads specification from feature file ,checks for the scenario that needs to be tested and execute the scenario against the system.
When we say that Cucumber execute the scenario written in feature file ,in actual it is interaction of feature file with step definition file i.e. mapping of the business-readable language of each step written in feature file with program code written in step definition language.
The subsequent flowchart depicts the test execution using Cucumber.
The diagram starts with the execution of scenario as first step followed by Cucumber reading the first step of scenario written in feature file and will try to find the match for the same in the step definition file.
If its not able to find the match it will stop the execution their itself and will throw an error “Undefined scenario error”.In case it find the corresponding matching , it will execute that execute corresponding step definitions code block.
If the definition block throw an exception, cucumber will determine whether the step has failed or code has not been written for the specific step.In both the case the execution of the scenario will be terminated at the failure step and execution will proceed to next scenario.
In case of Pass ,Cucumber will start with the execution of the next step and this will be continuing either till the end of the scenario in case all the steps are getting passed one by one or till the termination of the scenario due to failure of any steps.
This was quick, but I hope it must have helped you to get an idea of the Cucumber architecture.
In next post we will discuss on the automation tools that supports cucumber based automation and also the configuration of Cucumber on few of these tools.
Till then –Happy learning!!