ERROR com.intuit.karate.core.FeatureParser - syntax error: mismatched input '<EOF>' expecting {FEATURE_TAGS, FEATURE} [duplicate] - karate

As I'm trying to automate the API testing process, have to pass the XML file to Read method for example,
Given request read ( varXmlFile )
FYI: XML file is present in the same folder where the feature file exists.
Doing this, its throwing an exception like this
com.intuit.karate.exception.KarateException: called: D:\workspace\APIAutomationDemo\target\test-classes\com\org\features\rci_api_testing.feature, scenario: Get Membership Details, line: 15
javascript evaluation failed: read (varXmlFile )
So Karate doesn't allow this way or can we have any other alternative ?
Suggestion please.
Thanks

Please ensure the variable is set:
* def varXmlFile = 'some-xml-file.xml'
Given request read(varXmlFile)
Or just use normally:
Given request read('some-xml-file.xml')

The problem got solved as in the variable varXmlFile holds the file name along with single quote like this 'SampleXmlRequest.xml'.
So I removed the single quote while returning from the method.

Related

How to extracting large amounts of data (more than 100 MB) from Snowflake into CSV

I am trying to export large amounts of data from snowflake into a CSV. I saw a similar question and the solution given was to “Run the query as part of a COPY INTO {location} command to an internal stage, and then use a GET command to pull it down locally.”
I tried following the guide and ran the following but receives the error, “SQL compilation error: syntax error line 4 at position 3 unexpected 'file_format'.”
I am not sure how to fix this or even if the first part of my syntax is correct. Can someone please help.
copy into #my_stage/result/data_ from (select *
from"IRIS"."PRODUCTION"."VW_ALL_IIS_LHJ"
where (RECIP_ADDRESS_COUNTY = 06065 or ADMIN_ADDRESS_COUNTY = 06065)
file_format=(TYPE='CSV');
[ HEADER = TRUE]
get #%my_stage/result/data.csv/;
I'm pretty sure the issue is that you're missing a closing parenthesis. Try:
copy into #my_stage/result/data_ from (select *
from"IRIS"."PRODUCTION"."VW_ALL_IIS_LHJ"
where (RECIP_ADDRESS_COUNTY = 06065 or ADMIN_ADDRESS_COUNTY = 06065))
file_format=(TYPE='CSV');
[ HEADER = TRUE]
get #%my_stage/result/data.csv/;
Sorry - I don't have a way to test this.
You are missing a parentheses after the where clause. You opened a parentheses after the first FROM and then another one at the WHERE clause, but you only closed the WHERE parentheses.
Also, AFAIK, you don't need to call a get if the stage was properly set. The copy into command will place it in your stage, you then retrieve it from that stage but you can do this by the normal way of accessing the stage you specified. So if you sent it to a s3 bucket, you'd just access the resource from S3 as if it were any other file.
Lastly, remember there are many useful parameters you can indicate in the FILE_FORMAT, such as Record_delimiter, compression and how to handle nulls.
And remove the last semicolon after csv, that's going to cause another error because HEADER is not a valid instruction on its own.
Also you don't have to put HEADER = TRUE between brackets. Brackets in documentation mean it's an optional parameter.

Karate call read feature failing with reference error

I am trying to invoke a feature for each element of json array
* def values = karate.mapWithKey(values, 'value')
* def result = call read('my-feature') values
My feature is defined as
#Ignore
Feature: My feature
Background:
*some task
Scenario:
# TEST: My scenario
Given path urlPath, value
This works fine if i use #Tags and only run this scenario.
But on trying to run all karate tests, this fails with error
com.intuit.karate.exception.KarateException: my-feature.feature:15 - javascript evaluation failed: value, ReferenceError: "value" is not defined in at line number 1
How do i fix this?
I have marked the ignored feature as #Ignore, but that doesnt help
Got the solution ,
I was using #Ignore annotation but it also need to be mapped at APITest class
Defining
#KarateOptions(tags = {"~#Ignore"})
And marking the feature file as #Ignore, solved my issue
Shouldn't it be:
* def result = call read('my-feature') ids
If still stuck, follow this process please: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Not able to use variable defined in karate-config.js in my feature file

I want to set a Global variable for Base Test Data location which can be used in all of my feature files.
In karate-config.js i have made below changes -
var config = {
env: env,
INPUT_JSON_PATH: 'com/company/project/module/TestData'
}
And in my feature file I am trying to use it as -
Given path '/myService'
And request read('classname:INPUT_JSON_PATH/Exception_Handling/Mandatory_Fields_missing.json')
When method POST
Then status 400
But somehow its not getting resolved and I am getting error -
could not find or read file: classname:INPUT_JSON_PATH/Exception_Handling/Mandatory_Fields_missing.json
Any idea, what am i missing here?
Thanks,
Abhi
Just keep in mind that read() and other parts of the right-hand-side are treated as ordinary JavaScript. Maybe you were intending to do this:
And request read('classpath:' + INPUT_JSON_PATH + '/Exception_Handling/Mandatory_Fields_missing.json')

How to pass the background response value of the to another feature json in function value using Karate

I have got the response in the background to one of the request and passing to the function for polling purpose and need to run until specific condition met. In that function, I need to pass the values to the calling feature JSON file
while (true) {
var result = karate.call('extractProgress.feature') packageid; -- package id
is response of another request
I followed the similar way as mentioned but in that not passing any parameter.
https://github.com/intuit/karate/blob/933d3803987a736cc1a38893e7039c4b5e5132fc/karate-demo/src/test/java/demo/polling/polling.feature
But i am getting the below error
feature(com.intuit.karate.testng.KarateTestngTest):
java.lang.RuntimeException: javascript evaluation failed: packageid,
ReferenceError: "packageid" is not defined in at line number 1
Input for call inside js should be given as
karate.call("<featureFile>",yourInputVaraible);
refer this on doc
https://github.com/intuit/karate#the-karate-object
It sounds wrong to me, maybe you have a typo.
Also please read the docs carefully. Only JSON is supported as a call argument.
The best way for you to get support is to follow this process, else no one can help you with the limited info you seem to be providing in your questions.
https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Jmeter: validating Code in Beanshell Sampler

Here is the simple code
vars.put("str" , "${__time(dd/mm/yyyy HH:MM:SS)}");
log.info("${str}");
I am expecting to see the value of str in logs but I am getting ${str}. I am validating it because I have to assign the current time to a variable and later want to use it in script. But I am not getting the value stored in str.
try as follows using vars.get:
vars.put("str" , "${__time(dd/mm/yyyy HH:MM:SS)}");
log.info("str " + vars.get("str"));
I wouldn't recommend inlining functions and/or variables into Beanshell script as you may face syntax error issues, i.e. type mismatch if the value has quotation marks.
So either use log.info(vars.get("str")); or use Debug Sampler and View Results Tree listener combination to see JMeter variables values.
More information: How to Debug your Apache JMeter Script