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

Cannot get url to work with call feature #692

Closed
myturf opened this issue Mar 7, 2019 · 17 comments
Closed

Cannot get url to work with call feature #692

myturf opened this issue Mar 7, 2019 · 17 comments

Comments

@myturf
Copy link

myturf commented Mar 7, 2019

Hi, First of all congratulations and thank you for great work. I recently came across this framework and I am very impressed. Big thank you!

Second, I am stuck with call feature and was wondering if it is supported. I am trying to build a reusable login features.

#login.feature
#--------------
  Given url appUrl
  And path 'login'
  And headers { Content-Type: 'application/x-www-form-urlencoded' }
  And form field j_character_encoding = encoding
  And form field j_username = user
  And form field j_password = password
  When method post
  Then status 200
  * print 'responseCookies',responseCookies

I am calling from other feature like this



* def appUrl = 'someurl'
* def j_username= 'username'
* def j_password= 'password'
  * def result = call read('login.feature') { appUrl: '#(appUrl)',  encoding: 'UTF-8' , user: '#(j_username)', password: '#(j_password)' }



but I keep getting this error

com.intuit.karate.exception.KarateException: -unknown-:4 - javascript evaluation failed: appUrl, ReferenceError: "appUrl" is not defined in <eval> at line number 1
	at ✽.* url appUrl (-unknown-:4)

am I doing something wrong ?

@rexfordnana
Copy link

I would try renaming your variables a bit. make 'appUrl' unique.
def apUrl = 'someurl' def result = call read('login.feature') { appUrl: '#(apUrl)' }

@myturf
Copy link
Author

myturf commented Mar 7, 2019

BalurQA thank you, can you show how to use loginConfig in Login.feature ?

@BalurQA
Copy link

BalurQA commented Mar 7, 2019

   Scenario Outline: calling login feature
    * def loginConfig = { endPointURL: '<loginEndPointURL>',username: '<uName>', password: 
       '<passWord>' }
     * def loginResult = call read('../resources/Login.feature') loginConfig
     * print 'Sign In Reponse-'+loginResult.response

@myturf
Copy link
Author

myturf commented Mar 7, 2019

No I would like to see Login.feature, that is where the error is coming from
This is the part that throws errors, I tried different names , doesnt work
Given url appUrl

@BalurQA
Copy link

BalurQA commented Mar 7, 2019

Feature:  Login Feature
Scenario: Test Login for different users
Given url endPointURL
And form field username = username
And form field password = password
When method post
Then status 200

@BalurQA
Copy link

BalurQA commented Mar 7, 2019

Parameter names used in loginConfig should be same in Login.feature file where it is called. like username, password and endPointURL

@myturf
Copy link
Author

myturf commented Mar 7, 2019

I tried that too , Here is the exact error I am getting

com.intuit.karate.exception.KarateException: login.feature:5 - javascript evaluation failed: endPointURL, ReferenceError: "endPointURL" is not defined in <eval> at line number 1
	at ✽.Given url endPointURL (login.feature:5)

@BalurQA
Copy link

BalurQA commented Mar 7, 2019

I think you doing mistake in karate-config.js file

@BalurQA
Copy link

BalurQA commented Mar 7, 2019

if you not using karate-config.js file, then declare the endpoint url in Background

@myturf
Copy link
Author

myturf commented Mar 7, 2019

Here is my karate-config.js, I simply copied example


function fn() {    
  var env = karate.env; // get system property 'karate.env'
  karate.log('karate.env system property was:', env);
  if (!env) {
    env = 'dev';
  }
  var config = {
    env: env,
	myVarName: 'someValue'
  }
  if (env == 'dev') {
    // customize
    // e.g. config.foo = 'bar';
  } else if (env == 'e2e') {
    // customize
  }
  return config;
}

@BalurQA
Copy link

BalurQA commented Mar 7, 2019

   #login.feature
     #--------------
      * print 'Config printed are not '+loginConfig 
      Given url endPointURL
      And path 'login'
      And headers { Content-Type: 'application/x-www-form-urlencoded' }
      And form field j_character_encoding = encoding
      And form field j_username = username
      And form field j_password = password
      When method post
      Then status 200
     * print 'responseCookies',responseCookies

Another feature where login is called.

         Scenario Outline: calling login feature
           * def loginConfig = { endPointURL: '<loginEndPointURL>',username: '<uName>', password: 
             '<passWord>', encoding = '<encoding>'}
          * def loginResult = call read('../resources/Login.feature') loginConfig
           * print 'Sign In Reponse-'+loginResult.response
            Examples:
          | uName     | passWord  | loginEndPointURL                             | encoding |
           | helluser    | hellopwd    | https://www.tester.com//login/login    |      UTF-8| 

I hope this will work.

@myturf
Copy link
Author

myturf commented Mar 7, 2019

Thank you this worked

@myturf myturf closed this as completed Mar 7, 2019
@Vikash007-123
Copy link

How I will call karte-config.js file in feature file

my kartae-config.js file Her
function fn() {

var config = { 
		someUrl : 'https://reqres.in/api/users/3'
	
};

// don't waste time waiting for a connection or if servers don't respond within 5 seconds
/*karate.configure('connectTimeout', 5000);
karate.configure('readTimeout', 5000);*/
return config;

}

and my feature fie is Here
Feature: user Details
Background:

  • def expectedOutput = read('result2.json');

Scenario:request user Details

Given url someUrl
When method GET
Then status 200
And match response == expectedOutput
Then print 'I am calling karate-config.js Here--',someUrl

@Vikash007-123
Copy link

I try to call but I got some exceptions. I mentioned down could you check
KarateDemo.config: config.feature:7 - evaluation (js) failed:
someUrl, javax.script.ScriptException: ReferenceError: "someUrl" is not defined in at line number 1
stack trace: jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:47
0)

@ptrthomas
Copy link
Member

@Vikash007-123
Copy link

@ptrthomas I am not able to find that could you help me please

@ptrthomas
Copy link
Member

ptrthomas commented Oct 13, 2020

@Vikash007-123 here is a screenshot
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants