I am using Apache Jmeter. I have a script with different controllers inside a globalNav. I would want to make it so that if the condition in my first if controller is true, i send a certain cookie to all other requests in the other controllers. If the condition in the other if is true, i send another type of cookie to the other controllers
I know my if condition is correct because i tested it in its own controller but i can't seem to make it work globally. Please note that i'm new to Jmeter.
Thanks
I don't think it will work this way, if you don't have any Samplers under the If Controller the HTTP Cookie Manager will be silently ignored. Moreover according to JMeter Scoping Rules the cookie will be created only for the HTTP Request samplers which are under the particular If Controller.
I would rather go for JSR223 PreProcessor and the code like:
if (vars.get('somevar') == 'foo') { // change it to your condition like in the If Controller
sampler.getCookieManager().add(new org.apache.jmeter.protocol.http.control.Cookie("my-cookie", "foo", "example.com", "/", false, System.currentTimeMillis() + 10000))
} else {
sampler.getCookieManager().add(new org.apache.jmeter.protocol.http.control.Cookie("my-cookie", "bar", "example.com", "/", false, System.currentTimeMillis() + 10000))
}
Related
I'm testing an app with Cypress, and the tests go against real HTTP servers. I'm not stubbing the HTTP requests.
Is there a way to make my tests fail if any of the HTTP requests fail?
There is a solution that seems ok in this other SO post, but I wonder if there is a more proper solution. In my case, I'm not always converting all HTTP errors into invocations to console.error.
You can listen to the request using cy.intercept() & check the status code etc.
Ref : https://docs.cypress.io/api/commands/intercept.html#Intercepting-a-response
Example 1 :
// Wait for intercepted HTTP request
cy.intercept('POST', '/users').as('createUser')
// ...
cy.wait('#createUser')
.then(({ request, response }) => {
expect(response.statusCode).to.eq(200)
})
Example 2 :
// Listen to GET to comments/1
cy.intercept('GET', '**/comments/*').as('getComment')
// we have code that gets a comment when
// the button is clicked in scripts.js
cy.get('.network-btn').click()
// https://on.cypress.io/wait
cy.wait('#getComment').its('response.statusCode').should('be.oneOf', [200, 304])
I have several controllers that each responds to a particular endpoint. Let's say "GET /api/users/{userId}" and "GET /api/posts/{postId}". I'm implementing another endpoint "/api/batch" that accepts a batch request so that the client could POST an array of APIs to call, such as
{
requests: [
{
method: "GET",
url: "/api/users/1"
},
{
method: "GET",
url: "/api/posts/1"
}
]
}
On Spring boot, inside the batchController, how can I create a Request object based on the url and then dispatch it to the corresponding controller? I know that I could use a HTTP Client or a RestTemplate to call directly the endpoint inside the batchController, but I would like to avoid that because it implies a creation of an extra HTTP request.
Thank you.
I'm trying to use Fine Uploader 5.15.0, set up with multiple file fields & uploader instances (multiple: false is set on each) which all display and select files correctly. They are posting to a custom endpoint that is returning any parameters to me. Uploads are set to happen as soon as the file is selected, and file and QQ parameters are sent okay.
My problem is when I attempt to send additional data to the server along with the upload.
I have tried including my additional parameters in the endpoint of the request option, and as a params node added to the options variously as follows:
uploaders[1] = new qq.FineUploader({
element: document.getElementById("uploader-1"),
multiple: false,
request: {
endpoint: "default.cfm",
paramsInBody: false,
params: {
act: "action/processFile",
uid: 4747
}
}
})
Calls without any parameters available in either form or URL scopes.
Removing the params section and attempting to pass them via endpoint:
request: { endpoint: "default.cfm?act=action/processFile" }
Works fine, but obviously no additional parameters.
request: { endpoint: "default.cfm?act=action/processFile&uid=4747" }
Calls without any URL parameters.
request: { endpoint: "default.cfm?act=action/processFile&uid=4747" }
Calls with "act" available, but all others have their ampersand stripped out, so the parameter name becomes "amp;uid"
According to https://blog.fineuploader.com/include-params-in-the-request-body-or-the-query-string-479ac01cbc63 and other questions on here the first one should work. For the others obviously FineUploader is doing some additional processing on endpoint that is wiping out my parameters.
I'm missing something essential, can anyone educate me?
Thanks!
I'm using Spring Boot to create an API that needs to be consumed in Angular 4. Spring and Angular are on different ports.
The problem is that Spring's ResponseEntity raises an error in Angular.
#RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ResponseEntity getFlow(#PathVariable int id) {
Flow flow = flowService.findById(id);
return new ResponseEntity(flow, HttpStatus.FOUND);
}
Now, I can perfectly use Postman to test the API and it works.
But when I make a request from Angular, it returns an error:
Strangely, it returns an error alongside the requested object.
Now, the cause of the problem is that the Spring Boot application returns a ResponseEntity and not a normal object (like String), and Angular doesn't know how to interpret it. If the controller returns just a Flow object, it works.
How can it be solved using ResponseEntity? Or, how else can I send the object alongside the HTTP status code?
Also, in #RequestMapping put produces = "application/json", and in get request in angular, add http options :
const httpOptions = {
headers: new HttpHeaders({
'Accept': 'application/json',
'Content-Type': 'application/json'
})
};
So your get request looks like this:
this.http.get(url, httpOptions)
As per the document mentioned here
https://docs.angularjs.org/api/ng/service/$http
A response status code between 200 and 299 is considered a success status and will result in the success callback being called. Any response status code outside of that range is considered an error status and will result in the error callback being called. Also, status codes less than -1 are normalized to zero. -1 usually means the request was aborted, e.g. using a config.timeout. Note that if the response is a redirect, XMLHttpRequest will transparently follow it, meaning that the outcome (success or error) will be determined by the final response status code.
As you are sending an instance of ResponseEntity(HttpStatus.Found) whose Http status code is 302 which doesnt fall under the success range thats why error callback is called.
Try returning the content like this
return new ResponseEntity(flow, HttpStatus.OK);
I'm working on a integration test where authentication is needed.
Session state (ie. cookie) seems not to be maintain beetween requests.
Is there a CookieManager or something like that ?
#Test
public void whenAuthenticatedUserRequestAForbiddenUrlShouldObtain403() {
def client = new RESTClient('http://127.0.0.1:8080/app/')
def login = client .post(
path: 'api/login.json',
body: [j_username: 'user', j_password: 'test'],
requestContentType: ContentType.URLENC)
def resp = client .get(path: 'forbidden-url')
assert (resp.status == 403)
==> FAILS status = 200
}
It looks to me like the problem is not losing session state but rather the 'forbidden-url' might not be specified as secure in the first place. If it were, it does not seem that client request request should succeed EVEN IF you login. Try removing the login at the top and if you still get 200, you probably don't have the URL secured anyway.