Does Karate Support displaying the assertions or failures in the html Report for Server side scenario of incoming API requests to a mock server? [closed] - karate

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
This might be a dumb question or may be already answered but i wasnt able to find any answers for this :
I have a requirement of testing a Micro Service that sends out an API request to a particular endpoint or a Consumer. I was able to successfully write the mocks using karate and send back response on required filter criteria and validations happening inside the "server-side" scenario.
If any assertion fails it does log that server-side scenario failed.
I wanted to know how i can add these to a report ( i currently use the cucumber reporting which can be integrated with Karate) and fail a test if any server side scenario fails?
Any help would be appreciated.

Great question, this is an unusual requirement - but you can be super-creative with Karate mocks.
Remember - a Karate mock is a legitimate REST server, so all you need to do is add one more request "route". You already know that you can "collect" data into global variables defined in the Background. So something like this:
Background:
* def errors = []
Scenario: pathMatches('/myapi')
* def result = karate.match("request == { foo: 'bar' }")
* if (!result.pass) errors.add(result)
* def response = { some: 'response' }
Scenario: pathMatches('/mytest')
* def response = errors
Now at the end of your test, just call the additional /mytest API and you get a nice JSON array of all errors.

Related

Javascript fetch POST request formdata size limitation CORS error? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I'm attempting to make a pretty straightforward fetch request to one of our business' APIs (back end running .NET Core 3.1/ASP Core MVC), and it's giving me an inconsistent result. If the length of the token value passed via a formdata field is greater than about 1000 characters, the request gets stopped with a CORS error (the pretty standard "has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource"), but below that length the request goes through without issue. Running on Chrome or on Firefox both give me a CORS error about missing this header value. There aren't any specific limits on input size set within the API itself or the IIS server it's running on, so I'm at a loss for what might be going on.
I'm assuming this is one of those times when a CORS error is really just masking something else going on. Is there something obvious I'm overlooking?
obj = {
data: {
idToken: "A".repeat(1200) // just for testing purposes
}
};
str = JSON.stringify(obj);
const fd = new FormData();
fd.append("token", str);
const BaseURL = "https://XXXX";
const url = `${BaseURL}/api/YYY/getLocations`;
fetch(url, {
method: 'post',
body: fd,
})
.then...
It turned out that the network appliance that handled requests to all of our externally visible API's was imposing a strict size limit on all incoming requests. Once that was lifted to a higher level, everything worked as expected.

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

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:)

Error in SAP BI when trying to send report to destination [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
When I select a report and try to send it to a destination I get this HTTPS error but cant find more info as to why I am getting that.
HTTP Status 500 – Internal Server Error
Type Status Report
Message javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.faces.el.PropertyNotFoundException: Error getting property 'dsGridContainer' from bean of type com.businessobjects.clientaction.shared.sendto.SendToDestinationBean
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Apache Tomcat/8.5.13
Anyone had such or can point me in the right direction ?
It is saying that a setter(void) or getter(return type of its global variable of the same name and the variable it "returns") method with the name "dsGridContainer" in a bean class that is in a shared library application .jar file that has been loaded has an error when called.
*note a setter and getter (and also an "is" boolean method) have an associate global variable of the same name as the methods.
You may be able to get a better comprehensive error output in the server error.log file.

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.

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