REST uses four Authentication mechanisms and one of the popular authentication mechanisms is “Token Authentication” or “Bearer Authentication”. As the name “Bearer Authentication” suggests this type of authentication gives access to the bearer of this token. The token is a cryptic number and generated by the server in response to a login request. The client uses this token in the header of subsequent API calls in order to access protected APIs.
In this blog, let’s look at a step by step example of how this dynamically generated Token can be generated and passed to another Step in your Feature using NoCodeBDD. Creating Feature, Scenarios, Steps and rolling out Behavior Driven Development and Automating using NoCodeBDD literally takes minutes and all can be done without writing any code. If you are new to NoCodeBDD, you can see one of our previous blog that shows how REST API testing can be automated in minutes without writing any code
Step 1: Create Token
In order to pass the Token, it has to be created first. This can be done by calling the login API as shown in the example below. Once the login API is called, you can see result of that in the Audit screen
Step 2: Pass Token using JSON Path
You can pass result of any previous steps to subsequent steps using JSON Path. For an example, in the API that is called in Step 1, the token value can be passed to any subsequent Steps in that Scenario by simply providing the JSON Path for that token. If you are not familiar with JSON Path, there are several online tools available such as JSONPathFinder. We have put together a tutorial on how to find JSON Path for any element. The tutorial is very handy to find any JSON Path.
As you can see, passing Token or any values from one BDD Step to another Step in NoCodeBDD is as easy as providing the JSON Path. As mentioned before the response from a Step, can be passed to any Steps within that Scenario. When a Step is executed, NoCodeBDD walks back all the previous steps response and pull the required element if a JSON Path is provided.
Jerome Josephraj is the Founder and CTO of NoCodeBDD. He has more than 20 years of experience in Software Development and have been rolling out Behavior Driven Development for large projects in United Kingdom. He has a strong Java Development Background and have been working as a Technical Consultant. In one of his recent large enterprise projects, he has successfully rolled out Behavior Driven Development consisting of more than 1000 scenarios. He was also the Founder of http://www.campusinteraction.com, a student analytics portal, which was later bought by Preludesys. Based on the previous start-up experience and a strong Behavior Driven Development experience, he founded NoCodeBDD to improve efficiency of rolling out Behavior Driven Development by 10x.