Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index.json empty object, not being recorded #6

Open
dummyaccct opened this issue Jul 11, 2019 · 11 comments
Open

index.json empty object, not being recorded #6

dummyaccct opened this issue Jul 11, 2019 · 11 comments
Labels
question Further information is requested

Comments

@dummyaccct
Copy link

Followed the steps to set up auto-record, but even with the cypress example tests, the index.json file remains empty. I see the task to read and write file, but all that gets written to index.json is: {}
I included const autoRecord = require('cypress-autorecord'); at the top of my test file, and autoRecord(__filename); just inside the context/describe function, and made sure the describe/context and it functions were NOT arrow functions.
Then in index.js I added fs, autorecord and set autoRecord(on, config, fs) in module exports.

Maybe it would help if you included a demo of changes to a cypress example file that would make it auto-record/stub in the readme?

@Nanciee
Copy link
Owner

Nanciee commented Jul 11, 2019

That's a good suggestion and I'll be updating this repo with an example app with the setup. From what you wrote, it sounds like the setup was down correctly. What does your tests look like?

@dummyaccct
Copy link
Author

dummyaccct commented Jul 12, 2019

I tried it with window.spec.js from the cypress examples
So the file looks like:

const autoRecord = require('cypress-autorecord');

context('Window', function () {
  autoRecord(__filename);

  beforeEach(function () {
    cy.visit('https://example.cypress.io/commands/window')
  })

  it('[r] cy.window() - get the global window object', function () {
    // https://on.cypress.io/window
    cy.window().should('have.property', 'top')
  })

  it('[r] cy.document() - get the document object', function () {
    // https://on.cypress.io/document
    cy.document().should('have.property', 'charset').and('eq', 'UTF-8')
  })

  it('[r] cy.title() - get the title', function () {
    // https://on.cypress.io/title
    cy.title().should('include', 'Kitchen Sink')
  })
})

I guess technically all the requests are non-xhr requests. Does auto record only work with xhr requests? Even if that's the case, my actual app has many xhr requests but is still writing nothing but an empty object to the index.json file

Also what is the __filename supposed to be? Logged mine and it is set to /index.js. Is this expected?

@Nanciee
Copy link
Owner

Nanciee commented Jul 13, 2019

Yes, auto record only works for xhr requests because it uses Cypress' built in stubbing mechanism cy.route. You can find more information about that here: https://docs.cypress.io/api/commands/route.html#Syntax. Cypress-autorecord records requests per test, which means that if the test you've written has no xhr requests, nothing will be recorded. I'm not sure if that is the case for you! Do you see any requests showing up when you run your tests? It should look something like this:

Screen Shot 2019-07-12 at 9 26 18 PM

As for the __filename, that was just the fastest and simplest way for me to get access to the filename of the test. I will then use it to auto generate the mock files with matching names. It is definitely expected!

@Nanciee Nanciee added the question Further information is requested label Jul 13, 2019
@dummyaccct
Copy link
Author

There are definitely XHR requests being sent out, but still nothing being saved to the mock file unfortunately.
I tested on the cypress 'network_requests.spec.js' file and the xhr requests were saved to the mock, but not on my actual app.

@Nanciee
Copy link
Owner

Nanciee commented Jul 20, 2019

Could you confirm if you are seeing them being logged when you run your test? How are you making those requests?

@dummyaccct
Copy link
Author

On my actual app the requests are not being logged at all, even though there are XHR requests going out in the chrome network tab (you can filter by XHR, and even with the filter there are plenty of requests, none of them are logged).
The XHR requests are through JQuery I believe

@dummyaccct
Copy link
Author

Tested again today with your updated version, mock file is still empty :'(

@Nanciee
Copy link
Owner

Nanciee commented Aug 1, 2019

I'm going to take some time to look into it this weekend! Will keep you updated.

@Boka-Rafaeli
Copy link

Recorder file is empty

cypress.json
"autorecord": {
"forceRecord": true
}
I see my XHR friends, but file is empty
Please help
image

@Boka-Rafaeli
Copy link

Also all recorded request do not save headers !

image

@Nanciee
Copy link
Owner

Nanciee commented Mar 2, 2021

@Benyamin-Rafaeli Could you provide a bit more detail on the http you are making?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants