Mocking server side requests for end to end testing by cypress - testing

I am using Cypress for end to end tests. To test my payment process I need to mock the request of my back end(express) to bank for transaction. So when the cypress test clicks buy, a request goes to backend and the backend sends a request to bank for purchase, then the bank sends response to backend. So I need to test everything except requests to/from bank. From this answer I assume there is no way to mock server side requests by cypress. Hope someone can show me that I am wrong and the way of doing that!
I was hoping that cypress plugins will let me to do that, but seems like I misunderstood the purpose of them.

Related

Checkout operation gives 403 response code JMeter

Hi there I am conducting a Stress test form JMeter. And I am doing a checkout operation for a shopping controller. But for most of checkout request are failing with 403 response code.
As you can see if I check the response data the page title says 503 but sample result says 403. So it is a bit confusing to me. And also for checkout operation I am using a module controller for login , so each time user do the checkout it should login. also I am using regular expression extractor to extract he csrf token for cart. So there should not be any authentication issues as the 403 error indicates. Can you please help me with this?
If you are sending the checkout requests in a production environment (like checkout on Amazon with PayPal), it is very normal that most of your requests are failing. Because it is some sort of protection to avoid frauding. You are sending lots of checkout request from the same ip address, so server starts to think that you are playing some sort of game there and decides to block you. In real-life performance tests; companies usually choose to mock this checkout endpoints to bypass the process or they use some test cards.

E2E Testing a frontend and mock a request the backend is making with Cypress

Currently when creating a customer during an e2e testcase, my stripe-like payment gateway says "Customer already exists" which is true because this testcase has been run once already.
What is the high level solution? If it would be a unit test, I think mocking the payment-provider request would be the way to go. But in this case I can only intercept the requests that go from my frontend, right? I could mock away the whole request to my backend but that's not the point of e2e testing I think.
I also thought about some sort of flag or environment variable so that the backend knows if it's currently e2e tested (and in this case behave differently, eg not make this specific request). But I think that's not good practice.
Okay I figured out something. I think e2e should test the integrated services too, like the integration between my backend and the payment gateway.
When the test starts, I modify the email (which was the duplicate key for the payment provider) by doing the following little code snippet. Works for now and I think it's not that bad:
user.email = user.email.split("#").join(`${Date.now()}#`);

How to stub an API when testing with Selenium Server

I'm using Nightwatch.js to test a MERN stack application—it makes calls to the Twilio API when it receives a POST request at /sms/outgoing/.
I would rather not send SMS messages every time I run my e2e tests—instead I'd like to stub out the behaviour and, ideally, return the request data, so that I can check my app is submitting the correct info.
I have looked at libraries such as nock and fetch-mock, but neither of these will work with tests that rely on selenium.
Is there a library that can intercept requests made by Selenium Server and provide the stubbing behaviour I'm after?
As you have mentioned nock and fetch-mock, I assume you're using a node server?
If that is the case, you could modify the server to detect an environment variable process.env.MOCK_API and return hard-coded responses to fetch request using fetch-reply-with

JMeter's ResourceLastAccessedTime GET request failed

I am trying to use JMeter to test our Web Application. We originally used LoadComplete to test our Web Application, but because LoadComplete is not able to run on a non-GUI mode, we were not able to use the max stat’s from our test server (strain our 8 CPU’s and 8GB’s of RAM). That is why I moving towards JMeter (https://blazemeter.com/blog/5-ways-launch-jmeter-test-without-using-jmeter-gui).
The test includes logging in, choosing a specific app, do a simple task through this app and then end the recording. The HTTP Requests, which are failing are printing Failed Access on their Response Data on the View Results Tree.
I used the HTTP(S) Test Script Recorder to record each HTTP request. My JMeter project is failing on a few different HTTP Requests, which includes oauthtoken Get Request that includes jessionid="item", a GET resourceLastAccessedTime Request, and a couple GET resourceLastAccessedTime Requests. I tried to follow blazementer's guidance for how to use JMeter for Login Authentication, because these requests seem to be involved with the authentication of each user after logging in and the problem I am getting on Response data for each of these requests on the View Results Tree it says Access denied. (https://docs.blazemeter.com/customer/portal/articles/1743663-how-to-use-jmeter-for-login-authentication-).
One of the steps is to "copy and paste" the Parameters from the Post request after you login to these requests. I can add these parameters to these requests right below where it says Send Parameters with the request, but our POST request only has two parameters (the login name and the password). Is there somewhere else to look for these parameters?
I tried a combination of a lot of different attempts, but I am still unsuccessful (meaning: I moved the Regular Expression Extractor to a few different HTTP requests and I moved which HTTP requests to put those parameters and I have not been successful yet).
Do you know of a URL that could be helpful for this?
Don't trust Test Script Recorder! It doesn't follow any logic while recording your requests. It just records requests processed through proxy as they are. In case you use parameters that can't be defined as constants, the best way would be to rewrite the script manually.
Be patient and spend some hours (only once!) to learn how to construct any test scenarios (even complex) manually using Jmeter GUI. It will save you a lot of time for debugging.
It seems like (just a guess) that your test scenario doesn't contain Cookie Manager item. Based on what you wrote above, it seems like after logging to serer (by sending POST with login and password) it sets some cookies by Set-Cookie HTTP header. These cookies should be included in every next request as a prove that you successfully logged in before (the most common logic for simple web applications). So, if you get Access Denied, means you didn't include appropriate cookies in test request. Use Cookie Manager for that.
Feel free to ping me in case you need any assistance.
Jmeter help manual is all you need to know about how each element works.
P.S.: Jmeter also can generate distributed load from multiple slave servers, in GUI and CLI modes both. So, in case you need to stress your server yout, Jmeter is the best choise.
And welcome to Jmeter users family! Good luck.

Want to know little info about enabling Asynchronous Request Processing in Apache Server?

I'm working upon Paypal integration for our website. As we know, we will provide IPN URL for every orders processing through Paypal, Last week, I have given a server URL for the Paypal Notification and also using that, I have processed the payments.
But, today, when i shifted my projects into an another server, where i have implemented the same IPN system. But I dont get the Notification for the same URL, in my new server. It seems that my new apache server doesn't support Asynchronous Request Processing.
What can i do to make my server to process Asynchronous Requests. Anyone please let me know, how can i do it?
Thanks in advance.
The "asynchronous" in the word doesn't refer to a feature that has to be activated in Apache. It's just that PayPal sends the request whenever it's ready, and your script calling it has no way of telling when that is.
Most likely, the server move changed something in the server URL. Try out some of the requests that you are telling PayPal to do manually and see what happens and what errors you get.