Assuming you have the project setup ready if not, see my post Getting started with Karate Automation . Once your project is set let’s start with creating a folder structure in Eclipse.
The below project is the maven project and src/test/java have a package called authentication which will have all authentication related feature files.

After you have created your authentication package you can create a feature file inside the same package and name it “Authentication.feature“.
Now add the below code into the feature file which will help you authentication a user using grant type implicit.
Feature: Implicit Auth Background: * url authURL Scenario: Verify the user details using OAuth2 Implicit grant type * path 'token' * form field grant_type = 'password' * form field username = 'username' * form field password = 'password' * form field client_id = 'appId' * form field client_secret = 'appSecret' * form field scope = 'your_App_Scope' * method post * status 200 * print response * def accessToken = response.access_token * header Authorization = 'Bearer ' + token
Once you have you Authentication set, create another scenario to create a test if the Authentication is working
@yourtag Scenario: get all employer details * path 'YourAPPURL' Given def query = read('yourRequestFileName.json') #Change your data as below And def variables = { name: 'Charmander' } And request { query: '#(query)', variables: '#(variables)' } #And request { query: '#(query)' } When method post * print response Then status 200
What API have you used?? I think you forgot to specify the most important part.
Hi priyankabrahmane ,
Thank you for your comment.
My post is not specific to any API , you can test your OAuth with any API that you are using.