Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
994731b
feat: add browser logs
vCaisim Mar 27, 2023
9fdeac5
chore: move from next to react + vite + typescript
vCaisim Mar 28, 2023
1951fcf
feat: add callback option
vCaisim Mar 28, 2023
ca38391
feat: add logs from the Console api
vCaisim Mar 28, 2023
8061f7c
fix: use useSearchParams to get the payload query param
vCaisim Mar 29, 2023
8cbb7e7
fix: clear the payload query param when the payload is removed
vCaisim Mar 29, 2023
fd69bf4
fix: reset the state when the payload param is removed
vCaisim Mar 29, 2023
9aeefe9
feat: update the UI for console messages
vCaisim Mar 29, 2023
b039b88
fix: get the correct values from the Console browser api
vCaisim Mar 29, 2023
de93226
chore: do not use logs from the deprecated Console domain
vCaisim Mar 30, 2023
dacd451
chore: limit the connection retries to the Chrome Debugging Protocol
vCaisim Mar 30, 2023
e512b06
fix: handle electron
vCaisim Mar 31, 2023
599a295
chore: small ui update
vCaisim Apr 3, 2023
601a8ac
chore: mini refactor
vCaisim Apr 3, 2023
540573d
chore: reconnect to cdp before each spec
vCaisim Apr 3, 2023
c062d23
chore: remove docs and ui packages
vCaisim Apr 3, 2023
428f8b0
chore: remove logs and comments
agoldis Apr 5, 2023
a861f77
fix: move the chrome-remote-interface dependences to the plugin package
vCaisim Apr 5, 2023
a728799
chore: import the types from cypress-debugger
vCaisim Apr 5, 2023
8e10453
fix: comments
vCaisim Apr 5, 2023
5eb5578
feat: add PluginOptions type
vCaisim Apr 5, 2023
67c8b7e
update README
vCaisim Apr 5, 2023
d3d1e05
fix: return rdp port depending on browser
vCaisim Apr 5, 2023
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ dump
dump_har
screenshots

# next.js
.next/
out/
build
# vite
tsconfig.tsbuildinfo

# misc
.DS_Store
Expand Down
130 changes: 96 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,128 @@
# Cypress Debugger

Debug cypress tests in CI - use rrweb to capture the execution, cypress hooks to capture cypress commands, and HttpArchive Generator to record the network.
Debug cypress tests in CI - collect and analyze rrweb records, browser network information, and browser console logs for each cypress step.

## Development
The plugin generates a `json` file for each test into the `dump` folder inside the working directory. Each file contains the following fields:

Start the packages in development mode
- `cy` - a list of cypress events. The data is collected from the cypress [`log:added`](https://docs.cypress.io/api/cypress-api/catalog-of-events) event.

- `rr` - a list of [rrweb](https://www.npmjs.com/package/rrweb) records, which represents the mutations in the DOM. The entries are linked to `cy` events on cypress `log:added` and `log:changed` events.

- `har` - an [HTTPArchive(HAR)](http://www.softwareishard.com/blog/har-12-spec/) object, recorded by the [HttpArchive Generator](https://github.com/NeuraLegion/cypress-har-generator).

- `meta` - [`RunContextData`](./packages/support/src/cy/runContext.ts) an object with the following fields:
```typescript
{
spec: string; // spec filename
test: string[]; // test title
retryAttempt: number; // https://docs.cypress.io/guides/guides/test-retries
}
```

- `browserLogs` - the browser logs at a moment in time. The data is collected using [chrome-remote-interface](https://www.npmjs.com/package/chrome-remote-interface).

- `pluginMeta` - the data passed down to the optional `meta` field of the `debuggerPlugin` options argument.

The collected data can be visualized by uploading a file to the web app.

## Requirements

- Cypress version 10+
- NodeJS [14+](https://docs.cypress.io/guides/getting-started/installing-cypress#:~:text=If%20you're%20using%20npm,Node.js%2014.x)

## Setup

Install the package:

```sh
npm install
npm run dev
npm install cypress-debugger
```

Runs a few tests
Add `cypress-debugger` to `cypress.config.{js|ts|mjs}`

```js
// cypress.config.js
const { defineConfig } = require("cypress");
const { debuggerPlugin } = require("cypress-debugger");
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
debuggerPlugin(on);
return config;
},
},
});
```

Add `cypress-debugger` to `cypress/support/e2e.{js|ts}`

```js
// cypress/support/e2e.js
const { debuggerSupport } = require("cypress-debugger");
debuggerSupport();
```

## Usage

Start running the tests with the following command:
```sh
npx cypress run --chrome
```

To run the plugin with the Electron app you need to set the remote-debugging-port launch argument:

```sh
cd apps/web
npm install
npx cypress run --browser chrome
ELECTRON_EXTRA_LAUNCH_ARGS=--remote-debugging-port=9222 npx cypress run --browser electron
```

You will see new `json` files created in `apps/web/dump`. Each file contains fields: `cy`, `rr`, and `har`.
Please refer to the [Electron documentation](https://www.electronjs.org/docs/latest/api/command-line-switches#--remote-debugging-portport) and the [Cypress documentation](https://docs.cypress.io/api/plugins/browser-launch-api#Modify-Electron-app-switches) for more information on usage with Electron.

- `cy` - data from cypress events
- `rr` - data from the [rrweb](https://www.npmjs.com/package/rrweb)
- `har` - data from the [HttpArchive Generator](https://github.com/NeuraLegion/cypress-har-generator)
## Example

Run the local server at http://localhost:3000/ and upload some file from `apps/web/dump` using the UI.
See an example in [apps/web](https://github.com/currents-dev/cypress-debugger//blob/main/apps/web) directory.

### Notes
## API

A `har.json` file could be visualized with [this tool](https://toolbox.googleapps.com/apps/har_analyzer/)
### debuggerPlugin

The [HAR generator](https://github.com/NeuraLegion/cypress-har-generator), currently, only supports Chrome family browsers. Please refer to [this](https://github.com/NeuraLegion/cypress-har-generator#generating-a-har-file) section in order to run cypress for other browsers.
Installs cypress-debugger.

## Usage
```ts
debuggerPlugin(on: Cypress.PluginEvents, options?: PluginOptions): void
```

- call the `install` function inside the `setupNodeEvents` in the cypress config file:
- `on` - [`Cypress.PluginEvents`](https://docs.cypress.io/guides/tooling/plugins-guide) `setupNodeEvents` method first argument
- `options` - [`PluginOptions`](./packages/plugin/src/types.ts) an object with the following fields:
- `meta`: an optional field which is added to the `TestExecutionResult` as `pluginMeta`
- `callback`: a callback function which is called after each test having the current test results as argument

```typescript
const { defineConfig } = require("cypress");
const { install } = require("@currents/cypress-debugger");
Example:

```js
// cypress.config.js
const { defineConfig } = require("cypress");
const { debuggerPlugin } = require("cypress-debugger");
module.exports = defineConfig({
e2e: {
...
setupNodeEvents(on, config) {
install(on, config);
return config;
debuggerPlugin(on, {
meta: {
key: 'value'
},
callback: (data) => {
console.log(data)
}
});
return config;
},
},
...
});
```

- call the `support` function in the `cypress/support/e2e` file:
### debuggerSupport

```typescript
import { support } from "@currents/cypress-debugger";
import "./commands";
Attaches required handlers to [Cypress events](https://docs.cypress.io/api/cypress-api/catalog-of-events)

support();
beforeEach(() => {
cy.visit("/");
});
```ts
debuggerSupport(): void
```
4 changes: 0 additions & 4 deletions apps/docs/.eslintrc.js

This file was deleted.

30 changes: 0 additions & 30 deletions apps/docs/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions apps/docs/next-env.d.ts

This file was deleted.

4 changes: 0 additions & 4 deletions apps/docs/next.config.js

This file was deleted.

27 changes: 0 additions & 27 deletions apps/docs/package.json

This file was deleted.

10 changes: 0 additions & 10 deletions apps/docs/pages/index.tsx

This file was deleted.

5 changes: 0 additions & 5 deletions apps/docs/tsconfig.json

This file was deleted.

24 changes: 24 additions & 0 deletions apps/web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
30 changes: 0 additions & 30 deletions apps/web/README.md

This file was deleted.

75 changes: 0 additions & 75 deletions apps/web/components/CySteps/CyStepItem.tsx

This file was deleted.

Loading