3

I am calling login feature file from other feature file from where I am passing url, username and password but it is not working for me. I am not using Background key here and i do not want also.

 @CallAnotherFeature
 Feature: Call Login Feature

 Scenario: Calling Login Test
 * def config = { endPointURL: 'https://qa1.testurl.com/login',username: 'user123', password: 'password123' }
* def result= call read('Login.feature') config
* print result.response
* print 'Sign In-'+signIn
* print 'Sign In Reponse-'+signIn.response


Feature:  Login Feature

Scenario: Test Login for different users

* print 'Starting Test','#(endPointURL)'
Given url '#(endPointURL)'
* print 'user name','#(username)'
* print 'Password ','#(password)'
#And form field username = '#(username)'
#And form field password = '#(password)'
And request { username: '#(username)', password: '#(password)'}
When method post
Then status 200
* print response
* match response.loginSuccess == true

In Login.feature I tried to pass username and password as form data also even though these did not work. Could someone tell me what mistake I am making here.

I am using latest karate version 0.9.0

1
  • can you please elaborate more about what is the error you are getting or what did not work? Commented Dec 11, 2018 at 3:40

1 Answer 1

6

I see a few issues in your scripts,

1. Call Login Feature

1.1) I don't see signIn variable initialized anywhere in this feature nor from your login feature but you are trying to print it.

1.2) = Should be placed properly ;)

* def result = call read('Login.feature') config

2. Login Feature

2.1) I think you misunderstood the concept of embedded expressions. only for templating it into a JSON you may use it. but for calling it you can simply use the variable name.

eg.

Given url endPointURL
And form field username = username
And request { username: '#(username)', password: '#(password)'}

NOT

Given url '#(endPointURL)'
And form field username = '#(username)'

I will be more clear for you if you read the karate documentation from here -> karate Doc and refer karate Demos

Sign up to request clarification or add additional context in comments.

2 Comments

is there any restriction that the def variable would not work with the Given keyword.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.