How can I print Cypress base Url in the `Git bash CLI console` - node.js

How can I print Cypress base Url in the Git bash CLI console while running the Cypress test ? Could someone please advise ?

When running headless, the browser logs don't show in the terminal, but those from the Cypress node process (aka cy.task()) do show up.
I assume the baseUrl is changing during the test, here is an example that does that and logs the current value using a task.
The configured value is http://localhost:3000, the test changes it to http://localhost:3001.
cypress.config.js
const { defineConfig } = require('cypress')
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
console.log('Printing baseUrl - during setup', config.baseUrl)
on('task', {
logBaseUrl(baseUrl) {
console.log('Printing baseUrl - from task', baseUrl)
return null
}
})
},
baseUrl: 'http://localhost:3000'
},
})
test
it('logs baseUrl to the terminal in run mode', () => {
console.log('Printing baseUrl - directly from test', Cypress.config('baseUrl')) // no show
Cypress.config('baseUrl', 'http://localhost:3001')
cy.task('logBaseUrl', Cypress.config('baseUrl'))
})
terminal
Printing baseUrl - during setup http://localhost:3000
====================================================================================================
Running: log-baseurl.cy.js (1 of 1)
Printing baseUrl - from task http://localhost:3001
√ logs baseUrl to the terminal in run mode (73ms)
1 passing (115ms)
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: 0 seconds │
│ Spec Ran: log-baseurl.cy.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
====================================================================================================
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ √ log-baseurl.cy.js 108ms 1 1 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
√ All specs passed! 108ms 1 1 - - -
Done in 18.49s.

You can use a nodejs command console.log(Cypress.config().baseUrl).
That does not require Git Bash though, only nodejs installed on Your Windows.
Or you can add in your tests cy.config().baseUrl.

Related

Request are not distributed across their worker process

I was just experimenting worker process hence try this:
const http = require("http");
const cluster = require("cluster");
const CPUs = require("os").cpus();
const numCPUs = CPUs.length;
if (cluster.isMaster) {
console.log("This is the master process: ", process.pid);
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on("exit", (worker) => {
console.log(`worker process ${process.pid} has died`);
console.log(`Only ${Object.keys(cluster.workers).length} remaining...`);
});
} else {
http
.createServer((req, res) => {
res.end(`process: ${process.pid}`);
if (req.url === "/kill") {
process.exit();
}
console.log(`serving from ${process.pid}`);
})
.listen(3000);
}
I use loadtest to check "Are Request distributed across their worker process?" But I got same process.pid
This is the master process: 6984
serving from 13108
serving from 13108
serving from 13108
serving from 13108
serving from 13108
...
Even when I kill one of them, I get the same process.pid
worker process 6984 has died
Only 3 remaining...
serving from 5636
worker process 6984 has died
Only 2 remaining...
worker process 6984 has died
Only 1 remaining...
How I am getting same process.pid when I killed that? And Why my requests are not distributed across their worker process?
Even when I use pm2 to test cluster mood using:
$ pm2 start app.js -i 3
[PM2] Starting app.js in cluster_mode (3 instances)
[PM2] Done.
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ app │ cluster │ 0 │ online │ 0% │ 31.9mb │
│ 1 │ app │ cluster │ 0 │ online │ 0% │ 31.8mb │
│ 2 │ app │ cluster │ 0 │ online │ 0% │ 31.8mb │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
for loadtest -n 50000 http://localhost:3000 I check pm2 monit:
$ pm2 monit
┌─ Process List ───────────────────────────────────────────────────┐┌── app Logs ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│[ 0] app Mem: 43 MB CPU: 34 % online ││ │
│[ 1] app Mem: 28 MB CPU: 0 % online ││ │
│[ 2] app Mem: 27 MB CPU: 0 % online ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└──────────────────────────────────────────────────────────────────┘└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
┌─ Custom Metrics ─────────────────────────────────────────────────┐┌─ Metadata ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Heap Size 20.81 MiB ││ App Name app │
│ Heap Usage 45.62 % ││ Namespace default │
│ Used Heap Size 9.49 MiB ││ Version N/A │
│ Active requests 0 ││ Restarts 0 │
└──────────────────────────────────────────────────────────────────┘└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
left/right: switch boards | up/down/mouse: scroll | Ctrl-C: exit To go further check out https://pm2.io/
But surprisingly, app1 and app2 never hit any request as well as it didn't show any app log.
Update 1
I still couldn't figure out any solution. If any further query need please ask for that. I faced that issue first time. That's why maybe I was unable to represent where the exact problem occurring.
Update 2
After getting some answer I try to test it again with a simple node server:
Using pm2 without any config:
Using config suggested from #Naor Tedgi's answer:
Now the server is not running at all.
I got this
Probably it is OS related,I am on Ubuntu 20.04.
you don't have cluster mode enabled if you want to use pm2 as load balancer you need to add
exec_mode cluster
add this config file name it config.js
module.exports = {
apps : [{
script : "app.js",
instances : "max",
exec_mode : "cluster"
}]
}
and run pm2 start config.js
then all CPU usage will divide equally
tasted on
os macOS Catalina 10.15.7
node v14.15.4
Not sure why, but it seems that for whatever reason cluster doesn't behave on your machine the way it should.
In lieu of using node.js for balancing you can go for nginx then. On nginx part it's fairly easy if one of the available strategies is enough for you: http://nginx.org/en/docs/http/load_balancing.html
Then you need to make sure that your node processes are assigned different ports. In pm2 you can either use https://pm2.keymetrics.io/docs/usage/environment/ to either manually increment port based on the instance id or delegate it fully to pm2.
Needless to say, you'll have to send your requests to nginx in this case.

PM2 & Puppeteer Watch Restarting

I have a puppeteer script which I am using to produce an export from a reporting tool that I use (called pivot.js):
const fs = require('fs');
const path = require('path');
const events = require('events');
const puppeteer = require('puppeteer');
let eventEmitter = new events.EventEmitter();
const directoryPath = "./storage/"; /* A path to the storage of exported files */
((directoryPath) => {
fs.mkdir(path.resolve(path.resolve(),
directoryPath.replace(/^\.*\/|\/?[^\/]+\.[a-z]+|\/$/g, '')), { recursive: true }, error => {
if (error) console.error(error);
});
})(directoryPath); /* Creating a storage folder for exported files (if such a folder doesn't exist yet) */
(async () => {
eventEmitter.once('reportcomplete', () => {
/*
All changes should be made within this function.
Available methods:
- setReport (https://www.flexmonster.com/api/setreport/)
- exportTo (https://www.flexmonster.com/api/exportto/)
The exportTo method takes two parameters: type and params.
Callback function will be ignored.
Possible destination types:
- plain (the file will be saved by the path defined as a value of the "directoryPath" variable)
- server (the file will be exported to the server)
Available events (use "eventEmitter" to manage events):
- ready (https://www.flexmonster.com/api/ready/)
- reportcomplete (https://www.flexmonster.com/api/reportcomplete/)
- exportcomplete (https://www.flexmonster.com/api/exportcomplete/)
Additional methods and events can be added using the template.
*/
eventEmitter.once('reportcomplete', () => { /* Exporting when the report is ready */
exportTo("csv");
exportTo("html");
exportTo("pdf");
exportTo("image");
exportTo("excel");
});
let exportCount = 0;
eventEmitter.on('exportcomplete', () => {
exportCount++;
if (exportCount == 5) browser.close(); /* Closing the browser when all the exports are complete */
});
setReport({
dataSource: {
filename: 'https://cdn.flexmonster.com/data/data.json'
}
});
});
const browser = await puppeteer.launch(); /* Launching the headless browser */
const page = await browser.newPage(); /* Creating a new page */
/* A function to set a report for the component dynamically */
function setReport(report) {
page.evaluate(report => {
flexmonster.setReport(report);
}, report)
}
/* This code is responsible for the export itself. It supports five export formats:
.html, .xlsx, .pdf, .csv, and .png. */
function exportTo(type, params) {
page.evaluate((type, params) => {
type = type.toLowerCase();
if (params) {
if (params.destinationType != "plain" && params.destinationType != "server")
params.destinationType = "plain";
}
else params = { destinationType: "plain" };
if (!params.filename) params.filename = "pivot";
flexmonster.exportTo(type, params, (result) => {
switch (type) {
case "pdf":
result.data = result.data.output();
break;
case "excel":
result.data = Array.from(result.data);
break;
case "image":
result.data = result.data.toDataURL();
break;
}
exportHandler(result);
});
}, type, params);
}
await page.exposeFunction('exportHandler', (result) => {
switch (result.type) {
case "excel":
result.data = Buffer.from(result.data);
result.type = "xlsx";
break;
case "image":
result.data = Buffer.from(result.data.replace(/^data:image\/\w+;base64,/, ""), 'base64');
result.type = "png";
break;
}
fs.writeFile(`${directoryPath}${result.filename}.${result.type}`, result.data, 'utf8', error => {
if (error) console.log(error);
});
});
/* This code adds functions to emit ready, reportcomplete, and exportcomplete events for the browser
when called. This approach allows us to handle the component's events in the browser's scope. */
await page.exposeFunction('onReady', () => {
eventEmitter.emit('ready')
});
await page.exposeFunction('onReportComplete', () => {
eventEmitter.emit('reportcomplete')
});
await page.exposeFunction('onExportComplete', () => {
eventEmitter.emit('exportcomplete')
});
/* Reading the file with the component and setting it as the browser page's contents */
await page.setContent(fs.readFileSync('index.html', 'utf8'));
/* This code runs in the page's scope, subscribing the browser window to the component's ready,
reportcomplete, and exportcomplete events */
await page.evaluate(() => {
window.addEventListener('ready', () => window.onReady());
window.addEventListener('reportcomplete', () => window.onReportComplete());
window.addEventListener('exportcomplete', () => window.onExportComplete());
});
})();
I am then using PM2 to watch the file, allowing me to swap out the code used to produce different reports, using:
pm2 start pivot.js --watch
The issue I have is that whenever I delete the contents of the storage folder (which the script writes into), a new export appears straight away. Almost as if the script is continuously being called, or PM2 is being restarted.
Both of the logs for PM2 are completely blank. But after running:
pm2 show 0
I receive the following:
│ status │ stopping │
│ name │ pivot │
│ namespace │ default │
│ version │ 1.0.0 │
│ restarts │ 1957 │
│ uptime │ 0 │
│ script path │ C:\Users\admin\Documents\Windows Puppeteer\pivot.js │
│ script args │ N/A │
│ error log path │ C:\Users\admin\.pm2\logs\pivot-error.log │
│ out log path │ C:\Users\admin\.pm2\logs\pivot-out.log │
│ pid path │ C:\Users\admin\.pm2\pids\pivot-0.pid │
│ interpreter │ node │
│ interpreter args │ N/A │
│ script id │ 0 │
│ exec cwd │ C:\Users\admin\Documents\Windows Puppeteer │
│ exec mode │ fork_mode │
│ node.js version │ 14.15.1 │
│ node env │ N/A │
│ watch & reload │ ✔ │
│ unstable restarts │ 0 │
│ created at │ 2020-11-30T01:24:27.461Z │
I hope you can help.
The issue is that the puppeteer script (named pivot.js) dumps the returning file in a folder called "storage". Storage is within the same directory as pivot.js, meaning that whilst PM2 monitors that directory, it is creating an infinite loop. The solution is to use the ignore watch option.
Creating a ecosystem file as such:
module.exports = {
apps : [{
script: 'pivot.js',
watch: '.',
ignore_watch : ["node_modules", "storage"]
}],
...
};
Or using:
pm2 start pivot.js --watch --ignore-watch="storage"
In my examples above will resolve the problem.

Cypress never get past loading screen on Ubuntu

I have created a new React project using
npx create-react-app virtual-office
I then installed a few things like styled-components, react-test-library etc
I then installed cypress with
yarn add -D cypress
When I try running cypress from the project directory with the command
./node_modules/.bin/cypress open
The cypress window opens but the spinner stays up and doesn't load any further.
Running cypress with the debugger turned on it looks like it can find the browser (see the end of the question for the output of the debugger). If I run cypress with the following command I get the same error
yarn run cypress open -b /usr/local/bin/chromium
I can open the Chromium browser with the command
/usr/local/bin/chromium
The version of Chromium is 81.0.4044.92
The command ls -la /usr/local/bin/c* gives the result
lrwxrwxrwx 2 root root 13 Apr 16 10:45 /usr/local/bin/chromium -> /usr/bin/snap
I have also run the commands
node_modules/.bin/cypress cache clear
node_modules/.bin/cypress install
node_modules/.bin/cypress open
And I get the same issue, the Cypress window opens, but no content loads.
What am I doing wrong?
Here are the logs from running the command
DEBUG=cypress:* yarn run cypress open -b /usr/local/bin/chromium &> cypress.log
yarn run v1.21.1
$ /home/luke/projects/virtual-office/node_modules/.bin/cypress open -b /usr/local/bin/chromium
2020-04-16T13:23:16.050Z cypress:cli:cli cli starts with arguments ["/usr/bin/node","/home/luke/projects/virtual-office/node_modules/.bin/cypress","open","-b","/usr/local/bin/chromium"]
2020-04-16T13:23:16.051Z cypress:cli NODE_OPTIONS is not set
2020-04-16T13:23:16.052Z cypress:cli:cli program parsing arguments
2020-04-16T13:23:16.052Z cypress:cli:cli opening Cypress
2020-04-16T13:23:16.149Z cypress:cli parsed cli options { browser: '/usr/local/bin/chromium' }
2020-04-16T13:23:16.149Z cypress:cli opening from options {"browser":"/usr/local/bin/chromium","project":"/home/luke/projects/virtual-office"}
2020-04-16T13:23:16.149Z cypress:cli command line arguments ["--browser","/usr/local/bin/chromium","--project","/home/luke/projects/virtual-office"]
2020-04-16T13:23:16.149Z cypress:cli verifying Cypress app
2020-04-16T13:23:16.150Z cypress:cli checking environment variables
2020-04-16T13:23:16.153Z cypress:cli checking if executable exists /home/luke/.cache/Cypress/4.4.0/Cypress/Cypress
2020-04-16T13:23:16.154Z cypress:cli Binary is executable? : true
2020-04-16T13:23:16.155Z cypress:cli binaryDir is /home/luke/.cache/Cypress/4.4.0/Cypress
2020-04-16T13:23:16.155Z cypress:cli Reading binary package.json from: /home/luke/.cache/Cypress/4.4.0/Cypress/resources/app/package.json
2020-04-16T13:23:16.163Z cypress:cli Found binary version 4.4.0 installed in: /home/luke/.cache/Cypress/4.4.0/Cypress
2020-04-16T13:23:16.166Z cypress:cli { verified: true }
2020-04-16T13:23:16.166Z cypress:cli is Verified ? true
2020-04-16T13:23:16.167Z cypress:cli DISPLAY environment variable is set to :1 on Linux
Assuming this DISPLAY points at working X11 server,
Cypress will not spawn own Xvfb
NOTE: if the X11 server is NOT working, Cypress will exit without explanation,
see https://github.com/cypress-io/cypress/issues/4034
Solution: Unset the DISPLAY variable and try again:
DISPLAY= npx cypress run ...
2020-04-16T13:23:16.168Z cypress:cli needs to start own Xvfb? false
2020-04-16T13:23:16.169Z cypress:cli spawning, should retry on display problem? true
2020-04-16T13:23:16.176Z cypress:cli passing DISPLAY :1
2020-04-16T13:23:16.176Z cypress:cli spawning Cypress with executable: /home/luke/.cache/Cypress/4.4.0/Cypress/Cypress
2020-04-16T13:23:16.177Z cypress:cli spawn args [ '--no-sandbox', '--', '--browser', '/usr/local/bin/chromium', '--project', '/home/luke/projects/virtual-office', '--cwd', '/home/luke/projects/virtual-office' ] { detached: false, stdio: 'inherit' }
2020-04-16T13:23:16.368Z cypress:ts Running without ts-node hook in environment "production"
2020-04-16T13:23:16.798Z cypress:server:appdata path: /home/luke/.config/Cypress/cy/production/browsers
2020-04-16T13:23:16.800Z cypress:server:util:node_options NODE_OPTIONS check passed, not forking { NODE_OPTIONS: '--max-http-header-size=1048576 --http-parser=legacy' }
2020-04-16T13:23:16.800Z cypress:server:util:node_options restoring NODE_OPTIONS { NODE_OPTIONS: '--max-http-header-size=1048576 --http-parser=legacy', ORIGINAL_NODE_OPTIONS: undefined }
2020-04-16T13:23:16.989Z cypress:server:cypress starting cypress with argv [ '/home/luke/.cache/Cypress/4.4.0/Cypress/Cypress', '--no-sandbox', '--', '--browser', '/usr/local/bin/chromium', '--project', '/home/luke/projects/virtual-office', '--cwd', '/home/luke/projects/virtual-office' ]
2020-04-16T13:23:16.989Z cypress:server:args argv array: [ '/home/luke/.cache/Cypress/4.4.0/Cypress/Cypress', '--no-sandbox', '--browser', '/usr/local/bin/chromium', '--project', '/home/luke/projects/virtual-office', '--cwd', '/home/luke/projects/virtual-office' ]
2020-04-16T13:23:16.992Z cypress:server:args argv parsed: { _: [ '/home/luke/.cache/Cypress/4.4.0/Cypress/Cypress' ], sandbox: false, browser: '/usr/local/bin/chromium', project: '/home/luke/projects/virtual-office', cwd: '/home/luke/projects/virtual-office', invokedFromCli: true }
2020-04-16T13:23:16.992Z cypress:server:util:proxy found proxy environment variables {}
2020-04-16T13:23:16.992Z cypress:server:args options { _: [ '/home/luke/.cache/Cypress/4.4.0/Cypress/Cypress' ], sandbox: false, browser: '/usr/local/bin/chromium', project: '/home/luke/projects/virtual-office', cwd: '/home/luke/projects/virtual-office', invokedFromCli: true, config: {} }
2020-04-16T13:23:16.992Z cypress:server:args argv options: { _: [ '/home/luke/.cache/Cypress/4.4.0/Cypress/Cypress' ], sandbox: false, browser: '/usr/local/bin/chromium', project: '/home/luke/projects/virtual-office', cwd: '/home/luke/projects/virtual-office', invokedFromCli: true, config: {}, projectRoot: '/home/luke/projects/virtual-office' }
2020-04-16T13:23:16.992Z cypress:server:cypress from argv [ '/home/luke/.cache/Cypress/4.4.0/Cypress/Cypress', '--no-sandbox', '--browser', '/usr/local/bin/chromium', '--project', '/home/luke/projects/virtual-office', '--cwd', '/home/luke/projects/virtual-office' ] got options { _: [ '/home/luke/.cache/Cypress/4.4.0/Cypress/Cypress' ], sandbox: false, browser: '/usr/local/bin/chromium', project: '/home/luke/projects/virtual-office', cwd: '/home/luke/projects/virtual-office', invokedFromCli: true, config: {}, projectRoot: '/home/luke/projects/virtual-office' }
2020-04-16T13:23:17.032Z cypress:server:appdata path: /home/luke/.config/Cypress/cy/production
2020-04-16T13:23:17.074Z cypress:server:cypress starting in mode interactive with options { _: [ '/home/luke/.cache/Cypress/4.4.0/Cypress/Cypress' ], sandbox: false, browser: '/usr/local/bin/chromium', project: '/home/luke/projects/virtual-office', cwd: '/home/luke/projects/virtual-office', invokedFromCli: true, config: {}, projectRoot: '/home/luke/projects/virtual-office' }
2020-04-16T13:23:17.076Z cypress:server:cypress running Electron currently
2020-04-16T13:23:17.122Z cypress:server:appdata path: /home/luke/.config/Cypress/cy/production
2020-04-16T13:23:17.420Z cypress:server:appdata path: /home/luke/.config/Cypress/cy/production/cache
2020-04-16T13:23:18.907Z cypress:server:util:process_profiler current & mean memory and CPU usage by process group:
┌─────────┬───────────────────┬──────────────┬────────────────┬────────────┬────────────────┬──────────┬──────────────┬─────────────┐
│ (index) │ group │ processCount │ pids │ cpuPercent │ meanCpuPercent │ memRssMb │ meanMemRssMb │ maxMemRssMb │
├─────────┼───────────────────┼──────────────┼────────────────┼────────────┼────────────────┼──────────┼──────────────┼─────────────┤
│ 0 │ 'cypress' │ 1 │ '31795' │ 0 │ 0 │ 147.84 │ 147.84 │ 147.84 │
│ 1 │ 'electron-shared' │ 1 │ '31797' │ 0 │ 0 │ 42.06 │ 42.06 │ 42.06 │
│ 2 │ 'other' │ 2 │ '31939, 31940' │ 0 │ 0 │ 3.72 │ 3.72 │ 3.72 │
│ 3 │ 'TOTAL' │ 4 │ '-' │ 0 │ 0 │ 193.63 │ 193.63 │ 193.63 │
└─────────┴───────────────────┴──────────────┴────────────────┴────────────┴────────────────┴──────────┴──────────────┴─────────────┘
2020-04-16T13:23:19.174Z cypress:server:saved_state making saved state from /home/luke/.cache/Cypress/4.4.0/Cypress/resources/app/packages/server
2020-04-16T13:23:19.174Z cypress:server:saved_state for project path /home/luke/projects/virtual-office
2020-04-16T13:23:19.176Z cypress:server:saved_state state path for project /home/luke/projects/virtual-office
2020-04-16T13:23:19.178Z cypress:server:appdata path: /home/luke/.config/Cypress/cy/production/projects/virtual-office-c3059dc18bc433707ce1e3eabd199225/state.json
2020-04-16T13:23:19.178Z cypress:server:saved_state full state path /home/luke/.config/Cypress/cy/production/projects/virtual-office-c3059dc18bc433707ce1e3eabd199225/state.json
2020-04-16T13:23:19.179Z cypress:server:saved_state making new state file around /home/luke/.config/Cypress/cy/production/projects/virtual-office-c3059dc18bc433707ce1e3eabd199225/state.json
2020-04-16T13:23:19.180Z cypress:server:file get values from /home/luke/.config/Cypress/cy/production/projects/virtual-office-c3059dc18bc433707ce1e3eabd199225/state.json
2020-04-16T13:23:19.182Z cypress:server:file attempt to get lock on /home/luke/.config/Cypress/cy/production/projects/virtual-office-c3059dc18bc433707ce1e3eabd199225/state.json
2020-04-16T13:23:19.187Z cypress:server:file gettin lock succeeded or failed for /home/luke/.config/Cypress/cy/production/projects/virtual-office-c3059dc18bc433707ce1e3eabd199225/state.json
2020-04-16T13:23:19.188Z cypress:server:file read /home/luke/.config/Cypress/cy/production/projects/virtual-office-c3059dc18bc433707ce1e3eabd199225/state.json
2020-04-16T13:23:19.193Z cypress:server:file read succeeded or failed for /home/luke/.config/Cypress/cy/production/projects/virtual-office-c3059dc18bc433707ce1e3eabd199225/state.json
2020-04-16T13:23:19.193Z cypress:server:file attempt to unlock /home/luke/.config/Cypress/cy/production/projects/virtual-office-c3059dc18bc433707ce1e3eabd199225/state.json
2020-04-16T13:23:19.195Z cypress:server:file unlock succeeded or failed for /home/luke/.config/Cypress/cy/production/projects/virtual-office-c3059dc18bc433707ce1e3eabd199225/state.json
2020-04-16T13:23:19.220Z cypress:server:windows creating electron window with options { backgroundColor: '#dfe2e4', width: 801, height: 550, minWidth: 458, minHeight: 400, x: 107, y: 214, type: 'INDEX', devTools: false, trackState: { width: 'appWidth', height: 'appHeight', x: 'appX', y: 'appY', devTools: 'isAppDevToolsOpen' }, onBlur: [Function: onBlur], onFocus: [Function: onFocus], onClose: [Function: onClose], show: true, frame: true, transparent: false, icon: NativeImage {}, webPreferences: { preload: '/home/luke/.cache/Cypress/4.4.0/Cypress/resources/app/packages/server/lib/ipc/ipc.js', partition: null, webSecurity: false, nodeIntegration: false, backgroundThrottling: false, backgroundColor: '#dfe2e4', transparent: false }, url: 'file:///home/luke/.cache/Cypress/4.4.0/Cypress/resources/app/packages/desktop-gui/dist/index.html', contextMenu: false, recordFrameRate: null, onCrashed: [Function: onCrashed], onNewWindow: [Function: onNewWindow] }
2020-04-16T13:23:19.678Z cypress:server:events got request for event: on:menu:clicked, undefined
2020-04-16T13:23:19.679Z cypress:server:events got request for event: get:options, undefined
2020-04-16T13:23:19.681Z cypress:server:events got request for event: get:current:user, undefined
2020-04-16T13:23:19.688Z cypress:server:file get values from /home/luke/.config/Cypress/cy/production/cache
2020-04-16T13:23:19.688Z cypress:server:file attempt to get lock on /home/luke/.config/Cypress/cy/production/cache
2020-04-16T13:23:19.694Z cypress:server:events sending ipc data { type: 'get:options', data: { id: 0.39036739440056767, data: { _: [Array], sandbox: false, browser: '/usr/local/bin/chromium', project: '/home/luke/projects/virtual-office', cwd: '/home/luke/projects/virtual-office', invokedFromCli: true, config: {}, projectRoot: '/home/luke/projects/virtual-office', onFocusTests: null, os: 'linux', version: '4.4.0' } }, originalData: { id: 0.39036739440056767, data: { _: [Array], sandbox: false, browser: '/usr/local/bin/chromium', project: '/home/luke/projects/virtual-office', cwd: '/home/luke/projects/virtual-office', invokedFromCli: true, config: {}, projectRoot: '/home/luke/projects/virtual-office', onFocusTests: [Function: onFocusTests], os: 'linux', version: '4.4.0' } } }
2020-04-16T13:23:19.696Z cypress:server:file gettin lock succeeded or failed for /home/luke/.config/Cypress/cy/production/cache
2020-04-16T13:23:19.696Z cypress:server:file read /home/luke/.config/Cypress/cy/production/cache
2020-04-16T13:23:19.698Z cypress:server:file read succeeded or failed for /home/luke/.config/Cypress/cy/production/cache
2020-04-16T13:23:19.698Z cypress:server:file attempt to unlock /home/luke/.config/Cypress/cy/production/cache
2020-04-16T13:23:19.698Z cypress:server:file unlock succeeded or failed for /home/luke/.config/Cypress/cy/production/cache
2020-04-16T13:23:19.699Z cypress:server:events sending ipc data { type: 'get:current:user', data: { id: 0.3728344423972798, data: {} }, originalData: { id: 0.3728344423972798, data: {} } }
2020-04-16T13:23:19.717Z cypress:server:events got request for event: on:focus:tests, undefined
2020-04-16T13:23:19.718Z cypress:server:events got request for event: on:spec:changed, undefined
2020-04-16T13:23:19.718Z cypress:server:events got request for event: on:config:changed, undefined
2020-04-16T13:23:19.718Z cypress:server:events got request for event: on:project:error, undefined
2020-04-16T13:23:19.719Z cypress:server:events got request for event: on:project:warning, undefined
2020-04-16T13:23:19.719Z cypress:server:events got request for event: open:project, '/home/luke/projects/virtual-office'
2020-04-16T13:23:19.719Z cypress:server:events open:project
2020-04-16T13:23:19.720Z cypress:server:browsers getAllBrowsersWith { nameOrPath: '/usr/local/bin/chromium' }
2020-04-16T13:23:19.720Z cypress:server:browsers:utils getBrowsers
2020-04-16T13:23:19.723Z cypress:launcher detecting if the following browsers are present [ { name: 'chrome', family: 'chromium', channel: 'stable', displayName: 'Chrome', versionRegex: /Google Chrome (\S+)/m, profile: true, binary: [ 'google-chrome', 'chrome', 'google-chrome-stable' ] }, { name: 'chromium', family: 'chromium', channel: 'stable', displayName: 'Chromium', versionRegex: /Chromium (\S+)/m, profile: true, binary: [ 'chromium-browser', 'chromium' ] }, { name: 'chrome', family: 'chromium', channel: 'canary', displayName: 'Canary', versionRegex: /Google Chrome Canary (\S+)/m, profile: true, binary: 'google-chrome-canary' }, { name: 'firefox', family: 'firefox', channel: 'stable', displayName: 'Firefox', info: 'Firefox support is currently in beta! You can help us continue to improve the Cypress + Firefox experience by [reporting any issues you find](https://on.cypress.io/new-issue).', versionRegex: /^Mozilla Firefox ([^\sab]+)$/m, profile: true, binary: 'firefox' }, { name: 'firefox', family: 'firefox', channel: 'dev', displayName: 'Firefox Developer Edition', info: 'Firefox support is currently in beta! You can help us continue to improve the Cypress + Firefox experience by [reporting any issues you find](https://on.cypress.io/new-issue).', versionRegex: /^Mozilla Firefox (\S+b\S*)$/m, profile: true, binary: [ 'firefox-developer-edition', 'firefox' ] }, { name: 'firefox', family: 'firefox', channel: 'nightly', displayName: 'Firefox Nightly', info: 'Firefox support is currently in beta! You can help us continue to improve the Cypress + Firefox experience by [reporting any issues you find](https://on.cypress.io/new-issue).', versionRegex: /^Mozilla Firefox (\S+a\S*)$/m, profile: true, binary: [ 'firefox-nightly', 'firefox-trunk' ] }, { name: 'edge', family: 'chromium', channel: 'stable', displayName: 'Edge', versionRegex: /Microsoft Edge (\S+)/m, profile: true, binary: 'edge' }, { name: 'edge', family: 'chromium', channel: 'canary', displayName: 'Edge Canary', versionRegex: /Microsoft Edge Canary (\S+)/m, profile: true, binary: 'edge-canary' }, { name: 'edge', family: 'chromium', channel: 'beta', displayName: 'Edge Beta', versionRegex: /Microsoft Edge Beta (\S+)/m, profile: true, binary: 'edge-beta' }, { name: 'edge', family: 'chromium', channel: 'dev', displayName: 'Edge Dev', versionRegex: /Microsoft Edge Dev (\S+)/m, profile: true, binary: 'edge-dev' } ]
2020-04-16T13:23:19.732Z cypress:launcher checking one browser chrome
2020-04-16T13:23:19.732Z cypress:launcher looking up chrome on linux platform
2020-04-16T13:23:19.732Z cypress:launcher finding version string using command "google-chrome --version"
2020-04-16T13:23:19.750Z cypress:launcher checking one browser chrome
2020-04-16T13:23:19.750Z cypress:launcher looking up chrome on linux platform
2020-04-16T13:23:19.750Z cypress:launcher finding version string using command "chrome --version"
2020-04-16T13:23:19.772Z cypress:launcher checking one browser chrome
2020-04-16T13:23:19.772Z cypress:launcher looking up chrome on linux platform
2020-04-16T13:23:19.772Z cypress:launcher finding version string using command "google-chrome-stable --version"
2020-04-16T13:23:19.785Z cypress:server:events got request for event: updater:check, undefined
2020-04-16T13:23:19.786Z cypress:server:updater checking for new version of Cypress. current version is 4.4.0
2020-04-16T13:23:19.811Z cypress:launcher Received error detecting browser binary: "google-chrome-stable" with error: Command failed with ENOENT: google-chrome-stable --version
spawn google-chrome-stable ENOENT
2020-04-16T13:23:19.811Z cypress:launcher Received error detecting browser binary: "chrome" with error: Command failed with ENOENT: chrome --version
spawn chrome ENOENT
2020-04-16T13:23:19.811Z cypress:launcher Received error detecting browser binary: "google-chrome" with error: Command failed with ENOENT: google-chrome --version
spawn google-chrome ENOENT
2020-04-16T13:23:19.811Z cypress:launcher browser chrome not installed
2020-04-16T13:23:19.811Z cypress:launcher browser chrome not installed
2020-04-16T13:23:19.811Z cypress:launcher browser chrome not installed
2020-04-16T13:23:19.813Z cypress:launcher checking one browser chromium
2020-04-16T13:23:19.813Z cypress:launcher looking up chromium on linux platform
2020-04-16T13:23:19.813Z cypress:launcher finding version string using command "chromium-browser --version"
2020-04-16T13:23:19.835Z cypress:launcher checking one browser chromium
2020-04-16T13:23:19.835Z cypress:launcher looking up chromium on linux platform
2020-04-16T13:23:19.835Z cypress:launcher finding version string using command "chromium --version"
2020-04-16T13:23:19.858Z cypress:network:agent addRequest called { isHttps: true, href: 'https://download.cypress.io/desktop.json' }
2020-04-16T13:23:19.863Z cypress:network:connect beginning getAddress { hostname: 'download.cypress.io', port: 443 }
2020-04-16T13:23:19.872Z cypress:launcher Received error detecting browser binary: "chromium-browser" with error: Command failed with ENOENT: chromium-browser --version
spawn chromium-browser ENOENT
2020-04-16T13:23:19.873Z cypress:launcher browser chromium not installed
2020-04-16T13:23:19.874Z cypress:network:connect got addresses { hostname: 'download.cypress.io', port: 443, addresses: [ { address: '104.26.7.176', family: 4 }, { address: '104.26.6.176', family: 4 }, { address: '2606:4700:20::681a:7b0', family: 6 }, { address: '2606:4700:20::681a:6b0', family: 6 } ] }
2020-04-16T13:23:19.902Z cypress:network:agent got family { family: 6, href: 'https://download.cypress.io/desktop.json' }
2020-04-16T13:23:20.631Z cypress:server:updater latest version of Cypress is: 4.4.0
2020-04-16T13:23:20.631Z cypress:server:updater new version of Cypress does not exist
2020-04-16T13:23:20.632Z cypress:server:events sending ipc data { type: 'updater:check', data: { id: 0.23731125038707646, data: false }, originalData: { id: 0.23731125038707646, data: false } }
2020-04-16T13:23:30.159Z cypress:server:util:process_profiler current & mean memory and CPU usage by process group:
┌─────────┬───────────────────┬──────────────┬───────────────────────┬────────────┬────────────────┬──────────┬──────────────┬─────────────┐
│ (index) │ group │ processCount │ pids │ cpuPercent │ meanCpuPercent │ memRssMb │ meanMemRssMb │ maxMemRssMb │
├─────────┼───────────────────┼──────────────┼───────────────────────┼────────────┼────────────────┼──────────┼──────────────┼─────────────┤
│ 0 │ 'cypress' │ 1 │ '31795' │ 1.23 │ 0.61 │ 235.24 │ 191.54 │ 235.24 │
│ 1 │ 'electron-shared' │ 3 │ '31797, 31953, 32245' │ 0 │ 0 │ 166.46 │ 104.26 │ 166.46 │
│ 2 │ 'desktop-gui' │ 1 │ '32561' │ 0 │ 0 │ 121.11 │ 121.11 │ 121.11 │
│ 3 │ 'other' │ 2 │ '32739, 32740' │ 0 │ 0 │ 3.57 │ 3.64 │ 3.72 │
│ 4 │ 'TOTAL' │ 7 │ '-' │ 1.23 │ 0.61 │ 526.38 │ 360.01 │ 526.38 │
└─────────┴───────────────────┴──────────────┴───────────────────────┴────────────┴────────────────┴──────────┴──────────────┴─────────────┘
2020-04-16T13:23:41.003Z cypress:server:util:process_profiler current & mean memory and CPU usage by process group:
┌─────────┬───────────────────┬──────────────┬───────────────────────┬────────────┬────────────────┬──────────┬──────────────┬─────────────┐
│ (index) │ group │ processCount │ pids │ cpuPercent │ meanCpuPercent │ memRssMb │ meanMemRssMb │ maxMemRssMb │
├─────────┼───────────────────┼──────────────┼───────────────────────┼────────────┼────────────────┼──────────┼──────────────┼─────────────┤
│ 0 │ 'cypress' │ 1 │ '31795' │ 1.17 │ 0.8 │ 238.16 │ 207.08 │ 238.16 │
│ 1 │ 'electron-shared' │ 3 │ '31797, 31953, 32245' │ 0.61 │ 0.2 │ 166.46 │ 124.99 │ 166.46 │
│ 2 │ 'desktop-gui' │ 1 │ '32561' │ 0.89 │ 0.44 │ 114.76 │ 117.94 │ 121.11 │
│ 3 │ 'other' │ 2 │ '912, 927' │ 0 │ 0 │ 3.63 │ 3.64 │ 3.72 │
│ 4 │ 'TOTAL' │ 7 │ '-' │ 2.66 │ 1.3 │ 523.01 │ 414.34 │ 526.38 │
└─────────┴───────────────────┴──────────────┴───────────────────────┴────────────┴────────────────┴──────────┴──────────────┴─────────────┘
[31953:0416/232558.016581:WARNING:x11_util.cc(1443)] X error received: serial 9721, error_code 9 (BadDrawable (invalid Pixmap or Window parameter)), request_code 130, minor_code 3 (X_ShmPutImage)
[31953:0416/232558.032148:WARNING:x11_util.cc(1443)] X error received: serial 9726, error_code 9 (BadDrawable (invalid Pixmap or Window parameter)), request_code 130, minor_code 3 (X_ShmPutImage)
This is an issue with Cypress on Ubuntu when Chromium is installed via snap as documented here: https://github.com/cypress-io/cypress/issues/7020
There will be a release of Cypress in the future to address the issue, so watch the GitHub issue for any updates.
Workaround:
Install Chromium via apt instead (apt install chromium-browser)
Current answer
The problem is solved in Cypress 4.4.1, so if possible, just upgrade. Otherwise see the old answers
Old answers
It is an issue using chromium installed via snap on ubuntu: https://github.com/cypress-io/cypress/issues/7020
According to the issue this bug has been patched, so it should be fixed from the next Cypress release, so hopefully this will be over from 4.4.1.
Workaround that doesn't require changes in packages:
Change the path for the command until the patch is on npm:
For fish shells:
env PATH="/home/rohdef/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin /usr/bin:/sbin:/bin" nom run ...
for bash and similar:
PATH="/home/rohdef/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin /usr/bin:/sbin:/bin" npm run ...
Make sure to adjust the path for your system, so start by doing echo $PATH and ensure that you don't leave important things out, and make sure not to have /snap/bin in your path
Workaround by installing Chromium via apt (doesn't work in 19.10)
This only works on older than 19.10, since in 19.10 apt just installs Chromium using snap
sudo snap remove chromium
sudo apt install chromium-browser
Workaround using this PPA: https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-dev I have not tested it yet
Workaround by upgrading chromium (sporadic success)
$ sudo snap save chromium # optional, backup
$ sudo snap switch --beta chromium
$ sudo snap refresh chromium
Workaround don't have chromium
Another solution is to uninstall chromium all together.

Getting error when running Postman Script via Newman

I am trying to run the following Postman Script via Newman to write the response to file:
//verify http response code
pm.test("Report Generated", function () {
pm.response.to.have.status(200);
});
var fs = require('fs');
var outputFilename = 'C:/Users/archit.goyal/Downloads/spaceReport.csv';
fs.writeFileSync(outputFilename, pm.response.text());
The request gives a response but getting the following error when writing to file:
1? TypeError in test-script
┌─────────────────────────┬──────────┬──────────┐
│ │ executed │ failed │
├─────────────────────────┼──────────┼──────────┤
│ iterations │ 1 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ requests │ 20 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ test-scripts │ 20 │ 1 │
├─────────────────────────┼──────────┼──────────┤
│ prerequest-scripts │ 0 │ 0 │
├─────────────────────────┼──────────┼──────────┤
│ assertions │ 2 │ 0 │
├─────────────────────────┴──────────┴──────────┤
│ total run duration: 1m 48.3s │
├───────────────────────────────────────────────┤
│ total data received: 1.24MB (approx) │
├───────────────────────────────────────────────┤
│ average response time: 5.3s │
└───────────────────────────────────────────────┘
# failure detail
1. TypeError fs.writeFileSync is not a function
at test-script
inside "3i_BMS_Amortization_Schedule / GetReport"
Please help
Postman itself cannot execute scripts like that. To save your responses of all the api requests, you can create a nodeJS server which will call the api through newman and then save the response to a local file. Here is an example -
var fs = require('fs'),
newman = require('newman'),
allResponse=[],
outputFilename = 'C:/Users/archit.goyal/Downloads/spaceReport.csv';
newman.run({
collection: '//your_collection_name.json',
iterationCount : 1
})
.on('request', function (err, args) {
if (!err) {
//console.log(args); // --> args contain ALL the data newman provides to this script.
var responseBody = args.response.stream,
response = responseBody.toString();
allResponse.push(JSON.parse(response));
}
})
.on('done', function (err, summary) {
fs.writeFile(outputFilename,"");
for(var i =0;i<allResponse.length;i++)
{
fs.appendFileSync(outputFilename,JSON.stringify(allResponse[i],null,5));
}
});
Note that, the above code will save only the responses. Other data like request , or URl can be extracted in a similar manner. To run this, install newman in the same directory as the script, then run the script using -
node file_name.js

how to set a variable automatically zero for each midnight in node js

how to set a variable automatically zero for each midnight in node js is it possible to use node-schedule-npm ? if so please help me how to do it
initially var count= 0; when action is performed, it will get incremented throughout the day, for next day it should be automatically set to zero.
You can use node-cron from npm.
$ npm install --save node-cron
Here is an example code
var cron = require('node-cron');
cron.schedule('* * * * *', function(){
console.log('running a task every minute');
});
# ┌────────────── second (optional)
# │ ┌──────────── minute
# │ │ ┌────────── hour
# │ │ │ ┌──────── day of month
# │ │ │ │ ┌────── month
# │ │ │ │ │ ┌──── day of week
# │ │ │ │ │ │
# │ │ │ │ │ │
# * * * * * *
you can try this
var cron = require('node-schedule');
cron.scheduleJob('00 00 12 * * 1-7',function setVotesToZero(req, res, next) {
db.users.find().toArray(function(err, vote) {
if (err) return next(err);
db.users.update({}, {
$set: {
count : 0
},
}, function(err, result) {
if (err) return next(err);
res.send({
status: 'success',
});
});
})
})

Resources