scottschafer / cypressautomocker Goto Github PK
View Code? Open in Web Editor NEWcypress-based library for capturing APIs and replaying them as mocks
cypress-based library for capturing APIs and replaying them as mocks
after file recording, wait
for alias route fails in test
Step: "Add the cypress web hooks to your application."
Where exactly do those lines go? Into the application itself? Or somewhere in cypress. Is there any other way to do it? I am testing a web app that is already deployed to a server, so I can't change any of the application files themselves
The query is blank for these for me:
{
"method": "POST",
"path": "",
"query": "",
"request": "",
"response": "",
"status": 402,
"statusText": "Payment Required",
"contentType": "text/html; charset=utf-8"
},
This is preventing the failing query case and successful query case from working correect.
We were trying to use it in ng6 app test
But got error regarding missing addEventListener method
i was able to fix it using
addEventListener: function(callback) {
this.object.addEventListener(callback);
}
I have a request in my application that it is correctly being writen to its mockup but after running the test it always gets aborted.
Here is an example of the mocked call
{
"url": "http://localhost:4200/translate/translate/invoices-payments/en_US",
"method": "GET",
"status": 200,
"body": null,
"response": {
"views.document_center.reference_searcher.select_reference_type": "Reference Type",
"views.lien_release.message_confirmation_description1": "Massive Request submitted"
}
}
Everything looks ok, but I don't know why the XHR stub gets aborted. Any ideas?
Mocking seems to work for most of my calls but some are saying MOCKING ON, but letting this fall through
. Why is that? Seems to happen to calls that it does a lot of to the same endpoint but different querystring.
The endpoints are recorded and saved as json.
Since this isn't maintained continuously, please can you let us know the last working version of Cypress where this module works as expected?
You mention on the README that:
we are using a different approach to testing now and so keeping this updated is not a top priority for me.
What method are you using now?
Mocks are not being stored/generated. but it is creating files like testCounter.json but this file is empty.
not sure if anything else need to be done.
Looks very promising, but I couldn't get it to work under TypeScript.
My specs as well as my commands are written in TypeScript and when I try to import the "cypressautomocker/include-in-tests" it doesn't work:
Would be great if someone has figured out how to use cypressautomocker alongside TypeScript.
Thanks in advance for all hints!
Hi,
I'm working for AlertMedia and we are making some improvements on the automocker and such (https://github.com/alertmedia/cypress-auto-mock). We were wondering if you were open to having us merge our changes to your branch so we can help maintain it. Our changeset deviates quite a bit, so we'll likely need to refactor to get it working wit yours.
A couple of bugs fix and changes are:
Let us know what your thoughts are. We are heavily invested in automock so we want to make sure that we can help maintain in any way possible.
Joeny
Hey thanks for the lib! I was able to get it to work in 1 test. But another test passed before and is now failing. Now I get this error and it never finishes:
This is after adding
const MOCK_FILENAME = 'bookTripSpecRecording'
before(() => {
cy.automock(MOCK_FILENAME);
})
after(() => {
cy.automockEnd()
})
The test that fails is an, "expected id of element to contain 'text' kind of assertion.
I'm not sure if it times out in my test or in waiting for automock to complete - any ideas? Thanks!
This is causing Automock to fail when using Cypress @^3.3.0
Situation:
We've got a create-react-app where we are using the Fetch API extensively. Now we know Cypress doesn't understand the Fetch API just yet so we do the following in support/commands.js
:
beforeEach(function() {
// If we remove window.fetch(), the polyfill will revert to XHR.
// Cypress only supports XHR stubbing, so this is a needed evil polyfill trigger
Cypress.on('window:before:load', win => {
win.fetch = null;
});
So far so good and this actually works while testing the app. The responses are coming in and tests pass based on those responses. However, the responses and requests are not saved in the automock files.
This is an example file of the automock we're getting:
[
{
"method": "GET",
"path": "/api/user/preferences/something",
"query": "",
"request": "",
"response": {},
"status": 200,
"statusText": "OK",
"contentType": "application/json;charset=UTF-8"
},
]
I'm happy to help and I'll investigate on my own as well, but any pointers on why this would break are more than welcome. We're very close to adopting Cypress in our projects, but the auto-mocking library really makes or breaks the DX for us.
What I've already tried:
Research findings:
In autoMockCommands.js
on line 178 and 181, the objects are empty. The XHR object itself does contain the responses and requests, but, it is a Blob. It silently errors in the following block:
try {
responseObject = JSON.parse(responseObject);
console.log({ responseObject });
} catch (e) {
console.log(e);
debugger;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.