-
Notifications
You must be signed in to change notification settings - Fork 17
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
Provide a flexible and simple mechanism to filter entries from the HAR #163
Labels
Comments
derevnjuk
added a commit
that referenced
this issue
Jan 19, 2023
derevnjuk
added a commit
that referenced
this issue
Jan 19, 2023
derevnjuk
added a commit
that referenced
this issue
Jan 19, 2023
derevnjuk
added a commit
that referenced
this issue
Jan 19, 2023
derevnjuk
added a commit
that referenced
this issue
Jan 19, 2023
derevnjuk
added a commit
that referenced
this issue
Jan 22, 2023
derevnjuk
added a commit
that referenced
this issue
Jan 22, 2023
derevnjuk
added a commit
that referenced
this issue
Jan 23, 2023
derevnjuk
added a commit
that referenced
this issue
Jan 23, 2023
derevnjuk
added a commit
that referenced
this issue
Jan 23, 2023
derevnjuk
added a commit
that referenced
this issue
Jan 23, 2023
derevnjuk
added a commit
that referenced
this issue
Jan 23, 2023
derevnjuk
added a commit
that referenced
this issue
Jan 23, 2023
derevnjuk
added a commit
that referenced
this issue
Jan 24, 2023
derevnjuk
added a commit
that referenced
this issue
Jan 24, 2023
derevnjuk
added a commit
that referenced
this issue
Jan 24, 2023
…te (#172) You can specify the `filter` option as a path to a JS/TS module that exports a function to filter out unwanted entries from the HAR. The function should take an [Entry object](http://www.softwareishard.com/blog/har-12-spec/#entries) as a parameter and return a boolean indicating whether the entry should be included in the final HAR or not. Here's an example of how to use the `filter` option: ```js cy.recordHar({ filter: '../support/include-password.ts' }); ``` And here's an example of what the `include-password.ts` filter module might look like: ```ts import { Entry } from 'har-format'; export default async (req: Entry) => { try { return /\"password":/.test(req.request.postData.text ?? ''); } catch { return false; } }; ``` In this example, the `filter` function will only exclude entries in the HAR where the request body contains a JSON object with a password field. You can also specify a `rootDir` option that will be used to resolve the path of the `filter` option. By default, the path is relative to the spec folder. But by providing a `rootDir` it will look for the module in the provided directory: ```js cy.recordHar({ filter: 'cypress/support/include-password.ts', rootDir: Cypress.config('projectRoot') }); ``` closes #163
@cheapsteak I am pleased to inform you that the feature you have been interested in (#85 (comment)) has been released in version 5.13.0. |
derevnjuk
added a commit
that referenced
this issue
Jan 25, 2023
It is now possible to utilize regular expressions rather than strings when specifying the excludePaths or includeHosts options. **Before**: ```ts cy.recordHar({ excludePaths: ['^\\/api\\/products$', '^\\/api\\/users$'] }); ``` **After**: ```ts cy.recordHar({ excludePaths: [/^\/api\/products$/, '^\\/api\\/users$'] }); ``` closes #163
derevnjuk
added a commit
that referenced
this issue
Jan 25, 2023
…#175) It is now possible to utilize regular expressions rather than strings when specifying the excludePaths or includeHosts options. **Before**: ```ts cy.recordHar({ excludePaths: ['^\\/api\\/products$', '^\\/api\\/users$'] }); ``` **After**: ```ts cy.recordHar({ excludePaths: [/^\/api\/products$/, '^\\/api\\/users$'] }); ``` closes #163
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
It would be useful to have a way to filter recorded entries from the resulting HAR file, as the current options (i.e.
cy.recordHar({ /* ... */})
) do not provide enough flexibility for certain use cases.Possible solution
We can add a query parameter that allows the user to filter the recorded entries using a Lucene-like syntax, XPath, or JSONPath. For example:
or
Alternatively, we can allow specifying the path to the module being used to filter them as follows:
Additional context
Cypress is spawning an independent child process that runs a plugin. The test is actually running in the browser. While communicating with each other, Cypress serializes command arguments and passes them to the plugin via WebSocket. Therefore, passing a plain JS function is hardly possible. This feature will give the users more control over the data that is saved and make it more efficient.
The text was updated successfully, but these errors were encountered: