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

Plugin crashes on test run #173

Closed
jmtimko5 opened this issue Jan 19, 2023 · 19 comments · Fixed by #179 or #241
Closed

Plugin crashes on test run #173

jmtimko5 opened this issue Jan 19, 2023 · 19 comments · Fixed by #179 or #241
Assignees
Labels
Type: bug Something isn't working

Comments

@jmtimko5
Copy link

Description
I installed according the readme, ran my first test with cy.recordHar() in the before hook. I got the following error

Error
Your configFile threw an error from: cypress.config.js

We stopped running your tests because your config file crashed.

[Stack trace](http://localhost:53986/__launchpad/index.html#)
Error: Session with given id not found.
    at /Users/josephtimko/work/netspring/firewatch/node_modules/chrome-remote-interface/lib/chrome.js:94:35
    at Chrome._handleMessage (/Users/josephtimko/work/netspring/firewatch/node_modules/chrome-remote-interface/lib/chrome.js:257:17)
    at WebSocket. (/Users/josephtimko/work/netspring/firewatch/node_modules/chrome-remote-interface/lib/chrome.js:235:22)
    at WebSocket.emit (events.js:400:28)
    at WebSocket.emit (domain.js:475:12)
    at Receiver.receiverOnMessage (/Users/josephtimko/work/netspring/firewatch/node_modules/chrome-remote-interface/node_modules/ws/lib/websocket.js:1068:20)
    at Receiver.emit (events.js:400:28)
    at Receiver.emit (domain.js:475:12)
    at Receiver.dataMessage (/Users/josephtimko/work/netspring/firewatch/node_modules/chrome-remote-interface/node_modules/ws/lib/receiver.js:517:14)
    at /Users/josephtimko/work/netspring/firewatch/node_modules/chrome-remote-interface/node_modules/ws/lib/receiver.js:468:23
    at /Users/josephtimko/work/netspring/firewatch/node_modules/chrome-remote-interface/node_modules/ws/lib/permessage-deflate.js:308:9
    at /Users/josephtimko/work/netspring/firewatch/node_modules/chrome-remote-interface/node_modules/ws/lib/permessage-deflate.js:391:7
    at afterWrite (internal/streams/writable.js:466:5)
    at onwrite (internal/streams/writable.js:446:7)
    at InflateRaw.afterTransform (internal/streams/transform.js:103:3)
    at Zlib.processCallback (zlib.js:607:8)

Steps to reproduce
Cypress Version: 10.10
Here is my cypress.config.ts

import { defineConfig } from "cypress";
import del from "del";
import { install } from "@neuralegion/cypress-har-generator";

import { dataSeedingRoutine } from "./cypress/helpers/seeding-utils";

/* eslint-disable no-console */

export default defineConfig({
	// env: {
	// 	hars_folders: "cypress/hars",
	// },
	e2e: {
		specPattern: "cypress/integration/**/*.spec.(js|ts)",
		viewportWidth: 1792,
		viewportHeight: 1024,
		defaultCommandTimeout: 10000,
		videoUploadOnPasses: false,
		animationDistanceThreshold: 2,
		retries: {
			runMode: 1,
			openMode: 0,
		},
		projectId: "fzgkok",
		experimentalInteractiveRunEvents: true,
		async setupNodeEvents(on, config) {
			require("@cypress/code-coverage/task")(on, config);
			console.log("install");
			console.log(install);
			// console.log("hey now");
			on("before:run", async (details) => {
				// We do not run this in CI because this runs N times where N is the number of parallel machines executing cypress tests
				// This has been extracted to a step before the cypress test step to ensure it only runs once.
				if (config.env.isLocal) {
					dataSeedingRoutine(config);
				}
			});
			// @ts-ignore
			on("after:spec", (spec, results) => {
				if (results?.stats?.failures === 0 && results?.video) {
					// `del()` returns a promise, so it's important to return it to ensure
					// deleting the video is finished before moving on
					return del(results.video);
				}
			});
			await install(on);
		},
	},
});
@jmtimko5 jmtimko5 added the Type: bug Something isn't working label Jan 19, 2023
@derevnjuk
Copy link
Member

@jmtimko5 thank you for submitting your report. Can you please provide additional details such as the browser you are using, how your test looks like, and any other relevant information?

@derevnjuk
Copy link
Member

@jmtimko5 I'm unable to reproduce the issue without further information. I'll enhance error handling and include debug messages for improved troubleshooting. Closing the issue.

@jmtimko5
Copy link
Author

@derevnjuk My apologies for the delay. The browser I am using is Chrome, and the test fails immediately on the cy.visit command. Is there any other information I can provide? Please reopen the issue when you get a chance

@derevnjuk
Copy link
Member

@jmtimko5 thanks for the response 😉 Could you attach an output obtained by running tests with the NODE_DEBUG=cypress-har-generator environment variable?

$ NODE_DEBUG=cypress-har-generator cypress run --browser chrome

Please first upgrade the plugin to the latest version: https://github.com/NeuraLegion/cypress-har-generator/releases/tag/v5.14.1

@derevnjuk derevnjuk reopened this Jan 31, 2023
@jmtimko5
Copy link
Author

jmtimko5 commented Feb 4, 2023

Hi there. I used the latest version as you stated, but the error is unfortunately seemingly empty

GET /_next/static/chunks/styles.js?ts=1675478556492 200 102.541 ms - -
GET /_next/static/chunks/main.js?ts=1675478556492 200 78.469 ms - -
CYPRESS-HAR-GENERATOR 48397: Failed request: 48945.165. Reason: net::ERR_ABORTED
CYPRESS-HAR-GENERATOR 48397: Failed request: 48945.175. Reason: net::ERR_ABORTED
🍑 Unable to attach to target. Please open an issue on the repository: https://github.com/NeuraLegion/cypress-har-generator/issues for assistance.

The stack trace for this error is:
GET /_next/static/chunks/1.js 200 514.511 ms - -

@derevnjuk
Copy link
Member

derevnjuk commented Feb 6, 2023

@jmtimko5 Sorry, this information is not sufficient. Let's try some tricks to gather more information to identify the root cause.

  1. Place the file at the root directory under the following path (i.e. ./patches/chrome-remote-interface+0.31.3.patch):
diff --git a/node_modules/chrome-remote-interface/lib/chrome.js b/node_modules/chrome-remote-interface/lib/chrome.js
index fb97a70..b02cd38 100644
--- a/node_modules/chrome-remote-interface/lib/chrome.js
+++ b/node_modules/chrome-remote-interface/lib/chrome.js
@@ -4,6 +4,7 @@ const EventEmitter = require('events');
 const util = require('util');
 const formatUrl = require('url').format;
 const parseUrl = require('url').parse;
+const debuglog = require('util').debuglog;
 
 const WebSocket = require('ws');
 
@@ -11,6 +12,8 @@ const api = require('./api.js');
 const defaults = require('./defaults.js');
 const devtools = require('./devtools.js');
 
+const log = debuglog('cypress-har-generator');
+
 class ProtocolError extends Error {
     constructor(request, response) {
         let {message} = response;
@@ -245,6 +248,7 @@ class Chrome extends EventEmitter {
 
     // handle the messages read from the WebSocket
     _handleMessage(message) {
+        log('The plugin receives from the CDP: %j', message);
         // command response
         if (message.id) {
             const callback = this._callbacks[message.id];
@@ -283,6 +287,7 @@ class Chrome extends EventEmitter {
             sessionId,
             params: params || {}
         };
+        log('The plugin sends to the CDP: %j', message);
         this._ws.send(JSON.stringify(message), (err) => {
             if (err) {
                 // handle low-level WebSocket errors

  1. Apply the patch using this command:
$ npx patch-package  
  1. Re-run your tests as before (i.e. $ NODE_DEBUG=cypress-har-generator cypress run --browser chrome ), and now you should observe the following logs in the output:
CYPRESS-HAR-GENERATOR 74572: send: {"id":5,"method":"Network.enable","sessionId":"B0E6A6C649DA8A23B7DC27DF32E83AC1","params":{}}
  1. Attach the output to the ticket.

@derevnjuk
Copy link
Member

@jmtimko5, can you provide an update?

@jmtimko5
Copy link
Author

Hi @derevnjuk, I am currently in a extremely busy time at work. I will need a bit of time to run this test. I appreciate your patience.

@you1anna
Copy link

you1anna commented Mar 6, 2023

Hi @derevnjuk I'm also experiencing this issue.

Cypress v12.7
Chrome v110

I'm using the suggested setup on the readme and getting the same error as @jmtimko5.

Here is the log output from $NODE_DEBUG=cypress-har-generator cypress run --browser chrome

debug.log

@derevnjuk
Copy link
Member

derevnjuk commented Mar 7, 2023

@you1anna, thank you for submitting the report. After reviewing the provided logs, I did not detect any errors or crashes. It appears that your tests have passed without any issues. However, I noticed that the logs lack the most crucial part. Have you forwarded all the outputs to the file like this NODE_DEBUG=cypress-har-generator cypress run --browser chrome > allout.txt 2>&1? Additionally, if possible, could you reduce the scope enabling only the single test that is causing the issue?
If you are able to provide a reproducible repository, it would be extremely helpful also.

@you1anna
Copy link

you1anna commented Mar 7, 2023

@derevnjuk It only seems to fail like this when run in headed/UI mode. The tests run and pass on the console.

If I run NODE_DEBUG=cypress-har-generator yarn cy:run:smoke --browser chrome > allout.txt 2>&1 the command returns without doing anything. Is it ok to include the yarn command? Anything else I could try?

@derevnjuk
Copy link
Member

@jmtimko5, it's fine. It will redirect all outputs (standard output and standard error) to allout.txt file located in the working directory. Just attach this file here if you still experience this issue.

@you1anna
Copy link

you1anna commented Mar 7, 2023

Hi @derevnjuk, this is the smallest test I have - please see attached outputs. Hope it helps.

outputad.txt
outputac.txt
outputab.txt
outputaa.txt

@you1anna
Copy link

you1anna commented Mar 8, 2023

We are seeing a few issues between Chrome v109 and v110, may be related?

@you1anna
Copy link

Hi @derevnjuk do we have an eta of when a fix may be available for this? We are eager to add this to our project, thanks.

@derevnjuk
Copy link
Member

@you1anna seems you are not experiencing the same issue since the logs you have provided do not show any errors or issues, either related to the reported problem or any other errors. Additionally, your tests have been completed successfully as I can see. Would it be possible for you to kindly provide a reproducible repository for further investigation?

@you1anna
Copy link

@derevnjuk it only seems to be an issue when running in UI mode. I'm sorry I don't have time to make a repo for this.

Please can you confirm if my config is valid?

`const { defineConfig } = require('cypress')
const path = require('path');

const queryTestDb = require( './db');

const {downloadFile} = require('cypress-downloadfile/lib/addPlugin')

const {
install,
ensureBrowserFlags
} = require('@neuralegion/cypress-har-generator');

module.exports = defineConfig({
pageLoadTimeout: 80000,
requestTimeout: 120000,
defaultCommandTimeout: 120000,
responseTimeout: 80000,
videoCompression: 25,
waitForAnimations: true,
projectId: "5eapb9",
viewportWidth: 1280,
viewportHeight: 800,
video: true,
videosFolder: "cypress/videos",
screenshotOnRunFailure: true,
screenshotsFolder: "cypress/screenshots",
trashAssetsBeforeRuns: true,
chromeWebSecurity: false,
parseSpecialCharSequences: false,
videoUploadOnPasses: false,
numTestsKeptInMemory: 10,
reporter: "mochawesome",
retries: {
runMode: 0,
openMode: 0
},
env: {
environment: "development",
db: {
host: "mysql",
user: "rguser",
password: "password",
database: "rg"
},
tenant_db: {
host: "mysql",
user: "root",
password: "password",
database: "8a98e6b3d06d4c1885d7fc239c87a2c9"
}
},
e2e: {
baseUrl: "https://site1.xxx.dev",
setupNodeEvents(on, config) {

  const options = {
    outputRoot: config.projectRoot + '/',
    outputTarget: {
      'terminal-report.log': 'txt'
    }
  };
  require('cypress-terminal-report/src/installLogsPrinter')(on, options);

  install(on);
  on('before:browser:launch', (browser = {}, launchOptions) => {
      ensureBrowserFlags(browser, launchOptions);
      if (browser.name === "chrome") {
        const ignoreXFrameHeadersExtension = path.join(__dirname, '../extensions/ignore-x-frame-headers');
        launchOptions.args.push(launchOptions.args.push(`--load-extension=${ignoreXFrameHeadersExtension}`));
        launchOptions.args.push("--disable-features=CrossSiteDocumentBlockingIfIsolating,CrossSiteDocumentBlockingAlways,IsolateOrigins,site-per-process");
        launchOptions.args.push('--no-sandbox');
        launchOptions.args.push('--disable-gpu');
      }
      return launchOptions
    })
  
    on('task', {
      log(message) {
        console.log(message)
  
        return null
      },
      table(message) {
        console.table(message)
  
        return null
      }
    })
  
    on('task', {
      queryDb: ({query, useTenant}) => {
        return queryTestDb({query, useTenant, config})
      },
    })
    on('task', {downloadFile})
}

}
})`

When launching Cypress 12.7 and running a test, I get this:

Screenshot 2023-03-14 at 11 47 30

@derevnjuk
Copy link
Member

derevnjuk commented Mar 14, 2023

@you1anna, your configuration appears to be correct. However, I don't believe that any misconfiguration issues are causing this error.

There are a couple of reasons why this error may occur:

  • The target may have closed during initialization.
  • The target may have crashed due to memory issues.

Despite it is possible to emulate this error, it does not explain the root cause of the issue. Therefore, I have improved the debug messages and adjusted the implementation to prevent tests from crashing due to this error.

Please install the latest version (i.e. v5.16.4) and verify if it works for you. If you encounter a warning stating "Unable to attach to the target," please rerun your tests in debug mode (by setting the NODE_DEBUG environment variable to cypress-har-generator, e.g. NODE_DEBUG=cypress-har-generator cypress open --browser chrome for the interactive mode) and open a new issue attaching the entire output to the ticket for further investigation and improvements.

@jmtimko5 fyi

@you1anna
Copy link

Tests are now running on the latest release, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: bug Something isn't working
Projects
None yet
3 participants