Multi threaded access requested by thread Thread[pool-2-thread-1,5,main] but is not allowed for language(s) js [duplicate] - karate

This question already has answers here:
Karate - Multi threaded access requested - issue
(2 answers)
Closed 1 year ago.
I'm converting about 2800 tests from Karate 0.9.6 to Karate 1.1.0. While going through the breaking changes and refactoring the existing tests I'm encountering a lot of tests randomly failing due to the error:
Multi threaded access requested by thread Thread[pool-2-thread-1,5,main] but is not allowed for language(s) js.
These are for different reasons all over the place. Most are from Background steps but not all. Here are a few cases that fail:
* configure headers = { cache-control: 'no-cache' , Accept: 'application/fhir+json' }
* def authToken = callonce read('classpath:com/company/tests/token/AuthToken.feature')
And header Access-Control-Request-Headers = 'Content-Type'
I tried to create a project to duplicate the issue but it seems random. Are there known issues with this?

I really hope that it is this issue: https://github.com/intuit/karate/issues/1725
Which will be easy to confirm, just upgrade to 1.2.0.RC1
If that doesn't work, that will be extremely bad news and you will have to submit a way to replicate.
And do note that the new JS engine doesn't like Java or JS functions being passed around in callSingle() or callonce: https://github.com/intuit/karate#karatecallsingle (see the paragraph that begins with IMPORTANT:)

Related

How to create a dynamic URL by a previous scenario response in Karate DSL [duplicate]

Does Karate supports a feature where you can define a variable in a scenario and reuse it in other scenarios in the same feature file. I tried doing the same but get an error. What's the best way to reuse the variables within the same feature file ?
Scenario: Get the request Id
* url baseUrl
Given path 'eam'
When method get
Then status 200
And def reqId = response.teams[0]resourceRequestId
Scenario: Use the above generated Id
* url baseUrl
* print 'From the previous Scenario: ' + reqId
Error:
Caused by: javax.script.ScriptException: ReferenceError: "reqId" is not defined in <eval> at line number 1
Use a Background: section. Here is an example.
EDIT: the variable if in the Background: will be re-initialized for every scenario which is standard testing framework "set up" behavior. You can use hooks such as callonce - if you want the initialization to happen only once.
If you are trying to modify a variable in one scenario and expect it to be now having that modified value when the next Scenario starts, you have misunderstood the concept of a Scenario. Just combine your steps into one Scenario, because think about it: that is the "flow" you are trying to test.
Each Scenario should be able to run stand-alone. In the future the execution order of Scenario-s could even be random or run in parallel.
Another way to explain this is - if you comment out one Scenario other ones should continue to work.
Please don't think of the Scenario as a way to "document" the important parts of your test. You can always use comments (e.g. # foo bar). Some teams assume that each HTTP "end point" should live in a separate Scenario - but this is absolutely not recommended. Look at the Hello World example itself, it deliberately shows 2 calls, a POST and a GET !
You can easily re-use code using call so you should not be worrying about whether code-duplication will be an issue.
Also - it is fine to have some code duplication, if it makes the flow easier to read. See this answer for details - and also read this article by Google.
EDIT: if you would like to read another answer that answers a similar question: https://stackoverflow.com/a/59433600/143475

Karate - Is it possible to read multiple feature files and send parameters in an afterScenario function? [duplicate]

This question already has answers here:
Dynamic scenario freezes when called using afterFeature hook
(2 answers)
Closed 1 year ago.
I have read elsewhere on here that I can indeed call another feature file in an afterScenario function such as:
karate.configure('afterScenario', read('some.feature'));
However, can one send multiple feature files and tagging specific scenarios and send parameters?
I have two different calls I need to make to "clean up" after each of my test scenarios:
* call read(etc.feature#etc')
* call read(etc1.feature#etc1') { etc: '#(etc)' }
I did try sending both of those calls through (both in a single karate.configure and multiple) and using the parameter but it failed. Is it possible to do?
EDIT: I am attempting the following an am getting more promising results but still not there.
* configure afterScenario =
"""
function(){
karate.log('etc');
karate.call(etc#etc');
}
"""
No, it is not possible. You are welcome to contribute code. You can always do a karate.get('someVarName') in case you want to access data.
You may be able to call a single feature (or JS function) that in-turn calls multiple other features. Such over-engineering is not something I personally recommend for tests.
Also see: https://stackoverflow.com/a/60944060/143475

How to print karate api configuration settings [duplicate]

This question already has answers here:
Logging Messages from Java Class back to the Karate Report
(3 answers)
Closed 1 year ago.
I am trying to print karate configuration settings(like readTimeout, connectTimeout etc.) in a test. Below is the sample request and I am configuring readTimeout and would like to print the same. Can someone please help me with this. Thanks in advance
Given url 'http://dummy.restapiexample.com'
And path 'api/v1/employees'
* configure readTimeout = 100000
* print readTimeout //nothing printed
When method GET
Then status 200
And print response
This is not currently supported as most teams don't need this. It sounds like you are attempting to write some custom framework using Karate. You are welcome to contribute code as this is an open-source project - or switch to some other framework.

How to send back to back http post request without waiting for response in Karate framework [duplicate]

I am using karate for automating the things in my project and I am so much exited to say that the way karate gives solutions on API testing. I have a requirement in my project where I need to check the effect on the system when multiple users are performing the same task at the same time(exactly same time including fraction of seconds). I want to identify the issues like deadlock, increased response time, application crashes etc... using this testing. Give me a glint that how can I get concurrent testing solution in karate?
There is something called karate-gatling, please read: https://github.com/intuit/karate/tree/master/karate-gatling

In Karate DSL, is there a way to define custom keywords for 'Given' step [duplicate]

This question already has an answer here:
In the Karate DSL Framework, how can we add custom step definitions to expand its functionalities beyond REST capabilities?
(1 answer)
Closed 1 year ago.
I am working on a Karate DSL project. I have 2 dependent ( A and B) SOAP transactions that I am testing. The 1st transaction namely A needs to be completed before my 2nd transaction B. I am able to accomplish this by calling the A's feature file from B.
My current code looks like this :
Background:
* url = https://www.abcshgda.com/service
* def result = call read(A.feature)
Scenario: B needs to run once the prerequisite A is completed.
Given request read(B_req.xml)
When soap action ''
Then status 200
But what I really want to do is something like this :
Given A
When SOAP ''
Then status 200
Since Karate is DSL, is there a way I can do the above without actually using the predefined keyword request and reading the request XML. Instead have A do that in the background.
Any help is greatly appreciated.
No. This is a deliberate design decision, if you want more details, read this thread: https://github.com/intuit/karate/issues/398
Karate seems to be working fine for you already and my opinion is you are un-necessarily trying to make it "look more readable" but you really won't gain anything from this from my experience.
The best you can do is this, if you have defined a JS function (or Java utility) that takes care of doing "A":
Given myJsFunctionThatCallsA()
And request read('B_req.xml')
When soap action ''
Then status 200