devDependencies from package.json
"cypress": "^10.3.1",
"cypress-mochawesome-reporter": "^3.2.0",
"cypress-parallel": "^0.9.1",
"typescript": "^4.7.4"
And here is configuration from cypress.config.ts
reporter: 'cypress-mochawesome-reporter',
reporterOptions: {
overwrite: false,
charts: true,
reportPageTitle: 'custom-title',
embeddedScreenshots: true,
inlineAssets: true,
saveAllAttempts: false,
autoOpen: true
},
Before using cypress-parallel everything was ok with cypress-mochawesome-reporter
But now I want to run tests in parallel and I'm doing it via cy:parallel script
"cy:run": "cypress run",
"cy:parallel" : "cypress-parallel -s cy:run -t 2 -d cypress/e2e -a '\"--headless --browser chrome\"'"
Here is an error:
Start generate report process
Read and merge jsons from "C:\Users\Администратор\WebstormProjects\cypress_task\cypress\reports\html\.jsons"
Copy screenshots folder from "C:\Users\Администратор\WebstormProjects\cypress_task\cypress\screenshots" to "C:\Users\Администратор\WebstormProjects\cypress_task\cypress\reports\html\screenshots"
An error was thrown in your plugins file while executing the handler for the after:run event.
The error we received was:
Error: Pattern C:\Users\Администратор\WebstormProjects\cypress_task\cypress\reports\html\.jsons/*.json matched no report files
In report folder, I only see screenshot of a fallen test
How to fix the error and combine cypress-mochawesome-reporter with cypress-parallel ?
Related
I am trying to generate one mochawesome report that contains all results of the spec files in my Cypress test suite.
Here is my package.json:
{
"test": "npx cypress run",
"combine-reports": "mochawesome-merge cypress/reports/mochawesome-report/*.json > mochareports/report.json",
"generate-report": "marge mochareports/*.json --reportDir mochawesome --assetsDir mochawesome/assets --reportPageTitle index.html"
},
"devDependencies": {
"cypress": "^9.5.4",
"mocha": "^9.2.2",
"mochawesome": "^7.1.3",
"mochawesome-merge": "^4.2.1",
"mochawesome-report-generator": "^6.2.0"
}
}
npm run test works as expected.
Running npm run combine-reports, creates mochareports/report.json as expected. I've opened the file in a text editor & it's populated with test stats, results, etc.
Running npm run generate-report displays Reports saved on the console.
If I open the HTML page (cypress/reports/mochareports/report.html) in VS Code, HTML is appearing. However, if I open it in a web browser, I get a blank HTML page & the below console error:
The HTML report is being generated, but for some reason is showing up as a blank page in a web browser.
Can someone please show me how to resolve this?
It would be better if you also add the cypress.json file, but I will explain with a simple example,
Here is my cypress.json report configuration
{
"reporter": "cypress-multi-reporters",
"reporterOptions": {
"reporterEnabled": "mochawesome",
"mochawesomeReporterOptions": {
"reportDir": "cypress/reports/mocha",
"quite": true,
"overwrite": false,
"html": false,
"json": true
}
}
}
And in your package.json I do not see the script to combine all json files
for ex:
"scripts": {
"clean:reports": "rm -R -f cypress/reports && mkdir cypress/reports && mkdir cypress/reports/mochareports ",
"pretest": "npm run clean:reports",
"scripts": "cypress run",
"combine-reports": "mochawesome-merge cypress/reports/mocha/*.json > cypress/reports/mochareports/report.json",
"generate-report": "marge cypress/reports/mochareports/report.json -f report -o cypress/reports/mochareports -- inline",
"posttest": "npm run combine-reports && npm run generate-report",
"test" : "npm run scripts || npm run posttest"
}
You can get some idea here also - https://medium.com/tech-learn-share/attach-screenshot-into-mochawesome-html-report-in-cypress-ca3792081474
I'm trying to generate a report on nightwatch cucumber using nightwatch-html-reporter but I'm not able to make it work.
The library I am using is [Nightwatch html Reporter][1], I followed the steps described but I'm getting the error when reading the reports directory:
Reading reports directory...
events.js:160
throw er; // Unhandled 'error' event
^
TypeError: Cannot read property 'name' of undefined
The correct configuration would be:
Create file in root tests, same level of package.json.
var reporter = require('cucumber-html-reporter');
var options = {
theme: 'bootstrap',
jsonFile: 'reports/cucumber.json',
output: 'reports/index.html',
reportSuiteAsScenarios: true,
launchReport: false
};
reporter.generate(options);
And configure runner in package.json. Example:
"scripts": {
"e2e": "npm-run-all test report --continue-on-error",
"test": "nightwatch",
"report": "node create-html-report.js"
}
Make sure it is set up this way, or enter more details of the error.
i have created a ne node project, i have installed a lot of modules and create the first index.js file
package.json
{
"name": "parser-test",
"version": "1.0.0",
"description": "parser test",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "luca bottoni",
"license": "ISC",
"dependencies": {
"node-cmd": "^3.0.0"
},
"devDependencies": {
"grunt": "^1.0.1",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-exec": "^3.0.0"
}
}
index.js (it's failed, because i want see jshint message!)
console.log("test");
a={a=6};
if i send the cmd jshint index.js from project folder i see (work fine):
index.js: line 3, col 5, Expected ':' and instead saw '='.
1 error
now i want use the grunt task to check my file
Gruntfile.js
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch:{
scripts:{
files:["./*.js"],
tasks:['jshint']
}
},
jshint: {
files: ['Gruntfile.js',"index.js"]
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-jshint');
// Default task(s).
grunt.registerTask('default', ['watch:scripts']);
grunt.registerTask('jshint', ['jshint']);
};
now i try use single task jshint with command grunt jshint, but the don't see any message. if i use the watch, watch task only the first time and after not check any change on file index.js.
i can not understand why the direct command jshint work, but the task grunt stay freezed
i have resolved after many test
i have turn-on verbose information on grunt command
grunt jshint --verbose and i have see infinite:
Running "jshint" task
Running "jshint" task
Running "jshint" task
Running "jshint" task
Running "jshint" task
Running "jshint" task
The register task and task in definition have the same name "jshint" and i have modified the name in grunt.registerTask('jshints', ['jshint']);
now work fine
I am using karma & jasmine to do unit tests, and I am trying to do my first test. I am using the first example here:
https://jasmine.github.io/1.3/introduction.html#section-Matchers
and it didn't seem to do anything, so I added some logging and tried to make it catch an error:
console.log('a');
describe("A suite", function() {
console.log('b', typeof(it));
it("contains spec with an expectation", function() {
console.log('c');
expect(true).toBe(false);
});
});
And this is what my output comes out with:
Chrome 43.0.2357 (Mac OS X 10.10.3) LOG: 'a'
Chrome 43.0.2357 (Mac OS X 10.10.3) LOG: 'b', 'function'
so it looks like nothing internal to the "it" function gets executed since 'c' is never outputted. Am I missing something?
Update
So this is the grunt task I am running:
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
karma: {
unit: {
configFile: 'karma.conf.js'
}
}
});
grunt.loadNpmTasks('grunt-karma');
grunt.registerTask('default', ['karma']);
};
And this is my package.json with the list of installed npm packages:
{
"name": "abc.com",
"version": "0.0.1",
"private": true,
"dependencies": {
"bcrypt": "^0.8.3",
"body-parser": "^1.0.2",
"bower": "^1.4.1",
"ejs": "^2.3.1",
"email-templates": "^2.0.0-beta.1",
"error-handler": "^0.1.4",
"errorhandler": "^1.3.6",
"express": "~4.1.1",
"express-session": "^1.11.2",
"grunt": "^0.4.5",
"jade": "~0.31.2",
"jasmine": "^2.3.1",
"jasmine-runner": "^0.2.9",
"karma": "^0.12.37",
"karma-chrome-launcher": "^0.2.0",
"karma-jasmine": "^0.3.5",
"karma-junit-reporter": "^0.2.2",
"method-override": "^1.0.0",
"morgan": "^1.0.0",
"mysql": "^2.6.2",
"nodemailer": "^1.3.4",
"protractor": "^1.1.1",
"shelljs": "^0.2.6",
"xoauth2": "^1.0.0"
},
"scripts": {
"prestart": "npm install",
"postinstall": "bower install --allow-root",
"start": "supervisor -n error app.js",
"pretest": "npm install",
"test": "karma start karma.conf.js",
"test-single-run": "karma start karma.conf.js --single-run",
"preupdate-webdriver": "npm install",
"update-webdriver": "webdriver-manager update",
"preprotractor": "npm run update-webdriver",
"protractor": "protractor e2e-tests/protractor.conf.js",
"update-index-async": "node -e \"require('shelljs/global'); sed('-i', /\\/\\/##NG_LOADER_START##[\\s\\S]*\\/\\/##NG_LOADER_END##/, '//##NG_LOADER_START##\\n' + sed(/sourceMappingURL=angular-loader.min.js.map/,'sourceMappingURL=bower_components/angular-loader/angular-loader.min.js.map','app/bower_components/angular-loader/angular-loader.min.js') + '\\n//##NG_LOADER_END##', 'app/index-async.html');\""
},
"configs": {
"client_javascript_paths": [
"public/components/common/helpers.js",
"public/libs/bower_components/html5-boilerplate/js/vendor/modernizr-2.6.2.min.js",
"public/libs/bower_components/jquery/dist/jquery.min.js",
"public/libs/bower_components/angular/angular.js",
"public/libs/bower_components/angular-route/angular-route.js",
"public/libs/bower_components/angular-resource/angular-resource.js",
"public/libs/bower_components/d3/d3.js",
"public/libs/bower_components/c3/c3.js",
"public/libs/bower_components/angular-chart/angular-chart.js",
"public/libs/bower_components/moment/moment.js",
"public/components/common/filters.js",
"public/components/notify/notify.js",
"public/components/static/static.js",
"public/components/account/account.js",
"public/components/auth/auth.js",
"public/components/formatted-table/formatted-table.js",
"public/app.js",
"public/libs/underscore.js"
]
},
"devDependencies": {
"jasmine": "^2.3.1",
"jasmine-core": "^2.3.4",
"karma": "^0.12.37",
"karma-chrome-launcher": "^0.2.0",
"karma-jasmine": "^0.3.5",
"karma-phantomjs-launcher": "^0.2.0",
"phantomjs": "^1.9.17"
}
}
And finally, this is my karma.conf.js
module.exports = function(config) {
var package = require('./package.json')
console.log(package.configs.client_javascript_paths);
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'requirejs'],
// list of files / patterns to load in the browser
files: package.configs.client_javascript_paths.concat([
'public/components/**/*.tests.js'
]),
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
and I just run
grunt
to start it to get the output at the top of this.
It is happening because of requirejs framework you use with karma. If you don't need it, then you could just remove it from karma.conf.js and test will work just fine. But if you actually need it, then I would suggest to look at this documentation page, explaining how to configure requirejs for karma, it actually requires an extra file.
Using the files you've presented in the question I was able to execute the tests after the following steps:
first create a backup of karma.conf.js
use CLI command karma init to reinitiate creation of karma config
on the step Do you want to use Require.js ? selected Yes
on the step Do you wanna generate a bootstrap file for RequireJS? selected Yes
copied everything from a backup and added a file that was generated by karma init, it should be called test-main.js, to the list of watched files:
module.exports = function(config) {
var package = require('./package.json');
config.set({
// ...
files: package.configs.client_javascript_paths.concat([
'public/components/**/*.tests.js',
'test-main.js', // here it is
])
// ...
});
};
Here is a basic view of my "watch" grunt task:
module.exports = function(grunt){
require("matchdep").filterDev("grunt-*").forEach(grunt.loadNpmTasks);
grunt.initConfig({
watch: {
options: {
livereload: true,
},
gruntfile:{
files:['gruntfile.js'],
tasks:['default']
},
html: {
files: ['index.html', 'assets/templates/*.html'],
tasks: ['default']
},
js: {
files: ['assets/js/*.js'],
tasks: ['default']
},
sass: {
options:{
livereload:false
},
files:['assets/sass/*.scss'],
tasks:['buildcss'],
},
css:{
files:['assets/sass/*.scss'],
tasks:[]
},
},
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['htmlhint','buildjs', 'buildcss', 'browserSync', 'watch','serve']);
};
So I have buildcss that compiles and minifies my scss into a master.css file. I've set up watch to watch the scss for changes, run the buildcss task, and then run the default task once the master.css file is updated. Then it should then refresh the page.
However, whenever I make a change to the scss file and save it, terminal shows no file updates even though it is apparently "watching files...". The only files that show as updated when I make changes are the html files: index and templates. It makes no sense to me. Sorry, I'm configuring Grunt for the first time here.
I was confusing watch and browserSync instead of using them together. First, I had to add watchTask: true, to browserSync, then I had to ensure that browserSync was being called before watch, and then I had to add the snippet of code the console prodded me to add to my index.html. Now it works perfectly. Here is the site I used to find my way: http://blog.teamtreehouse.com/getting-started-with-grunt