Post method gets converted to GET after redirection - karate

I have one POST call related to search.It is like I am sending some data as parameters to call and some in payload.after getting 302 it gets redirected.But the issue is once it gets redirected,POST call gets converted to GET call and payload is lost.As a result I am unable to get desired search result.Is there anything related to config that I might be missing??

Yes this is the correct behavior. Sounds like you need to disable automatic re-directs for this test, see configure. You can do:
* configure followRedirects = false
And then get the redirect location manually as follows:
* def location = responseHeaders['Location'][0]
Refer to this test for an example: redirect.feature

Related

get request for search in JMeter

I am performing a search request in jmeter. So my test plan flow is home then login then product catalogue and then search. I tried to make a post request for search but it failing all the time. I used a CSV file so each time the query is changed. But then I used a get request and used the query variable in the search path like this search?query=${search_input}and then it passed but when i checked the html it is not the correct page. In the html response I also see this
{{noSearchResults.query}}'. But if i put the url on the browser it works fine. Can you please help me with this?
Double check that your ${search_input} variable has the anticipated value using Debug Sampler and View Results Tree listener combination
It might be the case that your ${search_input} variable contains special characters which need to be URL-encoded so you might need to wrap the variable into __urlencode() function like:
search?query=${__urlencode(${search_input})}
JMeter automatically treats responses with status code below 400 as successful, if you need to add an extra layer of check for presence of the results or absence of {{noSearchResults.query}} - use Response Assertion

In karate mocking (karate-netty), how can we override request header value?

Objective:
We want few API calls should go to mock-server(https://192.x.x.x:8001) and others should go to an actual downstream application server(https://dev.api.acme.com).
Setup :
On local, mock server is up with standalone jar on port 8001. e.g https://192.x.x.x:8001
In application config file (config.property)downstream system(which need to mock) defined with mockserver IP i.e https://192.x.x.x:8001
Testing scenario and problem:
1.
Scenario: pathMatches('/profile/v1/users/{id}/user')
* karate.proceed('https://dev.api.acme.com')
* def response = read ('findScope.json')
* def responseStatus = 200ˀˀ
* print 'created response is: ' + response
Now, when we hit API request via postman or feature file then it does karate.proceed properly to https://dev.api.acme.com/profile/v1/users/123/user instead of 192.x.x.x. However, in this request, host is referring to https://192.x.x.x:8001 instead of https://dev.api.acme.com which create a problem for us.
How can we override request header in this case? I did try with karate.set and also with header host=https://192.x.x.x:8001 but no luck.
Thanks!
Please see if the 1.0 version works: https://github.com/intuit/karate/wiki/1.0-upgrade-guide
Unfortunately https proxying may not work as mentioned. If you are depending on this, we may need your help (code contribution) to get this working
If the Host header is still not mutable, that also can be considered a feature request, and here also I'd request you to consider contributing code

JMeter variable in GET request failing

I have a GET Request that is returning an XML that contains a TicketName. I have setup the Regular Expression Extractor with Debug Sampler. It is picking up the TicketName as required and is displaying it in the View Results Tree, with the correct name variable name ticketID_g1.
However when I pass that variable to the next GET request the test plan fails with Non HTTP response message: Socket closed.
The thing is that the GET request looks find when I look at the request tab in the Results Tree.
I have changed my regular expression a number of times with each one extracting the TicketName properly but each time I apply it as a variable the GET request fails. However if I copy the request showing in the Results Tree Request Tab and paste it directly into my browser I get the desired result.
I have been through the manuals and on-line tutorials and it appears that I am doing everything right but obviously I am missing something.
The 1st GET Request returns an XML that contains name="2019-05-09-16-59-54cmrpip000613_EDASERVE" needsPrompt
I am using the following regular expression to extract the name for my variable ticketID
name="([^"]+)" needsPrompt - This works
The Results Tree is showing the following response from the Debug Sampler -
ticketID_g1=2019-05-09-16-59-54cmrpip000613_EDASERVE
When I pass the ticketID variable to the next GET request
//localhost:8080/ibi_apps/rs?IBIRS_action=getReport&IBIRS_ticketName=${ticketID_g1}cmrpip000589_EDASERVE&IBIRS_service=defer
The Response tab in the Results Tree for the second GET request is showing that the request is good but is failing.
GET http://localhost:8080/ibi_apps/rs?IBIRS_action=getReport&IBIRS_ticketName=2019-05-09-16-59-54cmrpip000613_EDASERVE&IBIRS_service=defer
What I am expecting is that this second GET will run with the variable and return a report but is throwing the Non HTTP response message: Socket closed error.
You have below variable which is capturing ticket id.
ticketID_g1=2019-05-09-16-59-54cmrpip000613_EDASERVE
But, in the below request you are passing the same which also have repeated content that is
"cmrpip000589_EDASERVE"
Request:-//localhost:8080/ibi_apps/rs?IBIRS_action=getReport&IBIRS_ticketName=${ticketID_g1}cmrpip000589_EDASERVE&IBIRS_service=defer
Please pass the ticketID variable correctly and hopefully it solves the issue. If I am correct you request should look like:-
Request:-//localhost:8080/ibi_apps/rs?IBIRS_action=getReport&IBIRS_ticketName=${ticketID_g1}&IBIRS_service=defer

Astrid request returning empty

I'm trying to use the http://Astrid.com API, specifically to get data using the method under the "Request Format" section on this page - http://astrid.com/apidoc/file.README.html
The URL I built is:
https://astrid.com/api/7/task_list?app_id=[MY APP ID]&time=1&user_id=[MY USER ID]&sig=[MY REQUEST SIGNATURE]
And it returns this:
{"list":[],"time":1363131562,"status":"success"}
Seems like it worked, but does anyone know why the "list" array might be returning empty? I've created a bunch of tasks in my profile so it should be showing those.
Thanks!
You need to sign in first with the method user_signin. If successful you get a token.
Then you need to call the task_list method providing the token.
You do not need to provide a user id with the task_list method. It is only used to select tasks that you share with this user.
Example for signing in:
https://astrid.com/api/7/user_signin?provider=password&app_id=YOUR_APP_ID&secret=YOUR_ASTRID_PASSWORD&sig=SIGNATURE&time=1365715302.36&email=YOUR_EMAIL
Example for getting your tasks:
https://astrid.com/api/7/task_list?active=true&token=THE_TOKEN&sig=SIGNATURE&app_id=YOUR_APP_ID&time=1365715304.41

how to set HTTP_HOST for WebTestCases in Symfony2

My application is generating some absolute links via $this->get('request')->getHost().
Problem is: when I try to run testcases, I get following error message:
[exception] 500 | Internal Server Error | Twig_Error_Runtime
[message] An exception has been thrown during the rendering of a template ("Undefined index: HTTP_HOST") in "::base.html.twig" at line 69.
Somehow it's clear to me that there is no host when calling my app via CLI, but I think there must be a way to prevent Symfony2 from throwing that error.
Anyone knows how to get rid of it?
You could create the request like this:
$request = Request::create('http://example.com/path');
That will make the HTTP host be set.
Maybe what you could do is to inject the host you need directly in the request headers before calling the getter. The host is retrieved by looking at various parameter values. First, the headers parameter X_FORWARDED_HOST is checked to see if it is set. If it is set, it is returned otherwise the method getHost checks if the headers parameter HOST is set then the if the server parameter SERVER_NAME is set and finally if the server parameter SERVER_ADDR is set.
What you could try is to set the header parameter HOST like this before calling the getHost method:
$request = $this->get('request');
$request->headers->set('HOST', 'yourhosthere');
$request->getHost(); // Should return yourhosthere
That being said, I'm not sure this will solve the problem because the error you mentioning tells us that the template tries to retrieve the value of the index HTTP_HOST but it is not defined. Looking at the methods $request->getHost and $request->getHttpHost, I don't see anything trying to retrieve a value having HTTP_HOST as the index but I could have missed it. Could you post the file ::base.html.twig to see if the problem could be lying there.
Regards,
Matt
Thanks guys- your answers lead me into the right direction.
This is no Symfony2 issue, as i figured out:
It's just the facebook API PHP wrapper which directly accesses the SERVER parameters. This code solved my issue:
$facebook = $this->container->get('facebook');
$returnUrl = 'http://'.$request->getHost();
$returnUrl .= $this->container->get('router')->generate('_validate_facebook');
$_SERVER['HTTP_HOST'] = $request->getHost();
$_SERVER['REQUEST_URI'] = $request->getRequestUri();
$loginUrl = $facebook->getLoginUrl(array(
'req_perms' => 'publish_stream',
'next' => $returnUrl,
));
return $loginUrl;
now my app runs from web and CLI again