Karate API testing - unique value [duplicate] - java

This question already has an answer here:
How to set and retrieve the global variable's values in the feature file in karate?
(1 answer)
Closed 1 year ago.
I was wondering if anyone knows this karate problem I have.
Scenario: a user can create his profile
Given path '/signup'
And request { "username":"#(username)", "password":"#(password)" }
When method POST
Then status 200
the username has to have a unique value to get a 200 response. In this case it runs once but for obvious reasons doesn't run again.
Is there a way to hypothetically run the post request or perhaps use a dummy value?

Have you tried Postman? It's a program for testing APIs.

Related

Is karate-configure.js processed each time a request is made? [duplicate]

This question already has answers here:
How to share variables between feature runs in Karate?
(2 answers)
Closed 1 year ago.
I understand that karate-configure.js is processed for each scenario or each example under scenario outlines.
However, I found one interesting thing. In my karate-configure.js, I am generating UUID
and this traceId is being retrieved and set in Background under a feature file.
I have a scenario where I am sending two requests, one for post followed by delete. I realized that although the first request takes the header set in Background but the second request doesn't.
So I added a line for header before sending second request:
To my surprise(although this is desirable), I found out that traceId in second request wasn't the same as the one used by previous request. Does that mean karate-configure.js was processed before sending the second request, even though both are part of one scenario.
I'm pretty sure you have a configure headers routine also in action otherwise this shouldn't happen. Of course it is impossible to tell without seeing all your code.
So if you think you have found a bug in Karate, please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Trigger email using java after 2 hours [duplicate]

This question already has answers here:
Scheduling a time in the future to send an email in Java or Python
(6 answers)
Closed 5 years ago.
I want to trigger an email with user details in that email after two hours if the user updated basic information. I used TimerTask class in java and it was working fine. But planning to use ScheduledThreadPoolExecutor.java.
My question is,
Since using multithreading, I must avoid race condition (For that I am using ScheduledThreadPoolExecutor.java or TimerTask.java).
User can update his/her basic details N number of times within two hours.So, after two hours I have to send mail with updated details.How to track that timing?
Is there any better approach for this?
Since using multithreading, What are the scenarios I have to cover?
Thanks in advance,
A quick approach is, each time when you do such update email, capture all the necessary data (i.e. copy it) within the task so you totally avoid locking concern. Given your application I think this is sensible and sufficient.
For 2) depends on if you wish to do conflation (i.e. keep only the latest task in the queue) or you wishes to just let me be.

How to Display JSON Objects in Internet Explorer [duplicate]

This question already has answers here:
How can I convince IE to simply display application/json rather than offer to download it?
(9 answers)
Closed 8 years ago.
I have a RESTful web services application that reads from the database and returns objects in JSON format. It works flawless in Chrome and Firefox. Unfortunately, when I am testing it in Internet Explorer (IE), IE does not want to display JSON objects. It asks if I want to save it. I don't want to save it. I want to display JSON just like in Chrome and Firefox.
Could anyone please point me in the right direction on how to fix it? I read somewhere that I can tweak the properties of my IE browser in order to display JSON as plain text, but this is not an option for me. In the future the application will be used by other people, and some of them might use IE as their browser.
My code looks something like this:
#GET
#Path("/read")
#Produces("application/json")
public Something read(#QueryParam("page") String page){
//bluh bluh bluh
}
Thank you.
The question appears very similar to another question asked here
How can I convince IE to simply display application/json rather than offer to download it?
The second answer specified there seems to be what you want.
IE is not handling rightfully the content type application/json.
You could change the content type, accordingly to the user-agent but it's kind of dirty. You could also change it to text/javascript for everyone, it's a little less dirty.

Get Request source URL in PHP and Java [duplicate]

This question already has answers here:
HttpServletRequest - how to obtain the referring URL?
(4 answers)
Closed 7 years ago.
I want to determine the website from which the request to the particular website has been called.
For Example..I have a website www.ex.com.
Now this website link has been there on three websites www.a.com, www.b.com, and www.c.com.
Suppose one user has clicked the link from www.a.com to go to www.ex.com. Now I want to determine that the request has come from the www.a.com and then the page in www.ex.com will be displayed accordingly.
Similarly if the user has clicked the www.ex.com link from www.b.com then the page will be displayed accordingly.
So how can I determine this request source, means from which website www.ex.com has been called?
It is good if you will explain this using code in PHP and JAVA.
I don't know about in Java, but in PHP you can use $_SERVER['HTTP_REFERER'].

Request Param ordering [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Ordering of values in HttpServletRequest.getParameterValues()
We have J2EE based web application. On server side, we want to get parameters in exactly same order in which sent by client browser.
We tried request.getParameterMap() and request.getParameterNames() but these methods does not returns parameters in same sequence as send by client browser.
How can we get parameters in exactly same order in which sent by client browser?
Request parameters are stored internally in a map so you should make no assumptions about their order.
But why don't you just read them as they are and then sort them?
I am not sure why do we need to rely upon order of the parameters sent. Can you let know why thats required, may be you can solve the problem by alternative methods.
This is not even Java related.
You can't even rely on the browser to send the request params in a specific order.
Besides that as #mgamer noted, you can't make assumptions about the parameters order.
What you can do if you need to read the params in some predefined order, is to create some scheme in which you can do that easily. For example send a JSON object or use some simple format like param1=val&param2=another-val etc.

Categories

Resources